1. Data Verification

# Double-check file access
file_path <- "training_data.txt"
cat("Reading from:", normalizePath(file_path), "\n")
## Reading from: /cloud/project/training_data.txt
# Safe file reading
if (file.exists(file_path)) {
  training_data <- readLines(file_path)
  head(training_data, 3) %>% 
    knitr::kable(col.names = "Sample Texts")
} else {
  cat("ERROR: File not found at:", file_path)
}
Sample Texts
how are you
i love programming
predict the next word

2. Model Testing

test_phrases <- c("how are", "i love", "predict the")

tryCatch({
  results <- sapply(test_phrases, predict_next_word)
  data.frame(Input = test_phrases, Prediction = results) %>% 
    knitr::kable()
}, error = function(e) {
  cat("Model error:", e$message)
})
## Model error: could not find function "str_remove_all"