GithubHelp home page GithubHelp logo

zroe1 / letter-predictor Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 54 KB

Using a linear regression model and publicly available data, my code predicts the final letter in five-letter words.

C 24.87% Jupyter Notebook 75.13%
artificial-intelligence c linear-regression python tensorflow

letter-predictor's Introduction

Letter Predictor

Using a linear regression model and publicly available data, my code predicts the final letter in five-letter words. The accuracy is ~20% which is significantly greater than a random algorithm (~3.8%).

Motivation

With modern transformer models (GTP-4, Claude, ect.), AI labs have found clever solutions for accurately predicting the next word in a sequence. In this respository, I test a similar idea with a regression model. I wondered if could a regression model also predict the next character? To test this out I provided the model with a small amount of data, trained it and recorded the results.

How it works

There are two files that do significant work to create the model in this repository:

  1. words_to_tensorflow_readable.c: a file written in C that takes the csv file in the oldCSVfiles folder containing common words and their part of speech (wordFrequency.csv) and creates a new csv in a format that is easily used by tensorflow (ASCII numbers instead of letters and a different column for each letter). By modifying the global variables for the start line and end line in the top of the C file, I was able to create training.csv and eval.csv (one file to train the model and the other to evaluate it). For the output that would contain all the lines of the file, I have included output.csv in the oldCSVfiles folder.
  2. letterpredictor.ipynb: the notebook that contains the code that trains and evaluates the linear-regression model. Linear-regression is a common machine learning algorithm that can predict outcomes based on a labeled dataset like the one in this example.

Performance

Overall, the model was able to perform at about 20% accuracy (more consistently at a bit lower though at ~18%) which is pretty strong considering that a randomly-choosing model would perform at only about ~3.8%. This accuracy demonstrates strong and impressive performance considering the size of the dataset and the challenge of the problem.

Screenshot 2023-06-13 at 5 58 59 PM

Take the word "flame" for example. In this case, the model was able to correctly predict that the final letter in the string "flam" was the character "e" (ASCII character 101), giving this character a roughly 45% chance of being correct as shown below:

Screenshot 2023-06-13 at 6 00 52 PM

The model also seems to be good at having a bias against characters that are extremely unlikely to end a five letter word. For the string "flam", the model gives a close to zero probability that the final character in the string is an "x" (ASCII character 120).

Screenshot 2023-06-13 at 6 00 04 PM

To be fair, it's performance is far from perfect. For the same string "flam", the model gave a 31% likelihood that the final character was a "t" (ASCII character 116) which doesn't seem correct at all from a human perspective.

Screenshot 2023-06-13 at 6 01 08 PM

Sources

  • List of words and part of speech data used to train the model was barrowed from www.wordfrequency.info
  • The linear regression section of the course https://www.youtube.com/watch?v=tPYj3fFJGjk was heavily referenced to build this model. The course, at the time it was made, was mostly just an in-depth walkthrought of the tensorflow documentation.

letter-predictor's People

Contributors

zroe1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.