GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - DoronF/NgramsPredictor

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
presentation_files
presentation_files
 
 
www
www
 
 
DROP_short_and_long_sentences.R
DROP_short_and_long_sentences.R
 
 
README.md
README.md
 
 
Text2SQLite.R
Text2SQLite.R
 
 
app.R
app.R
 
 
generate_ngrams.R
generate_ngrams.R
 
 
generate_top_ngrams.R
generate_top_ngrams.R
 
 
predict.R
predict.R
 
 
presentation.Rmd
presentation.Rmd
 
 
presentation.html
presentation.html
 
 
shared.R
shared.R
 
 
test_normalize.R
test_normalize.R
 
 
top_ngrams.RData
top_ngrams.RData
 
 

Repository files navigation

Stochastic N-gram Word Predictor

link to app on Shinyapps.io

overview

Goal is to create a next word prediction model using Markov chain. Text was obtained from 3 sources Twitter, Blogs and News. The texted was tokenized into sentences and loaded into SQLite using Text2SQLite.R this allowed to maintain a relational link from the sentence to it's source for balanced sampling. Sampling random sentences proved slow so I dropped sentences I was filtering out with a WHERE clause, such as short sentences (> 5) and long sentences (< 50). DROP_short_and_long_sentences.R

Ngrams generation

Probably the hardest part of this project. Prediction were hard to get before these things happened:

  • I unit test test_normalize.R the normalizing function and found many of it's failures.
  • I excluded stopwords from being counted as ngrams but included them in context words.
  • Using textclean::replace_contraction() and lemmatize_strings() was a game changer. this stablized the process and I was able to generate ngrams databases with up to 500,000 sentences. I settled on 100,000 sentence (about 90MB) for portability. Used Kneser-Ney smoothing to calculate probability and store it along the words and frequncy. generate_ngrams.R

predict.R

predict_next_word <- function(input_text, n_top = 5) {..} a function that takes in a sentences and returns a next words prediction along with it's probability and source n-gram. it returns 5 predictions by default but can be set to any number of prediction. the prediction is done by backing off from higher order grams to lower ones with fall back to bigrams.

calculate_perplexity <- function(input_text) {..} calculates the perplexity of input text against the ngrams dataset.

app.R

Shiny app with prediction UI, stats, details about the data set generated by generate_top_ngrams.R which creates top_ngrams.RData. this helps with loading time.

About

No description, website, or topics provided.

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.