Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started