'I want to write a function that takes in an arbitrary word and generates a sentence where the word has a high probability of appearing
I want to write a function that takes in an arbitrary word and generates a sentence (or set of sentences) where the word has a high probability of appearing. For example,
>> generate_sentence("lawn")
>> ['Joe mowed the lawn', 'Nothing beats the smell of a freshly mown lawn', ...]
How do I approach this problem?
If I already have a set of candidate sentences, it is easy to order them according to the probability of my word appearing, by using a language model (e.g., GPT-2). However, I want to generate these sentences from the language model directly, while enforcing a minimum probability of my word as a constraint (e.g., minimum probability = 50%).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
