Weighted Randomised Selection
Explore how to enhance a text generator by using weighted randomized selection to pick words based on their relative frequency in a source text. Understand how to build and use cumulative totals to favor frequent word sequences while still allowing variability. This lesson helps you apply Laravel techniques to create more natural text generation using Markov chains.
We'll cover the following...
We can improve the behavior of our text generator by updating the process we use to select our next word. Currently, our algorithm is simply choosing a word entirely at random. This is in contrast to the behavior we want—randomly selecting a word but preserving the relative probability of word sequences. The changes to achieve this can be found in the code below:
We are creating a new ...