“Tiny” Shakespeare#
As made popular by Andrej Karpathy in his blog post The Unreasonable Effectiveness of RNN’s, this selection from several of Shakespeare’s works has seen re-use in various tutorials, librarys, demos, including Tensorflow and HuggingFace, themselves.
from pathlib import Path
import dvc.api as dvc
data_dir = Path(dvc.Repo().find_root())/'resources'/'data'/'shakespeare'/'shakespeare.txt'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 4
1 from pathlib import Path
2 import dvc.api as dvc
----> 4 data_dir = Path(dvc.Repo().find_root())/'resources'/'data'/'shakespeare'/'shakespeare.txt'
AttributeError: module 'dvc.api' has no attribute 'Repo'
# Get raw text as string.
text = data_dir.read_text()
print(text[1000:1500])
Markov Language Model#
import markovify
model = markovify.Text(text, state_size=2, well_formed=False)
model.make_sentence(tries=500)
for i in range(5):
print(model.make_sentence_with_start('Therefore, we', strict=False, tries=500))