"“Loop through the text and make a Dictionary, meaning key - value container. And put all pair..."

“Loop through the text and make a Dictionary, meaning key - value container. And put all pair of words as keys and the word following as a value. For example: if you have a text: “a b c a b k” you start with “a b” as key and “c” as value, then “b c” and “a” as value… the value should be a list or any collection holding 0..many ‘items’ as you can have more than one value for a given pair of words. In the example above you will have “a b” two times followed fist by “c” then in the end by “k”. So in the end you will have a dictionary/hash looking like this: {‘a b’: [‘c’,’k’], ‘b c’: [‘a’], ‘c a’: [‘b’]}

Now you have the needed structure for building your funky text. You can choose to start with a random key or a fixed place! So given the structure we have we can start by saving “a b” then randomly taking a following word from the value, c or k, so the first save in the loop, “a b k” (if “k” was the random value chosen) then you continue by moving one step to the right which in our case is “b k” and save a random value for that pair if you have, in our case no, so you break out of the loop (or you can decide other stuff like start over again) When to loop is done you print your saved text string.

The bigger the input, the more values you will have for you keys (pair of words) and will then have a “smarter bot” so you can “train” your bot by adding more text (perhaps chat input?). If you have a book as input, you can construct some nice random sentences.”



-

How do Markov Chain chatbots work

… reading about markov chain and book writing…