Capstone PitchDeck - Next Word App

Renping Wang

Jan 11,2024

Introduction

This is th capstone project of Data Science track by Johns Hopkins University. It was done as an industry partnership with SwiftKey. The job was to clean and analyze a large corpus of unstructured text and build a word prediction model and use it in a web application.

Text Transformation

The process of transforming raw text to useful units for text analysis is called tokenization. What kind of transformations are needed is an important choice. In the case of word prediction, it is probably the most important step.

  • Word Stemming

In many NLP tasks you stem the words, which means reducing inflected or derived word to its basic part (ie. connection, connected and connecting, would all become connect)

  • Lowercase

Removes the problem of beginning of sentence words being “different” than the others.

  • Remove numbers

    • Remove tokens that consist only of numbers, but not words that start with digits

    • Numbers are hard to predict or use in word prediction

  • Remove punctuation

With simple ngram-model punctuation causes too many sequences

  • Remove separators

  • Spaces and variations of spaces, plus tab, newlines, and anything else in the Unicode “separator” category

  • Remove Twitter characters e.g. @ and #

Prediction Model

I use Markov models-stupid backoff -algorithm in this case.

Stupid backoff -algorithm centers around N-grams. They mean contiguous word sequences of length n. Selection of the size depends on the genre of text you are trying to predict. Higher n-grams are not always preferable for prediction. Also the computing and storage needs grow expotentially with that parameter. I chose to let user choose n-grams of lengts one, two and three.

---

Examples

*for example if n = 3*

1. Take the input and use the same text transformations as for the training data and return last two words.

2. Search for two first input words in the 3-grams training data and if matched, predict the third word. If no match, then next step.

3. Search with only the last input word in the first word of 2-grams training data. If matched, predict the second word. If no match, then next step.

4. Predict the most common words in the 1-gram data.

How it looks like