bred

Generation

generate functionTue, 17 Jan 2023

This function will take in a sentence and generate new poem lines for it.

def get_poem_lines(sentence): # We want to pass the lines from the sentence through the model # and collect the _last_ output for each line poem_lines = [] h = None for i in range(0, len(sentence) - 1, 2): # We ignore the last line (even index) input = sentence[i] target = sentence[i+1] output, h = model(input, h) poem_lines.append(output) # We also get the last output/hidden state # before we truncate the sentence last_word, last_hidden = model(sentence[-1], h) poem_lines.append(last_hidden) return poem_lines

Questions about programming?Chat with your personal AI assistant