subject

01.2: generate text from n-gram language model (10pts) complete the following generate_text function based on these input/output requirements: input: • im: the im object, a dictionary you return from the train_ngram_im function • vocab: vocab is a list of unique word types in the training set computed already computed for you during data loading. • context: the input context string that you want to condition your language model on, should be a space-separated string of tokens • order: order of your language model (i. e., "n" in the n-gram model) • num_tok: number of tokens to be generated following the input context output: • generated text, should be a space-separated string hint: after getting the next-word distribution given history, try using numpy. random. choice to sample the next word from the distribution. [] #generate text def generate_text(lm, vocab, context="he is the", order=3, num_tok=25): # the goal is to generate new words following the context # if context has more tokens than the order of lm, # generate text that follows the last (order-1) tokens of the context # and store it in the variable "history order -= 1 history = context. split([-order: ] # 'outis the list of tokens of context # you need to append the generated tokens to this list out = context. split() for i in range(num_tok): implement me!

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:30
1. technician a says horsepower information can be used by consumers to compare the power of different automobile engines. technician b says that manufacturers will often list the horsepower output of their engines in the online service information. who is right?
Answers: 2
question
Computers and Technology, 23.06.2019 01:50
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
question
Computers and Technology, 24.06.2019 17:30
Looking at the electroscope, describe how you can cause the two leaves at the bottom to repel each other and stay that way
Answers: 3
You know the right answer?
01.2: generate text from n-gram language model (10pts) complete the following generate_text functio...
Questions
question
Computers and Technology, 11.03.2020 22:01
question
Mathematics, 11.03.2020 22:01
Questions on the website: 13722361