1. Goal of the project

The final product is a Shiny app that predicts the next word while a person types (like a phone keyboard). It will be powered by a prediction algorithm trained on real English text from blogs, news articles and Twitter. This report shows that the data is loaded, summarises it, and outlines the plan.

2. Getting and loading the data

3. Basic summary statistics

Source Size_MB Lines Words Longest_line_chars
blogs 200.4 899,288 37,546,806 40,833
news 196.3 1,010,242 34,762,658 11,384
twitter 159.4 2,360,148 30,096,690 140

The three sources differ in style: Twitter lines are very short (140-character limit at collection time), blogs have the longest lines, and news sits in between.

4. Sampling and cleaning

The files are large, so exploration uses a random 1% sample from each source. Text is lower-cased, and non-English characters are removed.

5. Most common words and word pairs

6. How many words do we need?

Coverage Unique_words_needed
50% 155
90% 7522

A small number of words covers most of everyday text, while a very long tail of rare words and misspellings adds little. The dictionary can be trimmed to keep the app small and fast.

7. Interesting findings

8. Plan for the prediction algorithm and Shiny app

  1. Clean the full text (lower-case, remove numbers, symbols, profanity).
  2. Build n-gram tables (1 to 4 words) and prune rare entries to keep them small.
  3. Predict with a back-off model: look for the last 3 words, and if not found, fall back to the last 2, then 1, then the most common words.
  4. Evaluate accuracy on held-out text and tune size versus speed.
  5. Deploy a Shiny app with a text box that shows the top 3 predicted next words.

Feedback is welcome on the sampling size, the back-off approach, and the app design.