November 2019
Intermediate to advanced
346 pages
9h 36m
English
Let's see how to generate text using Markov chains by performing the following steps:
import markovifyimport pandas as pddf = pd.read_csv("airport_reviews.csv")
As an illustration, I have chosen a collection of airport reviews as my text:
"The airport is certainly tiny! ..."
from itertools import chainN = 100review_subset = df["content"][0:N]text = "".join(chain.from_iterable(review_subset))markov_chain_model = markovify.Text(text)
Behind the scenes, the library computes the transition word probabilities ...