Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Solving environment: done\n",
"\n",
"# All requested packages already installed.\n",
"\n"
]
}
],
"source": [
"!conda install -y keras"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: textgenrnn in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages\n",
"Requirement already satisfied: h5py in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from textgenrnn)\n",
"Requirement already satisfied: keras in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from textgenrnn)\n",
"Requirement already satisfied: tensorflow in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from textgenrnn)\n",
"Requirement already satisfied: numpy>=1.7 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from h5py->textgenrnn)\n",
"Requirement already satisfied: six in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from h5py->textgenrnn)\n",
"Requirement already satisfied: scipy>=0.14 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from keras->textgenrnn)\n",
"Requirement already satisfied: pyyaml in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from keras->textgenrnn)\n",
"Requirement already satisfied: wheel>=0.26 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from tensorflow->textgenrnn)\n",
"Requirement already satisfied: protobuf>=3.2.0 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from tensorflow->textgenrnn)\n",
"Requirement already satisfied: werkzeug>=0.11.10 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from tensorflow->textgenrnn)\n",
"Requirement already satisfied: setuptools in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from protobuf>=3.2.0->tensorflow->textgenrnn)\n",
"\u001b[33mYou are using pip version 9.0.1, however version 10.0.1 is available.\n",
"You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
]
}
],
"source": [
"!pip install textgenrnn"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from textgenrnn import textgenrnn"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The moment to the state of the super confirmed to the star the state back to the star the programmer of the company and the states of the Game of Thrones and the sub in the stars and started and the\n",
"\n"
]
}
],
"source": [
"textgen = textgenrnn()\n",
"textgen.generate()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7680\n",
"Epoch 2/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7472\n",
"Epoch 3/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7112\n",
"Epoch 4/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.6842\n",
"Epoch 5/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.6509\n",
"Epoch 6/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.6364\n",
"Epoch 7/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.6074\n",
"Epoch 8/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.6036\n",
"Epoch 9/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.5751\n",
"Epoch 10/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.5602\n",
"Epoch 11/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.5404\n",
"Epoch 12/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.5261\n",
"Epoch 13/20\n",
"2444/2444 [==============================] - 4s 1ms/step - loss: 0.5277A: 0s - loss: \n",
"Epoch 14/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.5061\n",
"Epoch 15/20\n",
"2444/2444 [==============================] - 4s 2ms/step - loss: 0.4958\n",
"Epoch 16/20\n",
"2444/2444 [==============================] - 4s 1ms/step - loss: 0.4852\n",
"Epoch 17/20\n",
"2444/2444 [==============================] - 4s 1ms/step - loss: 0.4772\n",
"Epoch 18/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.4708\n",
"Epoch 19/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.4670\n",
"Epoch 20/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.4627\n"
]
}
],
"source": [
"textgen.train_on_texts(open(\"Dori.txt\").readlines(), num_epochs=20)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"And all the man believe that he was there's no force in nature that gravity with there's no force in nature that gravity with himself and soul in the folding with there in the flesh that bell.\n",
"But there's no force in nature that ball the fly and see hears that he was dovelike dive.\n",
"His blood of the woman told there's no force in nature that gravity wishes that is there in the forest in a sing to the forest in my next poem. I'm atreamble)\n",
"What time thought he was all the forest in a daze.\n",
"With evermoving himself a wound with a group of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your plac\n",
"– What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is yo\n",
"– What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is your place of birth? – What is yo\n",
"Who dived into a man and soul is thriving.\n",
"A hus to trade old of the man feels that felt within there in the forest in a man believe a soul and shut an eye hears that he was then he we have a museum,\n",
"A man creatures that gravity is that and he was a white head.\n",
"And all the mother would he dove a pool\n",
"The flying fish that gravity of there in his blood of the woman told her boy at the museum,\n",
"And a grasped\n",
"And all the while his blood in the forest in own away, and second talk? It's now your turn to trade old.\n",
"His soul is north of times head out for the boy a second talk? It's now your turn to pract and beautiful.\n",
"And all the the man is travelling in the forest in the forest in his balance\n",
"Who dived out to sing to practing there, and and hears the fly.\n",
"He builds in his blood bulled a wound with himself a wound with its black inds that and write.\n",
"The flying fish that flock there in the foamy Sprite Solid\n",
"Can a man told there's no force in nature that gravity with him in the forest in a sound.\n"
]
}
],
"source": [
"Dori = textgen.generate(20, temperature=0.3, return_as_list=True)\n",
"for line in Dori:\n",
" print(line.strip())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: pronouncing in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages\n",
"\u001b[33mYou are using pip version 9.0.1, however version 10.0.1 is available.\n",
"You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
]
}
],
"source": [
"!pip install pronouncing"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pronouncing\n",
"import random"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A man creatures that gravity is that and he was a white head.\n",
"\n"
]
}
],
"source": [
"Dori_line = 1\n",
"\n",
"for x in range(Dori_line):\n",
" print (random.choice(Dori))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: tracery in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages\n",
"\u001b[33mYou are using pip version 9.0.1, however version 10.0.1 is available.\n",
"You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
]
}
],
"source": [
"!pip install tracery\n",
"import tracery"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I remember things that happened in an empty building (which is to say, one they hadn’t yet finished building) in Ramat Gan, in the fifties. Then too (as now) legs were the principal thing. The world was full of legs of all sorts and there was movement in space. Someone — Ezra Danischevsky — said to me once: I want to be an elevator repairman (you can imagine the motion and its various directions). In that (empty) building, a woman who’s now seventy-four (if she’s not dead) took off her dress.\n"
]
}
],
"source": [
"hoffmann_moods = \"I remember things that happened in an empty building (which is to say, one they hadn’t yet finished building) in Ramat Gan, in the fifties. Then too (as now) legs were the principal thing. The world was full of legs of all sorts and there was movement in space. Someone — Ezra Danischevsky — said to me once: I want to be an elevator repairman (you can imagine the motion and its various directions). In that (empty) building, a woman who’s now seventy-four (if she’s not dead) took off her dress.\"\n",
"\n",
"print(hoffmann_moods)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['the foam of the sewers at the end of the sea waves', 'the tiles with a repeating marble pattern', 'to write with markers on an eggshell', 'leaving your blancket on the chair in the morning', 'stepping on a sea turtle', 'putting a tea cup on a the book you were just reading', 'not loving your brother', 'kicking a wet plastic bag', 'a burn on the tongue', 'unclosed breakups', 'The smell of burning tires', 'sleepovers after everyone already fell asleep', \"the time in the army when I knew nothing I'll do won't metter anymore\", 'wet leather gloves', \"old people's ringtones\", 'insults']\n"
]
}
],
"source": [
"the_opposite_of_sweetness = [\"the foam of the sewers at the end of the sea waves\",\n",
" \"the tiles with a repeating marble pattern\",\n",
" \"to write with markers on an eggshell\",\n",
" \"leaving your blancket on the chair in the morning\",\n",
" \"stepping on a sea turtle\",\n",
" \"putting a tea cup on a the book you were just reading\",\n",
" \"not loving your brother\",\n",
" \"kicking a wet plastic bag\",\n",
" \"a burn on the tongue\",\n",
" \"unclosed breakups\",\n",
" \"The smell of burning tires\",\n",
" \"sleepovers after everyone already fell asleep\",\n",
" \"the time in the army when I knew nothing I'll do won't metter anymore\",\n",
" \"wet leather gloves\",\n",
" \"old people's ringtones\",\n",
" \"insults\"]\n",
" \n",
"\n",
"print(the_opposite_of_sweetness)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"hoffmann_b = [\"I remember things that happened in an empty building (which is to say, one they hadn’t yet finished building) in Ramat Gan, in the fifties.\",\n",
" \"Someone — Ezra Danischevsky — said to me once: I want to be an elevator repairman (you can imagine the motion and its various directions).\",\n",
" \"In that (empty) building, a woman who’s now seventy-four (if she’s not dead) took off her dress.\" \n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"hoffmann_about = [\"how the Bible that the principal gave me at the end of eighth grade saved my life (it was in the pocket of my army vest and the bullet went into it up to the Book of Nehemiah)\",\n",
" \"how, as though in an American movie, I went to the wedding of a girl I was in love with once and at the last minute etcetera.\"\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"- - - \n",
" - - \n",
" - - \n",
" -\n"
]
}
],
"source": [
"birds = [\n",
" \"- - - \\n - - \\n - - \\n -\",\n",
" \"- - - \\n - - \\n - - \\n -\",\n",
" \" -- - - - - \\n - -- -\\n - \\n - \",\n",
" \" -- - -\\n - - -\\n - -\\n - - \\n -\"\n",
"]\n",
"\n",
"print (birds [0])"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"- - - \n",
" - - \n",
" - - \n",
" - \n",
"\n",
"There are lots of birds in the sky suddenly. \n",
"\n",
"I remember things that happened in an empty building (which is to say, one they hadn’t yet finished building) in Ramat Gan, in the fifties. Then too (as now) the opposite of sweetness was wet leather gloves. I could write about how the Bible that the principal gave me at the end of eighth grade saved my life (it was in the pocket of my army vest and the bullet went into it up to the Book of Nehemiah) \n",
" \n",
"A bona fide story with plot twists and intrigue, \n",
"and an ending cut off like a salami – \n",
"to keep it modern.\n"
]
}
],
"source": [
"rules = {\n",
" \"origin\": \"#birds# \\n\\nThere are lots of birds in the sky suddenly. \\n\\n#hoffmann_b# Then too (as now) the opposite of sweetness was #the_opposite_of_sweetness#. I could write about #hoffmann_about# \\n \\nA bona fide story with plot twists and intrigue, \\nand an ending cut off like a salami – \\nto keep it modern.\",\n",
" \"birds\" : birds,\n",
" \"hoffmann_b\" : hoffmann_b,\n",
" \"hoffmann_about\" : hoffmann_about,\n",
" \"the_opposite_of_sweetness\" : the_opposite_of_sweetness\n",
"}\n",
"grammar = tracery.Grammar(rules)\n",
"print(grammar.flatten(\"#origin#\"))"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What is your place of birth? What does and beautiful and beautiful. The man wished a darkest wishes that he was a dovelike. There are lots of birds in the sky suddenly. In that (empty) building, a woman who’s now seventy-four (if she’s not dead) took off her dress. Then too (as now) the opposite of sweetness was the time in the army when I knew nothing I'll do won't metter anymore. I could write about how the Bible that the principal gave me at the end of eighth grade saved my life. What is your place of birth?\n"
]
}
],
"source": [
"Fin_poem = \"What is your place of birth? What does and beautiful and beautiful. The man wished a darkest wishes that he was a dovelike. There are lots of birds in the sky suddenly. In that (empty) building, a woman who’s now seventy-four (if she’s not dead) took off her dress. Then too (as now) the opposite of sweetness was the time in the army when I knew nothing I'll do won't metter anymore. I could write about how the Bible that the principal gave me at the end of eighth grade saved my life. What is your place of birth?\"\n",
"\n",
"print(Fin_poem)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment