Skip to content

Instantly share code, notes, and snippets.

@Hbentzur
Created April 13, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hbentzur/38865bb794ee37b45c7ee991c834c64b to your computer and use it in GitHub Desktop.
Save Hbentzur/38865bb794ee37b45c7ee991c834c64b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"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": 2,
"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: tensorflow in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from textgenrnn)\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: wheel>=0.26 in /Users/Hbentzur/anaconda3/lib/python3.6/site-packages (from tensorflow->textgenrnn)\n",
"Requirement already satisfied: six>=1.10.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: numpy>=1.11.0 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: 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: 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 9.0.3 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": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"from textgenrnn import textgenrnn"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I was a lot of the sub of the strong to the surprise the most of the support in the super started to the windows in the super started to the states of the story of the best of the morning to the sub\n",
"\n"
]
}
],
"source": [
"textgen = textgenrnn()\n",
"textgen.generate()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.9278\n",
"Epoch 2/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.5869\n",
"Epoch 3/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.3973\n",
"Epoch 4/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.2488\n",
"Epoch 5/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.1575\n",
"Epoch 6/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.0818\n",
"Epoch 7/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 1.0247\n",
"Epoch 8/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.9761\n",
"Epoch 9/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.9335\n",
"Epoch 10/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.9029\n",
"Epoch 11/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.8807\n",
"Epoch 12/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.8451\n",
"Epoch 13/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.8216\n",
"Epoch 14/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.8012\n",
"Epoch 15/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7854\n",
"Epoch 16/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7670\n",
"Epoch 17/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7531\n",
"Epoch 18/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7431\n",
"Epoch 19/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7346\n",
"Epoch 20/20\n",
"2444/2444 [==============================] - 3s 1ms/step - loss: 0.7277\n"
]
}
],
"source": [
"textgen.train_on_texts(open(\"Dori.txt\").readlines(), num_epochs=20)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What 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 your pl\n",
"He had to do to plate that that is your second talk? It's him, he was believe.\n",
"The darkest wishes that we have topple there in the fly.\n",
"His black hears the man is the son and beautiful.\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 does and beautiful and beautiful.\n",
"The forest that black her writes that was a dovelike.\n",
"His nature of nature of the forest 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 in the s\n",
"And there's no force in the found of our place of birth? – What does and beautiful.\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 flying out of our to travellin\n",
"What your place is now that he was himself that was now in the ball.\n",
"His nature that was there's no force in the forest that was beautiful.\n",
"He he was there in the sandpapered forest blanket and hears his own with a nature of birth? – What is your place of birth? – What is your flying for there is there in the darkest wishes that his dow\n",
"And there's a museum on the head blanket at the firmer is in soul.\n",
"What is your place of birth? – What is your found of interviews.\n",
"He her head of now that believe a dovelike that was that he was then were her thread that is there in a dollard.\n",
"What is your place of birth? – What is your place in the forest that make a man west in the woman and second talking to plate.\n",
"He had a man was the forest for there her beautiful.\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 you thread the wound of besides in the\n",
"The man wished a darkest wishes that he was a dovelike.\n",
"His galled in a second talk at the soul is whitens there's no force in nature that was there in the forest of nature is there in the forest to the forest that was himself and hears the flystead of b\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": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['What 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 your pl',\n",
" \"He had to do to plate that that is your second talk? It's him, he was believe.\\n\",\n",
" 'The darkest wishes that we have topple there in the fly.\\n',\n",
" 'His black hears the man is the son and beautiful.\\n',\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 does and beautiful and beautiful.\\n',\n",
" 'The forest that black her writes that was a dovelike.\\n',\n",
" 'His nature of nature of the forest 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 in the s',\n",
" \"And there's no force in the found of our place of birth? – What does and beautiful.\\n\",\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 flying out of our to travellin',\n",
" 'What your place is now that he was himself that was now in the ball.\\n',\n",
" \"His nature that was there's no force in the forest that was beautiful.\\n\",\n",
" 'He he was there in the sandpapered forest blanket and hears his own with a nature of birth? – What is your place of birth? – What is your flying for there is there in the darkest wishes that his dow',\n",
" \"And there's a museum on the head blanket at the firmer is in soul.\\n\",\n",
" 'What is your place of birth? – What is your found of interviews.\\n',\n",
" 'He her head of now that believe a dovelike that was that he was then were her thread that is there in a dollard.\\n',\n",
" 'What is your place of birth? – What is your place in the forest that make a man west in the woman and second talking to plate.\\n',\n",
" 'He had a man was the forest for there her beautiful.\\n',\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 you thread the wound of besides in the',\n",
" 'The man wished a darkest wishes that he was a dovelike.\\n',\n",
" \"His galled in a second talk at the soul is whitens there's no force in nature that was there in the forest of nature is there in the forest to the forest that was himself and hears the flystead of b\"]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Dori"
]
},
{
"cell_type": "code",
"execution_count": 29,
"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 9.0.3 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": 49,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pronouncing\n",
"import random"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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 you thread the wound of besides in the\n"
]
}
],
"source": [
"Dori_line = 1\n",
"\n",
"for x in range(Dori_line):\n",
" print (random.choice(Dori))"
]
}
],
"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