Question: Exercise 1 ( 1 5 points ) Your first task is to implement compute _ ngrams, which will take a list of tokens, a value
Exercise points
Your first task is to implement computengrams, which will take a list of tokens, a value n indicating the ngram length eg for grams and return an ngram dictionary. The keys in the returned dictionary should all be strings, whose values will be lists of one or more tuples. Note that even in the case of nwhich would be the minimum value the dictionary should map strings to lists of tuples ie instead of to lists of individual tokens
Exercise points
Next, you will implement genpassage, which will take an ngram dictionary and a length for the passage to generate as a token count
As described earlier, it will work as follows:
Select a random key from the dictionary and use it as the start token of the passage. It will also serve as the current token for the next step.
Select a random tuple from the list associated with the current token and append the sequence to the passage. The last token of the selected sequence will be the new current token.
If the current token is a key in the dictionary then simply repeat step otherwise select another random key from the map as the current token and append it to the passage before repeating step
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
