- Title: Word Prediction App
- Objective: To present an innovative app for predicting the next word based on user input.
09/09/2024
quanteda package for text processing and prediction.# Example R code to show in the presentation library(quanteda)
## Package version: 2.0.1
## Parallel computing: 2 of 32 threads used.
## See https://quanteda.io for tutorials and examples.
## ## Attaching package: 'quanteda'
## The following object is masked from 'package:utils': ## ## View
# Create a sample corpus
corpus <- corpus(c("this is a test", "this is another example", "predict the next word"))
# Create a document-feature matrix
dfm <- dfm(tokens(corpus), ngrams = 2:3)
## Warning: ngrams argument is not used.
# Convert dfm to a dataframe dfm_df <- convert(dfm, to = "data.frame") # Show the first few rows of the dataframe head(dfm_df)
## document this is a test another example predict the next word ## 1 text1 1 1 1 1 0 0 0 0 0 0 ## 2 text2 1 1 0 0 1 1 0 0 0 0 ## 3 text3 0 0 0 0 0 0 1 1 1 1