Search for question
Question

E Problem 3: Random sampling Write a function that generates a random sentence by sampling from a trigram language model (see sections 3.3 and 3.4 in Jurafsky & Martin). Here's the basic approach you should take: Every sentence will start with the start symbols <s> <s>. The language model gives us the conditional probability of each possible word given that context: P(w1|<s> <s>) = = C(<s> <s> w₁) + a C(<s> <s>) + aV Pick word w1 at random by drawing from this distribution. Let's say the word you pick is disgruntled. Now the probability of any word being the next word in the sentence is: C(<s> disgruntled w₂) + a P(w2 <s> disgruntled) = = C(<s> disgruntled) + aV Pick word w2 at random by drawing from this new distribution. Keep going like this until you've picked 50 words or the next word is </s> (and the sentence is finished), whichever comes first. To do the random picking, use the function multinomial defined below. It takes a dictionary mapping words to probabilities and chooses one word at random using the method shown in Figure 3.3 in Jurafsky & Martin./nProblem 2: Smoothing In the definition for TrigramLM, alpha is the smoothing parameter. What is the best value to use? Try building models with different values for alpha and compute their perplexity on both sentences_train[:500] and sentences_test[:500]. For alpha values, try different powers of 10 (e.g., [1e-5, 1e-4, le-3, le-2, 1e-1]). What patterns do you see and what might account for them? What's the best value of alpha? your code goes here> <your text goes here > Python/nProblem 1: Perplexity Define a function that calculates the perplexity of a model on a corpus (= a list of sentences). Use the definition of perplexity given in section 3.2.1 of Jurafsky and Martin. def perplexity (model, sentences): your code goes here> 1m TrigramLM(alpha=0.1) = 1m.train (sentences_train) perplexity (1m, sentences_test[:100]) Python Python

Fig: 1

Fig: 2

Fig: 3