text = "ALICE was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, " Using R This is a bi-gram write a function that predicts a set of possible next words in a given partial sentence. The function will take three inputs: (1) sentence: the starting of a sentence as a character string, ex. “Hello, how are” and (2) n: the number of words to return that might come next in the sentence. The first returned word should have the highest probability of coming next, the second word should have the second highest probability, and so on. (3) trans_mat: a transition matrix from a previously fitted markov model. The function should base its predictions on the last bigram of the partial sentence. Note: if there are less than n words that can be generated based on the text, then have your function only return these.
text = "ALICE was beginning to get very tired of
sitting by her sister on the bank, and of having
nothing to do: once or twice she had peeped into
the book her sister was reading, but it had no
pictures or conversations in it, "
Using R
This is a bi-gram
write a function that predicts a set of possible next
words in a given partial sentence.
The function will take three inputs:
(1) sentence: the starting of a sentence as a character string, ex. “Hello, how are” and
(2) n: the number of words to return that might come next in the sentence. The first
returned word should have the highest probability of coming next, the second word
should have the second highest probability, and so on.
(3) trans_mat: a transition matrix from a previously fitted markov model.
The function should base its predictions on the last bigram of the partial sentence.
Note: if there are less than n words that can be generated based on the text, then have your
function only return these.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images