{ "cells": [ { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "moves = pd.read_csv(\"data/moves.csv\")\n", "text = moves[[\"Name\", \"Effect\"]]\n", "combined_move = text.apply(lambda x: x[\"Name\"] + \" \" + x[\"Effect\"], axis = 1).tolist()\n", "text = ''.join(str(elem) for elem in combined_move)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Corpus length: 82111\n", "Total chars: 70\n", "Number of sequences: 27357\n" ] } ], "source": [ "from tensorflow import keras\n", "from tensorflow.keras import layers\n", "\n", "import numpy as np\n", "import random\n", "import io\n", "\n", "\n", "\n", "#path = keras.utils.get_file(\n", "# \"nietzsche.txt\", origin=\"https://s3.amazonaws.com/text-datasets/nietzsche.txt\"\n", "#)\n", "#with io.open(path, encoding=\"utf-8\") as f:\n", "# text = f.read().lower()\n", "\n", "\n", "\n", "#text = text.replace(\"\\n\", \" \") # We remove newlines chars for nicer display\n", "print(\"Corpus length:\", len(text))\n", "\n", "chars = sorted(list(set(text)))\n", "print(\"Total chars:\", len(chars))\n", "char_indices = dict((c, i) for i, c in enumerate(chars))\n", "indices_char = dict((i, c) for i, c in enumerate(chars))\n", "\n", "# cut the text in semi-redundant sequences of maxlen characters\n", "maxlen = 40\n", "step = 3\n", "sentences = []\n", "next_chars = []\n", "for i in range(0, len(text) - maxlen, step):\n", " sentences.append(text[i : i + maxlen])\n", " next_chars.append(text[i + maxlen])\n", "print(\"Number of sequences:\", len(sentences))\n", "\n", "x = np.zeros((len(sentences), maxlen, len(chars)), dtype=np.bool)\n", "y = np.zeros((len(sentences), len(chars)), dtype=np.bool)\n", "for i, sentence in enumerate(sentences):\n", " for t, char in enumerate(sentence):\n", " x[i, t, char_indices[char]] = 1\n", " y[i, char_indices[next_chars[i]]] = 1\n", " \n", " \n", " \n", " \n", "model = keras.Sequential(\n", " [\n", " keras.Input(shape=(maxlen, len(chars))),\n", " layers.LSTM(64),\n", " layers.Dense(len(chars), activation=\"softmax\"),\n", " ]\n", ")\n", "optimizer = keras.optimizers.RMSprop(learning_rate=0.01)\n", "model.compile(loss=\"categorical_crossentropy\", optimizer=optimizer)\n", "\n", "\n", "\n", "\n", "\n", "def sample(preds, temperature=1.0):\n", " # helper function to sample an index from a probability array\n", " preds = np.asarray(preds).astype(\"float64\")\n", " preds = np.log(preds) / temperature\n", " exp_preds = np.exp(preds)\n", " preds = exp_preds / np.sum(exp_preds)\n", " probas = np.random.multinomial(1, preds, 1)\n", " return np.argmax(probas)\n", "\n", "\n", "epochs = 40\n", "batch_size = 128\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "214/214 [==============================] - 5s 19ms/step - loss: 2.7839\n", "\n", "Generating text after epoch: 0\n", "...Diversity: 0.2\n", "...Generating with seed: \"c Laser The user shoots powerful lasers \"\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Exception ignored in: \n", "Traceback (most recent call last):\n", " File \"/Users/ArjunPatel/opt/anaconda3/envs/Speeko_Testing/lib/python3.8/site-packages/tensorflow/python/framework/c_api_util.py\", line 58, in __del__\n", " self.deleter(self.graph)\n", "AttributeError: deleter\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "...Generated: and the target the target the target target target target als als ats als ans the target the user al\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"c Laser The user shoots powerful lasers \"\n", "...Generated: als ald ats the user s bery the target ats atd thit as atatstamas the user s whit its the target the\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.7724\n", "\n", "Generating text after epoch: 1\n", "...Diversity: 0.2\n", "...Generating with seed: \"he user moves after the target, this att\"\n", "...Generated: acks the target its attacks the target its attacks the target its the target with stattack the targe\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"he user moves after the target, this att\"\n", "...Generated: acked. This move the target ind chaske twattat. This may also damang the target with sping. This may\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.5458\n", "\n", "Generating text after epoch: 2\n", "...Diversity: 0.2\n", "...Generating with seed: \". If this move is used every turn, its p\"\n", "...Generated: owers it is a cond the target with a pore on the target it is a the target with a to the target is a\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \". If this move is used every turn, its p\"\n", "...Generated: ower. This move lestock the target is hall the target with eseritical hits and and the target with a\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.4048\n", "\n", "Generating text after epoch: 3\n", "...Diversity: 0.2\n", "...Generating with seed: \"er quite a lot. This attack may leave th\"\n", "...Generated: e target its stats and attack the target with sowers the target its stat and attack the target in a \n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"er quite a lot. This attack may leave th\"\n", "...Generated: e target with amand and its bect the target. This may also leave the target its stat is a resing the\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.3027\n", "\n", "Generating text after epoch: 4\n", "...Diversity: 0.2\n", "...Generating with seed: \"ith lightning-like movement before deliv\"\n", "...Generated: erates that flict harses that canding Pokémon in the target. This may also leave the target with a p\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ith lightning-like movement before deliv\"\n", "...Generated: ent power. This may also leave the stat, that also leap and starges boising and by attack that ticen\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.2268\n", "\n", "Generating text after epoch: 5\n", "...Diversity: 0.2\n", "...Generating with seed: \"half the damage taken by the target.Hype\"\n", "...Generated: ram The user target with a ponding to the target. This may also leave the target's Sp. Def stats by \n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"half the damage taken by the target.Hype\"\n", "...Generated: rasing The user staroates the target's Attack stats.Stock The user attacks the target. This may also\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.1595\n", "\n", "Generating text after epoch: 6\n", "...Diversity: 0.2\n", "...Generating with seed: \"ground from priority moves and powers up\"\n", "...Generated: and the target. This may also lowers the user the target with a burn.Speed The user stats its targe\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ground from priority moves and powers up\"\n", "...Generated: and the target with a ponding a burn.Beap The user strakes the target. This also leave the user's a\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.1082\n", "\n", "Generating text after epoch: 7\n", "...Diversity: 0.2\n", "...Generating with seed: \"also leave the target with a burn.Boombu\"\n", "...Generated: t The user attacks the target is a retack that hits into the target with ever the target is hits int\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"also leave the target with a burn.Boombu\"\n", "...Generated: t The user attacks the target is of power is into the target is strend on the target with ever this \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.0621\n", "\n", "Generating text after epoch: 8\n", "...Diversity: 0.2\n", "...Generating with seed: \"erage its Attack and Sp. Atk stats with \"\n", "...Generated: a bittle.Spore The user attacks the target with its body raising the target with its body raising th\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"erage its Attack and Sp. Atk stats with \"\n", "...Generated: a moven the target with a burn.Streghim The user attacks the target with its bo de inflict damage.Sp\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 1.0201\n", "\n", "Generating text after epoch: 9\n", "...Diversity: 0.2\n", "...Generating with seed: \"ves that inflict status conditions are b\"\n", "...Generated: last of the target. This may also leave the target with a blad the target. The user restores the tar\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ves that inflict status conditions are b\"\n", "...Generated: last of dousing.Max Smise Beam The user crounds a ceres the target's anding its opposing Pokémon in \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.9896\n", "\n", "Generating text after epoch: 10\n", "...Diversity: 0.2\n", "...Generating with seed: \"acker's Defense stat.Octolock The user l\"\n", "...Generated: ays a sulleash and the target with a scathers the target. This may also leave the target with a scat\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"acker's Defense stat.Octolock The user l\"\n", "...Generated: eve attacks the target. This may also leave the target with a status conditions the target's Attack \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.9533\n", "\n", "Generating text after epoch: 11\n", "...Diversity: 0.2\n", "...Generating with seed: \"user whirls its fists to send a wave of \"\n", "...Generated: the target's damage. This may also leave the target with a bittle. This may also leave the target wi\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"user whirls its fists to send a wave of \"\n", "...Generated: the targetts target. This may also leave the target with a powerturn that also lives a restoic to a \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.9264\n", "\n", "Generating text after epoch: 12\n", "...Diversity: 0.2\n", "...Generating with seed: \"by vibration. This may also lower the ta\"\n", "...Generated: rget's Sp. Atk stat. This may also lower the target's Sp. Atk stat. This may also leave the target f\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"by vibration. This may also lower the ta\"\n", "...Generated: rget's Attack stat. This may also lower the target's Sp. Atk stat.Mint Band The user list of powers \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.9027\n", "\n", "Generating text after epoch: 13\n", "...Diversity: 0.2\n", "...Generating with seed: \"er attacks by wrapping the target in fie\"\n", "...Generated: r that boweleriting enery its boctical harshly lowers the user attacks by switched with a burn.Flarg\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"er attacks by wrapping the target in fie\"\n", "...Generated: r to lend and Sp. Den enditics. This may also leave the target with pouses the user target with pana\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.8782\n", "\n", "Generating text after epoch: 14\n", "...Diversity: 0.2\n", "...Generating with seed: \"ace or eyes. This may also lower the tar\"\n", "...Generated: get's Speed stat. This move's power is into the target with a blad conting the power of the target w\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ace or eyes. This may also lower the tar\"\n", "...Generated: get's Speed stat, has a bittle. This move allo es the preterf bo uned with eadoned to deal haves the\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.8620\n", "\n", "Generating text after epoch: 15\n", "...Diversity: 0.2\n", "...Generating with seed: \" its mind to ensure its next attack does\"\n", "...Generated: from stats of flasts and a bid on the target. This may also leave the target with its bood the targ\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \" its mind to ensure its next attack does\"\n", "...Generated: fince of Psychic trement on the giting the ground with its Awter throwing the target's accuracy.Sig\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.8419\n", "\n", "Generating text after epoch: 16\n", "...Diversity: 0.2\n", "...Generating with seed: \"d icicle lance at opposing Pokémon.Grass\"\n", "...Generated: Powd This The user attacks the target with a birsticul conting to target. This may also leave the t\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"d icicle lance at opposing Pokémon.Grass\"\n", "...Generated: Pladow The user terns an its that really is damage powerful halstical hits.Trows The user sharply r\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.8232\n", "\n", "Generating text after epoch: 17\n", "...Diversity: 0.2\n", "...Generating with seed: \"ater equivalent, its power increases and\"\n", "...Generated: restores the target with a bory hard land and heade the target with a power of the target with its \n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ater equivalent, its power increases and\"\n", "...Generated: attackes hall the user stronsing the user haslly lowers the target with and of attacked with its st\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.8119\n", "\n", "Generating text after epoch: 18\n", "...Diversity: 0.2\n", "...Generating with seed: \"sappears.Skill Swap The user employs its\"\n", "...Generated: poising a stat ally Pokémon a move tire ally Pokémon use. The user throws a seally poisonsuse. This\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"sappears.Skill Swap The user employs its\"\n", "...Generated: target with a pitended with a powerfles and attacks it it is heal attack the target. The user throw\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7990\n", "\n", "Generating text after epoch: 19\n", "...Diversity: 0.2\n", "...Generating with seed: \" inflict damage.Vise Grip The target is \"\n", "...Generated: attacked with its to five times in a row. Its attack hits with a bide tirn for for the user target f\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \" inflict damage.Vise Grip The target is \"\n", "...Generated: attacked with its swown drentical hit hits the target with its to five times in a refloce is dre pow\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7890\n", "\n", "Generating text after epoch: 20\n", "...Diversity: 0.2\n", "...Generating with seed: \"t-draining attack. The user's HP is rest\"\n", "...Generated: ored by harget flinch. The user attacks the target with a bide tirn of the target. This may also lea\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"t-draining attack. The user's HP is rest\"\n", "...Generated: ored for five turns. Pulp of lay inds a crount of a nefffoce ally Pokémon in the target. This may al\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7800\n", "\n", "Generating text after epoch: 21\n", "...Diversity: 0.2\n", "...Generating with seed: \"s of the listening opposing Pokémon. Thi\"\n", "...Generated: s may also leave the target with a power of fall a concering the target with a power of fall a conce\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"s of the listening opposing Pokémon. Thi\"\n", "...Generated: s may also leave the target with a power is damage the user tarleboches the target is a pulf fint th\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7695\n", "\n", "Generating text after epoch: 22\n", "...Diversity: 0.2\n", "...Generating with seed: \"ways results in a critical hit.Leech See\"\n", "...Generated: d The user attacks the target with its to five tires the target with a bit by hit makes the target w\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ways results in a critical hit.Leech See\"\n", "...Generated: d The user triches eces a beady the target with its Attack stat.Ligh Bear The user cunse stats itsel\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7558\n", "\n", "Generating text after epoch: 23\n", "...Diversity: 0.2\n", "...Generating with seed: \"a shock wave generated by the user's gap\"\n", "...Generated: s aint move to raise in the target. The user throws of its bocy ally Pokémon. This may also lower th\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"a shock wave generated by the user's gap\"\n", "...Generated: s and Sp. Def stats.Councheshes The user throws a status conditions. This may also lower the target'\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7477\n", "\n", "Generating text after epoch: 24\n", "...Diversity: 0.2\n", "...Generating with seed: \". When used with its water equivalent, i\"\n", "...Generated: ts bottring its attack for power. The user terns its stees a coilly and stats with a powerflly gite \n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \". When used with its water equivalent, i\"\n", "...Generated: ts body, the target from sweed flomes to half into Wlldes of the target. This may also lower the tar\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7382\n", "\n", "Generating text after epoch: 25\n", "...Diversity: 0.2\n", "...Generating with seed: \"ift The user swaps its offensive and def\"\n", "...Generated: elects and a dreat the plach ally Pokémon. This may also leave the target with a burn.Flare Blast Th\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ift The user swaps its offensive and def\"\n", "...Generated: levs confeates itself and puter that cantacterive itself and pptattacely, has beternstoring the powe\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7358\n", "\n", "Generating text after epoch: 26\n", "...Diversity: 0.2\n", "...Generating with seed: \"g its attack, the user rushes back to sw\"\n", "...Generated: itched in a raging the target to attack.Scles The user attacks the target with its move's power.Coar\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"g its attack, the user rushes back to sw\"\n", "...Generated: itch.Loubler Smot The user attacks the target with its a target flyies to for fron stat lughes with \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7275\n", "\n", "Generating text after epoch: 27\n", "...Diversity: 0.2\n", "...Generating with seed: \"onents.G-Max Cannonade A Water-type atta\"\n", "...Generated: ck that Gigantamax Guard The user sharply raises the user gathess dowe s at the target. This may als\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"onents.G-Max Cannonade A Water-type atta\"\n", "...Generated: ck that Gigand move canged a target. This may also power or Densends the target.Sweel Anger the user\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7256\n", "\n", "Generating text after epoch: 28\n", "...Diversity: 0.2\n", "...Generating with seed: \" last.Copycat The user mimics the move u\"\n", "...Generated: se. This move also lowers the target's Sp. Def stat.Max Sweed This move attack on the target with it\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \" last.Copycat The user mimics the move u\"\n", "...Generated: se. This move also lespowers and restares the target. This may also lowers the target's Speed stat. \n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7123\n", "\n", "Generating text after epoch: 29\n", "...Diversity: 0.2\n", "...Generating with seed: \"gears to raise the Attack and Sp. Atk st\"\n", "...Generated: at.ear Storm The user attacks with a burn.Storm The user attacks with a burn.Flaraly The user attack\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"gears to raise the Attack and Sp. Atk st\"\n", "...Generated: at cantices fire drensot the target with a burn.starge Areasive purp of cangelensing the target with\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7158\n", "\n", "Generating text after epoch: 30\n", "...Diversity: 0.2\n", "...Generating with seed: \"em becomes burned up and unusable.Infern\"\n", "...Generated: Push The user attacks with a powerfur that moves the target with a burn.Flare Punch The user attack\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"em becomes burned up and unusable.Infern\"\n", "...Generated: se The user hallstokss in hears boto inflict damage. This may also power om its power.Pounche The us\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.7057\n", "\n", "Generating text after epoch: 31\n", "...Diversity: 0.2\n", "...Generating with seed: \" the next turn.Spark The user throws an \"\n", "...Generated: engathin by a misle. This may also make the target with a nerys.Tax SwPeckif The user strokss the ta\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \" the next turn.Spark The user throws an \"\n", "...Generated: ond the target with its target in a row.Cuess A stat usted. This may also make the target with a bur\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6976\n", "\n", "Generating text after epoch: 32\n", "...Diversity: 0.2\n", "...Generating with seed: \"ack Dynamax Pokémon use. This raises all\"\n", "...Generated: of its mance the target. This also lowers the target's Speed stat.Ston Spoed At the user attacks th\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"ack Dynamax Pokémon use. This raises all\"\n", "...Generated: y Pokémon in the target, andick and a dist the target. This also leaves the target's Defense s attac\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6968\n", "\n", "Generating text after epoch: 33\n", "...Diversity: 0.2\n", "...Generating with seed: \"what they were.Torment The user torments\"\n", "...Generated: owe thrown to the target to a target into the target with its storm of falling this move in skgeste\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"what they were.Torment The user torments\"\n", "...Generated: or forlly, the user uses the target with a scill of scap at opposing Pokémon. This may also leave t\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6933\n", "\n", "Generating text after epoch: 34\n", "...Diversity: 0.2\n", "...Generating with seed: \"y Face The user frightens the target wit\"\n", "...Generated: h a power of the target. This may also leave the target with a burn.Flare Blast The user attacks wit\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"y Face The user frightens the target wit\"\n", "...Generated: h a burn.sound A supl to dearge drespict its stat ines.lariPs Guace of its bottringing and throus da\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6860\n", "\n", "Generating text after epoch: 35\n", "...Diversity: 0.2\n", "...Generating with seed: \"igantamax Pikachu use. This move paralyz\"\n", "...Generated: e dokémon the target with its own on the target with its offentical parions.Coak The user attacks wh\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"igantamax Pikachu use. This move paralyz\"\n", "...Generated: es the fire used it its move's power. This may also lower the target's Sp. Def stat.Shell Swap The u\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6901\n", "\n", "Generating text after epoch: 36\n", "...Diversity: 0.2\n", "...Generating with seed: \" move enables the user to protect itself\"\n", "...Generated: attack with a burn.Flare Blast The user attacks with a burn.Flare Blast The user attacks by wroppin\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \" move enables the user to protect itself\"\n", "...Generated: of inflaces if its bovy raises attack with its target with paracyone the target is and flaces if it\n", "\n", "214/214 [==============================] - 4s 19ms/step - loss: 0.6785\n", "\n", "Generating text after epoch: 37\n", "...Diversity: 0.2\n", "...Generating with seed: \"he user has no PP. It also damages the u\"\n", "...Generated: ser attacks the target with a burn.Trick Sheek The user strikes its target with a burn.Tric Punch Th\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"he user has no PP. It also damages the u\"\n", "...Generated: ser attacks with a poinct of its max mond of flaist an a redred the ground in the target. The user's\n", "\n", "214/214 [==============================] - 5s 25ms/step - loss: 0.6760\n", "\n", "Generating text after epoch: 38\n", "...Diversity: 0.2\n", "...Generating with seed: \"to exchange Abilities with the target.Sl\"\n", "...Generated: edp A stat usters attack types attack that harshes with a burn.Storm The user attacks the target wit\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"to exchange Abilities with the target.Sl\"\n", "...Generated: edp A stat usterned, the user attacks the target with eapopeatep to attat flome the by throus blad o\n", "\n", "214/214 [==============================] - 5s 21ms/step - loss: 0.6674\n", "\n", "Generating text after epoch: 39\n", "...Diversity: 0.2\n", "...Generating with seed: \"age on opposing Pokémon.Shock Wave The u\"\n", "...Generated: ser strikes itself of the target with a pay also make the target with a pay also make the target wit\n", "\n", "...Diversity: 0.5\n", "...Generating with seed: \"age on opposing Pokémon.Shock Wave The u\"\n", "...Generated: ser excls a neritical hits.Swetress The user swimser, the target's Attack stat buce into the target.\n", "\n" ] } ], "source": [ "for epoch in range(epochs):\n", " model.fit(x, y, batch_size=batch_size, epochs=1)\n", " print()\n", " print(\"Generating text after epoch: %d\" % epoch)\n", "\n", " start_index = random.randint(0, len(text) - maxlen - 1)\n", " for diversity in [0.2, 0.5]:\n", " print(\"...Diversity:\", diversity)\n", "\n", " generated = \"\"\n", " sentence = text[start_index : start_index + maxlen]\n", " #sentence = \"Surging Strikes\"\n", " print('...Generating with seed: \"' + sentence + '\"')\n", "\n", " for i in range(100):\n", " x_pred = np.zeros((1, maxlen, len(chars)))\n", " for t, char in enumerate(sentence):\n", " x_pred[0, t, char_indices[char]] = 1.0\n", " preds = model.predict(x_pred, verbose=0)[0]\n", " next_index = sample(preds, diversity)\n", " next_char = indices_char[next_index]\n", " sentence = sentence[1:] + next_char\n", " generated += next_char\n", "\n", " print(\"...Generated: \", generated)\n", " print()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "path = keras.utils.get_file(\n", " \"nietzsche.txt\", origin=\"https://s3.amazonaws.com/text-datasets/nietzsche.txt\"\n", ")\n", "with io.open(path, encoding=\"utf-8\") as f:\n", " text = f.read().lower()\n", "\n", "\n", "\n", "text = text.replace(\"\\n\", \" \") # We remove newlines chars for nicer display" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }