diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2023-01-23 14:14:07 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2023-01-23 14:14:07 +0530 |
commit | 43cd81bd64880af6492b94d644538df32bcf4e88 (patch) | |
tree | c07621299fcf8858ecea05b106c89ec575f41c7e | |
parent | 8c1bd6cafded83ab2729d851dcbe62df663e9667 (diff) |
upload files
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | GenerateShakespeare.ipynb | 1 | ||||
-rw-r--r-- | client.py | 33 | ||||
-rwxr-xr-x | convert.sh | 2 | ||||
-rw-r--r-- | jsmodel/group1-shard1of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | jsmodel/group1-shard2of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | jsmodel/group1-shard3of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | jsmodel/group1-shard4of4.bin | bin | 0 -> 3491076 bytes | |||
-rw-r--r-- | jsmodel/model.json | 1 | ||||
-rw-r--r-- | model.h5 | bin | 0 -> 16093616 bytes | |||
-rw-r--r-- | web/favicon.ico | 0 | ||||
-rw-r--r-- | web/index.html | 14 | ||||
-rw-r--r-- | web/jsmodel/group1-shard1of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard2of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard3of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard4of4.bin | bin | 0 -> 3491076 bytes | |||
-rw-r--r-- | web/jsmodel/model.json | 1 | ||||
-rw-r--r-- | web/script.js | 27 |
18 files changed, 80 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7275bb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv/ diff --git a/GenerateShakespeare.ipynb b/GenerateShakespeare.ipynb new file mode 100644 index 0000000..e49c4c8 --- /dev/null +++ b/GenerateShakespeare.ipynb @@ -0,0 +1 @@ +{"metadata":{"accelerator":"GPU","colab":{"provenance":[]},"gpuClass":"standard","kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.7.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install pandas","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"aOX6ge672GEp","outputId":"30bf145d-ffbf-476a-cc7b-3ee230c12787","execution":{"iopub.status.busy":"2023-01-23T05:42:10.084468Z","iopub.execute_input":"2023-01-23T05:42:10.085270Z","iopub.status.idle":"2023-01-23T05:42:17.352790Z","shell.execute_reply.started":"2023-01-23T05:42:10.085176Z","shell.execute_reply":"2023-01-23T05:42:17.351904Z"},"trusted":true},"execution_count":1,"outputs":[{"name":"stdout","text":"Requirement already satisfied: pandas in /opt/conda/lib/python3.7/site-packages (1.2.5)\nRequirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.7/site-packages (from pandas) (2.8.0)\nRequirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.7/site-packages (from pandas) (2021.1)\nRequirement already satisfied: numpy>=1.16.5 in /opt/conda/lib/python3.7/site-packages (from pandas) (1.19.5)\nRequirement already satisfied: six>=1.5 in /opt/conda/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)\n\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\n","output_type":"stream"}]},{"cell_type":"code","source":"import os\nos.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n\nimport tensorflow as tf\n\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras.layers import Embedding, GRU, Dense\n\nimport numpy as np\nimport pandas as pd\nimport os\nimport time","metadata":{"id":"Qu46zrM8wlpM","execution":{"iopub.status.busy":"2023-01-23T05:42:17.354943Z","iopub.execute_input":"2023-01-23T05:42:17.355430Z","iopub.status.idle":"2023-01-23T05:42:18.977205Z","shell.execute_reply.started":"2023-01-23T05:42:17.355391Z","shell.execute_reply":"2023-01-23T05:42:18.976489Z"},"trusted":true},"execution_count":2,"outputs":[]},{"cell_type":"code","source":"physical_devices = tf.config.list_physical_devices('GPU')\nprint(\"Num GPUs:\", len(physical_devices))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:42:18.978748Z","iopub.execute_input":"2023-01-23T05:42:18.979065Z","iopub.status.idle":"2023-01-23T05:42:19.037511Z","shell.execute_reply.started":"2023-01-23T05:42:18.979027Z","shell.execute_reply":"2023-01-23T05:42:19.036718Z"},"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Num GPUs: 1\n","output_type":"stream"}]},{"cell_type":"code","source":"dataset_url = tf.keras.utils.get_file('shakespeare.txt', 'https://storage.googleapis.com/download.tensorflow.org/data/shakespeare.txt')\ndataset_text = open(dataset_url, 'rb').read().decode(encoding='UTF-8')\nprint(dataset_text[:1000])","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"v4gmrb8Yw4HQ","outputId":"8e1db03d-310d-49f6-c617-c1b46014618c","execution":{"iopub.status.busy":"2023-01-23T05:42:19.040265Z","iopub.execute_input":"2023-01-23T05:42:19.040796Z","iopub.status.idle":"2023-01-23T05:42:19.050689Z","shell.execute_reply.started":"2023-01-23T05:42:19.040757Z","shell.execute_reply":"2023-01-23T05:42:19.050109Z"},"trusted":true},"execution_count":4,"outputs":[{"name":"stdout","text":"First Citizen:\nBefore we proceed any further, hear me speak.\n\nAll:\nSpeak, speak.\n\nFirst Citizen:\nYou are all resolved rather to die than to famish?\n\nAll:\nResolved. resolved.\n\nFirst Citizen:\nFirst, you know Caius Marcius is chief enemy to the people.\n\nAll:\nWe know't, we know't.\n\nFirst Citizen:\nLet us kill him, and we'll have corn at our own price.\nIs't a verdict?\n\nAll:\nNo more talking on't; let it be done: away, away!\n\nSecond Citizen:\nOne word, good citizens.\n\nFirst Citizen:\nWe are accounted poor citizens, the patricians good.\nWhat authority surfeits on would relieve us: if they\nwould yield us but the superfluity, while it were\nwholesome, we might guess they relieved us humanely;\nbut they think we are too dear: the leanness that\nafflicts us, the object of our misery, is as an\ninventory to particularise their abundance; our\nsufferance is a gain to them Let us revenge this with\nour pikes, ere we become rakes: for the gods know I\nspeak this in hunger for bread, not in thirst for revenge.\n\n\n","output_type":"stream"}]},{"cell_type":"code","source":"vocab = sorted(set(dataset_text))\nprint(f'There are {len(vocab)} unique characters')","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"M6fUyb4exOYw","outputId":"275ea813-d767-4653-d33a-34cafca6032b","execution":{"iopub.status.busy":"2023-01-23T05:42:19.051989Z","iopub.execute_input":"2023-01-23T05:42:19.052463Z","iopub.status.idle":"2023-01-23T05:42:19.072183Z","shell.execute_reply.started":"2023-01-23T05:42:19.052428Z","shell.execute_reply":"2023-01-23T05:42:19.071259Z"},"trusted":true},"execution_count":5,"outputs":[{"name":"stdout","text":"There are 65 unique characters\n","output_type":"stream"}]},{"cell_type":"code","source":"char2idx = {char:index for index, char in enumerate(vocab)}\nchar2idx","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"C_v1hjDmxnxQ","outputId":"c24d469d-5bf1-4d2b-d7ed-97785a91c573","execution":{"iopub.status.busy":"2023-01-23T05:42:19.073666Z","iopub.execute_input":"2023-01-23T05:42:19.073919Z","iopub.status.idle":"2023-01-23T05:42:19.086841Z","shell.execute_reply.started":"2023-01-23T05:42:19.073888Z","shell.execute_reply":"2023-01-23T05:42:19.086002Z"},"trusted":true},"execution_count":6,"outputs":[{"execution_count":6,"output_type":"execute_result","data":{"text/plain":"{'\\n': 0,\n ' ': 1,\n '!': 2,\n '$': 3,\n '&': 4,\n \"'\": 5,\n ',': 6,\n '-': 7,\n '.': 8,\n '3': 9,\n ':': 10,\n ';': 11,\n '?': 12,\n 'A': 13,\n 'B': 14,\n 'C': 15,\n 'D': 16,\n 'E': 17,\n 'F': 18,\n 'G': 19,\n 'H': 20,\n 'I': 21,\n 'J': 22,\n 'K': 23,\n 'L': 24,\n 'M': 25,\n 'N': 26,\n 'O': 27,\n 'P': 28,\n 'Q': 29,\n 'R': 30,\n 'S': 31,\n 'T': 32,\n 'U': 33,\n 'V': 34,\n 'W': 35,\n 'X': 36,\n 'Y': 37,\n 'Z': 38,\n 'a': 39,\n 'b': 40,\n 'c': 41,\n 'd': 42,\n 'e': 43,\n 'f': 44,\n 'g': 45,\n 'h': 46,\n 'i': 47,\n 'j': 48,\n 'k': 49,\n 'l': 50,\n 'm': 51,\n 'n': 52,\n 'o': 53,\n 'p': 54,\n 'q': 55,\n 'r': 56,\n 's': 57,\n 't': 58,\n 'u': 59,\n 'v': 60,\n 'w': 61,\n 'x': 62,\n 'y': 63,\n 'z': 64}"},"metadata":{}}]},{"cell_type":"code","source":"idx2char = np.array(vocab)\nidx2char","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"G1AnsQToxwUG","outputId":"f0fce00b-d6b4-47b6-f061-4b8f7b2d6ab4","execution":{"iopub.status.busy":"2023-01-23T05:42:19.088184Z","iopub.execute_input":"2023-01-23T05:42:19.088453Z","iopub.status.idle":"2023-01-23T05:42:19.096843Z","shell.execute_reply.started":"2023-01-23T05:42:19.088423Z","shell.execute_reply":"2023-01-23T05:42:19.095950Z"},"trusted":true},"execution_count":7,"outputs":[{"execution_count":7,"output_type":"execute_result","data":{"text/plain":"array(['\\n', ' ', '!', '$', '&', \"'\", ',', '-', '.', '3', ':', ';', '?',\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\n 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],\n dtype='<U1')"},"metadata":{}}]},{"cell_type":"code","source":"text_as_int = np.array([char2idx[char] for char in dataset_text])\ntext_as_int[:10]","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Lhj_cmzFyAnR","outputId":"d51a2588-9d44-4f0e-e221-7dfabfb1a622","execution":{"iopub.status.busy":"2023-01-23T05:42:19.098314Z","iopub.execute_input":"2023-01-23T05:42:19.098626Z","iopub.status.idle":"2023-01-23T05:42:19.257519Z","shell.execute_reply.started":"2023-01-23T05:42:19.098589Z","shell.execute_reply":"2023-01-23T05:42:19.256672Z"},"trusted":true},"execution_count":8,"outputs":[{"execution_count":8,"output_type":"execute_result","data":{"text/plain":"array([18, 47, 56, 57, 58, 1, 15, 47, 58, 47])"},"metadata":{}}]},{"cell_type":"code","source":"len(dataset_text)","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"fc0EdA8XyKCF","outputId":"a0609bed-91af-48fc-a42d-f51ef0bb1e2b","execution":{"iopub.status.busy":"2023-01-23T05:42:19.259051Z","iopub.execute_input":"2023-01-23T05:42:19.259368Z","iopub.status.idle":"2023-01-23T05:42:19.265849Z","shell.execute_reply.started":"2023-01-23T05:42:19.259334Z","shell.execute_reply":"2023-01-23T05:42:19.265149Z"},"trusted":true},"execution_count":9,"outputs":[{"execution_count":9,"output_type":"execute_result","data":{"text/plain":"1115394"},"metadata":{}}]},{"cell_type":"code","source":"seq_length = 100\nexamples_per_epoch = len(dataset_text)//seq_length\nexamples_per_epoch","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Q_MlG0OUyScY","outputId":"16035d85-136f-4178-f2ab-b1d9f876fa5d","execution":{"iopub.status.busy":"2023-01-23T05:42:19.269716Z","iopub.execute_input":"2023-01-23T05:42:19.270507Z","iopub.status.idle":"2023-01-23T05:42:19.277000Z","shell.execute_reply.started":"2023-01-23T05:42:19.270471Z","shell.execute_reply":"2023-01-23T05:42:19.276149Z"},"trusted":true},"execution_count":10,"outputs":[{"execution_count":10,"output_type":"execute_result","data":{"text/plain":"11153"},"metadata":{}}]},{"cell_type":"code","source":"char_dataset = tf.data.Dataset.from_tensor_slices(text_as_int)\nfor i in char_dataset.take(100):\n print(idx2char[i.numpy()])","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"H13JVt2Kycnv","outputId":"7eed174f-5c7c-49b5-81a7-6a9f840a2aa1","execution":{"iopub.status.busy":"2023-01-23T05:42:19.278448Z","iopub.execute_input":"2023-01-23T05:42:19.279059Z","iopub.status.idle":"2023-01-23T05:42:19.941991Z","shell.execute_reply.started":"2023-01-23T05:42:19.279020Z","shell.execute_reply":"2023-01-23T05:42:19.941236Z"},"trusted":true},"execution_count":11,"outputs":[{"name":"stdout","text":"F\ni\nr\ns\nt\n \nC\ni\nt\ni\nz\ne\nn\n:\n\n\nB\ne\nf\no\nr\ne\n \nw\ne\n \np\nr\no\nc\ne\ne\nd\n \na\nn\ny\n \nf\nu\nr\nt\nh\ne\nr\n,\n \nh\ne\na\nr\n \nm\ne\n \ns\np\ne\na\nk\n.\n\n\n\n\nA\nl\nl\n:\n\n\nS\np\ne\na\nk\n,\n \ns\np\ne\na\nk\n.\n\n\n\n\nF\ni\nr\ns\nt\n \nC\ni\nt\ni\nz\ne\nn\n:\n\n\nY\no\nu\n","output_type":"stream"}]},{"cell_type":"code","source":"sequences = char_dataset.batch(seq_length + 1, drop_remainder=True)\n\nfor item in sequences.take(50):\n print(repr(''.join(idx2char[item.numpy()])))","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"T8Q-SAGHyjvE","outputId":"058e81b3-ecc0-41d2-e918-2653c80a1bfe","execution":{"iopub.status.busy":"2023-01-23T05:42:19.943296Z","iopub.execute_input":"2023-01-23T05:42:19.943760Z","iopub.status.idle":"2023-01-23T05:42:19.977162Z","shell.execute_reply.started":"2023-01-23T05:42:19.943720Z","shell.execute_reply":"2023-01-23T05:42:19.976456Z"},"trusted":true},"execution_count":12,"outputs":[{"name":"stdout","text":"'First Citizen:\\nBefore we proceed any further, hear me speak.\\n\\nAll:\\nSpeak, speak.\\n\\nFirst Citizen:\\nYou '\n'are all resolved rather to die than to famish?\\n\\nAll:\\nResolved. resolved.\\n\\nFirst Citizen:\\nFirst, you k'\n\"now Caius Marcius is chief enemy to the people.\\n\\nAll:\\nWe know't, we know't.\\n\\nFirst Citizen:\\nLet us ki\"\n\"ll him, and we'll have corn at our own price.\\nIs't a verdict?\\n\\nAll:\\nNo more talking on't; let it be d\"\n'one: away, away!\\n\\nSecond Citizen:\\nOne word, good citizens.\\n\\nFirst Citizen:\\nWe are accounted poor citi'\n'zens, the patricians good.\\nWhat authority surfeits on would relieve us: if they\\nwould yield us but th'\n'e superfluity, while it were\\nwholesome, we might guess they relieved us humanely;\\nbut they think we a'\n're too dear: the leanness that\\nafflicts us, the object of our misery, is as an\\ninventory to particula'\n'rise their abundance; our\\nsufferance is a gain to them Let us revenge this with\\nour pikes, ere we bec'\n'ome rakes: for the gods know I\\nspeak this in hunger for bread, not in thirst for revenge.\\n\\nSecond Cit'\n\"izen:\\nWould you proceed especially against Caius Marcius?\\n\\nAll:\\nAgainst him first: he's a very dog to\"\n' the commonalty.\\n\\nSecond Citizen:\\nConsider you what services he has done for his country?\\n\\nFirst Citi'\n'zen:\\nVery well; and could be content to give him good\\nreport fort, but that he pays himself with bein'\n'g proud.\\n\\nSecond Citizen:\\nNay, but speak not maliciously.\\n\\nFirst Citizen:\\nI say unto you, what he hat'\n'h done famously, he did\\nit to that end: though soft-conscienced men can be\\ncontent to say it was for '\n'his country he did it to\\nplease his mother and to be partly proud; which he\\nis, even till the altitud'\n'e of his virtue.\\n\\nSecond Citizen:\\nWhat he cannot help in his nature, you account a\\nvice in him. You m'\n'ust in no way say he is covetous.\\n\\nFirst Citizen:\\nIf I must not, I need not be barren of accusations;'\n\"\\nhe hath faults, with surplus, to tire in repetition.\\nWhat shouts are these? The other side o' the ci\"\n'ty\\nis risen: why stay we prating here? to the Capitol!\\n\\nAll:\\nCome, come.\\n\\nFirst Citizen:\\nSoft! who co'\n'mes here?\\n\\nSecond Citizen:\\nWorthy Menenius Agrippa; one that hath always loved\\nthe people.\\n\\nFirst Cit'\n\"izen:\\nHe's one honest enough: would all the rest were so!\\n\\nMENENIUS:\\nWhat work's, my countrymen, in h\"\n'and? where go you\\nWith bats and clubs? The matter? speak, I pray you.\\n\\nFirst Citizen:\\nOur business is'\n\" not unknown to the senate; they have\\nhad inkling this fortnight what we intend to do,\\nwhich now we'l\"\n\"l show 'em in deeds. They say poor\\nsuitors have strong breaths: they shall know we\\nhave strong arms t\"\n'oo.\\n\\nMENENIUS:\\nWhy, masters, my good friends, mine honest neighbours,\\nWill you undo yourselves?\\n\\nFirs'\n't Citizen:\\nWe cannot, sir, we are undone already.\\n\\nMENENIUS:\\nI tell you, friends, most charitable car'\n'e\\nHave the patricians of you. For your wants,\\nYour suffering in this dearth, you may as well\\nStrike a'\n't the heaven with your staves as lift them\\nAgainst the Roman state, whose course will on\\nThe way it t'\n'akes, cracking ten thousand curbs\\nOf more strong link asunder than can ever\\nAppear in your impediment'\n'. For the dearth,\\nThe gods, not the patricians, make it, and\\nYour knees to them, not arms, must help.'\n\" Alack,\\nYou are transported by calamity\\nThither where more attends you, and you slander\\nThe helms o' \"\n'the state, who care for you like fathers,\\nWhen you curse them as enemies.\\n\\nFirst Citizen:\\nCare for us'\n\"! True, indeed! They ne'er cared for us\\nyet: suffer us to famish, and their store-houses\\ncrammed with\"\n' grain; make edicts for usury, to\\nsupport usurers; repeal daily any wholesome act\\nestablished against'\n' the rich, and provide more\\npiercing statutes daily, to chain up and restrain\\nthe poor. If the wars e'\n\"at us not up, they will; and\\nthere's all the love they bear us.\\n\\nMENENIUS:\\nEither you must\\nConfess yo\"\n'urselves wondrous malicious,\\nOr be accused of folly. I shall tell you\\nA pretty tale: it may be you ha'\n\"ve heard it;\\nBut, since it serves my purpose, I will venture\\nTo stale 't a little more.\\n\\nFirst Citize\"\n\"n:\\nWell, I'll hear it, sir: yet you must not think to\\nfob off our disgrace with a tale: but, an 't pl\"\n\"ease\\nyou, deliver.\\n\\nMENENIUS:\\nThere was a time when all the body's members\\nRebell'd against the belly\"\n\", thus accused it:\\nThat only like a gulf it did remain\\nI' the midst o' the body, idle and unactive,\\nS\"\n'till cupboarding the viand, never bearing\\nLike labour with the rest, where the other instruments\\nDid '\n'see and hear, devise, instruct, walk, feel,\\nAnd, mutually participate, did minister\\nUnto the appetite'\n\" and affection common\\nOf the whole body. The belly answer'd--\\n\\nFirst Citizen:\\nWell, sir, what answer \"\n\"made the belly?\\n\\nMENENIUS:\\nSir, I shall tell you. With a kind of smile,\\nWhich ne'er came from the lun\"\n'gs, but even thus--\\nFor, look you, I may make the belly smile\\nAs well as speak--it tauntingly replied'\n'\\nTo the discontented members, the mutinous parts\\nThat envied his receipt; even so most fitly\\nAs you m'\n\"align our senators for that\\nThey are not such as you.\\n\\nFirst Citizen:\\nYour belly's answer? What!\\nThe \"\n'kingly-crowned head, the vigilant eye,\\nThe counsellor heart, the arm our soldier,\\nOur steed the leg, '\n","output_type":"stream"}]},{"cell_type":"code","source":"def split_input_target(chunk):\n input_text = chunk[:-1]\n target_text = chunk[1:]\n return input_text, target_text\n\ndataset = sequences.map(split_input_target)","metadata":{"id":"ftr2kK3DzHub","execution":{"iopub.status.busy":"2023-01-23T05:42:19.980043Z","iopub.execute_input":"2023-01-23T05:42:19.980251Z","iopub.status.idle":"2023-01-23T05:42:20.032781Z","shell.execute_reply.started":"2023-01-23T05:42:19.980226Z","shell.execute_reply":"2023-01-23T05:42:20.032098Z"},"trusted":true},"execution_count":13,"outputs":[]},{"cell_type":"code","source":"for input_example, target_example in dataset.take(1):\n print('Input data: ', repr(''.join(idx2char[input_example.numpy()])))\n print('Target data:', repr(''.join(idx2char[target_example.numpy()])))","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"f-xcDQtkzWeR","outputId":"a5109e4b-ece7-48ab-e5d0-a1a245f97a9d","execution":{"iopub.status.busy":"2023-01-23T05:42:20.035451Z","iopub.execute_input":"2023-01-23T05:42:20.035648Z","iopub.status.idle":"2023-01-23T05:42:20.060245Z","shell.execute_reply.started":"2023-01-23T05:42:20.035626Z","shell.execute_reply":"2023-01-23T05:42:20.059123Z"},"trusted":true},"execution_count":14,"outputs":[{"name":"stdout","text":"Input data: 'First Citizen:\\nBefore we proceed any further, hear me speak.\\n\\nAll:\\nSpeak, speak.\\n\\nFirst Citizen:\\nYou'\nTarget data: 'irst Citizen:\\nBefore we proceed any further, hear me speak.\\n\\nAll:\\nSpeak, speak.\\n\\nFirst Citizen:\\nYou '\n","output_type":"stream"}]},{"cell_type":"code","source":"BATCH_SIZE = 64\nBUFFER_SIZE = 10000\n\ndataset = dataset.shuffle(BUFFER_SIZE).batch(BATCH_SIZE, drop_remainder=True)","metadata":{"id":"M3nYBNOPzZjB","execution":{"iopub.status.busy":"2023-01-23T05:42:20.061393Z","iopub.execute_input":"2023-01-23T05:42:20.061627Z","iopub.status.idle":"2023-01-23T05:42:20.072828Z","shell.execute_reply.started":"2023-01-23T05:42:20.061596Z","shell.execute_reply":"2023-01-23T05:42:20.072087Z"},"trusted":true},"execution_count":15,"outputs":[]},{"cell_type":"code","source":"vocab_size = 65 # len(vocab)\nembedding_dim = 256\nrnn_units = 1024\n\ndef build_model(vocab_size, embedding_dim, rnn_units, batch_size):\n model = tf.keras.Sequential()\n\n model.add(\n Embedding(\n vocab_size,\n embedding_dim,\n batch_input_shape = [batch_size, None]\n )\n )\n\n model.add(\n GRU(\n rnn_units,\n return_sequences=True,\n stateful=True,\n recurrent_initializer='glorot_uniform'\n )\n )\n\n model.add(\n Dense(vocab_size)\n )\n \n return model\n\nmodel = build_model(\n vocab_size=len(vocab),\n embedding_dim=embedding_dim,\n rnn_units=rnn_units,\n batch_size=BATCH_SIZE\n)","metadata":{"id":"PUgMHiBAzkF6","execution":{"iopub.status.busy":"2023-01-23T05:48:16.912285Z","iopub.execute_input":"2023-01-23T05:48:16.913054Z","iopub.status.idle":"2023-01-23T05:48:17.105930Z","shell.execute_reply.started":"2023-01-23T05:48:16.913018Z","shell.execute_reply":"2023-01-23T05:48:17.105120Z"},"trusted":true},"execution_count":31,"outputs":[]},{"cell_type":"code","source":"for input_example_batch, target_example_batch in dataset.take(1):\n example_batch_predictions = model(input_example_batch)\n print(example_batch_predictions.shape, \"# (batch_size, sequence_length, vocab_size)\")","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"t3vhBlLo1CpR","outputId":"6cc43fa1-a79c-4252-ae73-13f591674eb8","execution":{"iopub.status.busy":"2023-01-23T05:48:17.401827Z","iopub.execute_input":"2023-01-23T05:48:17.402309Z","iopub.status.idle":"2023-01-23T05:48:18.983245Z","shell.execute_reply.started":"2023-01-23T05:48:17.402280Z","shell.execute_reply":"2023-01-23T05:48:18.981735Z"},"trusted":true},"execution_count":32,"outputs":[{"name":"stdout","text":"(64, 100, 65) # (batch_size, sequence_length, vocab_size)\n","output_type":"stream"}]},{"cell_type":"code","source":"model.summary()","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IL1SWrFm1PzX","outputId":"be551056-289e-44c6-897f-49fb2b9aef67","execution":{"iopub.status.busy":"2023-01-23T05:48:18.985002Z","iopub.execute_input":"2023-01-23T05:48:18.985682Z","iopub.status.idle":"2023-01-23T05:48:18.994861Z","shell.execute_reply.started":"2023-01-23T05:48:18.985642Z","shell.execute_reply":"2023-01-23T05:48:18.993999Z"},"trusted":true},"execution_count":33,"outputs":[{"name":"stdout","text":"Model: \"sequential_2\"\n_________________________________________________________________\nLayer (type) Output Shape Param # \n=================================================================\nembedding_2 (Embedding) (64, None, 256) 16640 \n_________________________________________________________________\ngru_2 (GRU) (64, None, 1024) 3938304 \n_________________________________________________________________\ndense_2 (Dense) (64, None, 65) 66625 \n=================================================================\nTotal params: 4,021,569\nTrainable params: 4,021,569\nNon-trainable params: 0\n_________________________________________________________________\n","output_type":"stream"}]},{"cell_type":"code","source":"sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1)\nsampled_indices = tf.squeeze(sampled_indices, axis=-1).numpy()\nsampled_indices","metadata":{"id":"0-gpYLMw1Sdm","execution":{"iopub.status.busy":"2023-01-23T05:48:18.996495Z","iopub.execute_input":"2023-01-23T05:48:18.997002Z","iopub.status.idle":"2023-01-23T05:48:19.005064Z","shell.execute_reply.started":"2023-01-23T05:48:18.996966Z","shell.execute_reply":"2023-01-23T05:48:19.004150Z"},"trusted":true},"execution_count":34,"outputs":[{"execution_count":34,"output_type":"execute_result","data":{"text/plain":"array([11, 13, 63, 60, 45, 29, 57, 14, 55, 31, 28, 5, 6, 3, 64, 28, 48,\n 2, 18, 15, 55, 16, 13, 51, 41, 45, 1, 2, 13, 33, 59, 17, 59, 2,\n 32, 39, 22, 17, 39, 56, 30, 3, 51, 42, 51, 25, 31, 13, 30, 49, 53,\n 51, 11, 6, 53, 22, 48, 41, 5, 47, 40, 7, 47, 22, 25, 61, 42, 23,\n 25, 37, 14, 8, 2, 12, 39, 13, 33, 39, 50, 61, 27, 22, 4, 21, 63,\n 27, 58, 5, 50, 48, 38, 24, 4, 8, 12, 30, 48, 57, 38, 36])"},"metadata":{}}]},{"cell_type":"code","source":"print(\"Input: \\n\", repr(\"\".join(idx2char[input_example_batch[0]])))\nprint()\nprint(\"Next Char Predictions: \\n\", repr(\"\".join(idx2char[sampled_indices ])))","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"g3XtOlwA1kAx","outputId":"3e162f3c-76c9-4aea-e01e-05be7ff89c68","execution":{"iopub.status.busy":"2023-01-23T05:48:19.520318Z","iopub.execute_input":"2023-01-23T05:48:19.520564Z","iopub.status.idle":"2023-01-23T05:48:19.526600Z","shell.execute_reply.started":"2023-01-23T05:48:19.520539Z","shell.execute_reply":"2023-01-23T05:48:19.525826Z"},"trusted":true},"execution_count":35,"outputs":[{"name":"stdout","text":"Input: \n \"n looks bloody on the earth\\nAnd lean-look'd prophets whisper fearful change;\\nRich men look sad and r\"\n\nNext Char Predictions: \n \";AyvgQsBqSP',$zPj!FCqDAmcg !AUuEu!TaJEarR$mdmMSARkom;,oJjc'ib-iJMwdKMYB.!?aAUalwOJ&IyOt'ljZL&.?RjsZX\"\n","output_type":"stream"}]},{"cell_type":"code","source":"def loss(labels, logits):\n return tf.keras.losses.sparse_categorical_crossentropy(labels, logits, from_logits=True)","metadata":{"id":"6CGV77qX1pVb","execution":{"iopub.status.busy":"2023-01-23T05:48:20.622009Z","iopub.execute_input":"2023-01-23T05:48:20.622284Z","iopub.status.idle":"2023-01-23T05:48:20.626777Z","shell.execute_reply.started":"2023-01-23T05:48:20.622253Z","shell.execute_reply":"2023-01-23T05:48:20.625949Z"},"trusted":true},"execution_count":36,"outputs":[]},{"cell_type":"code","source":"checkpoint_dir = './training_checkpoints'\ncheckpoint_prefix = os.path.join(checkpoint_dir, 'ckpt_{epoch}')\n\ncheckpoint_callback = tf.keras.callbacks.ModelCheckpoint(\n filepath=checkpoint_prefix,\n save_weights_only=True\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:48:21.135077Z","iopub.execute_input":"2023-01-23T05:48:21.135456Z","iopub.status.idle":"2023-01-23T05:48:21.140266Z","shell.execute_reply.started":"2023-01-23T05:48:21.135425Z","shell.execute_reply":"2023-01-23T05:48:21.139270Z"},"trusted":true},"execution_count":37,"outputs":[]},{"cell_type":"code","source":"def loss(labels, logits):\n return tf.keras.losses.sparse_categorical_crossentropy(labels, logits, from_logits=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:48:21.952950Z","iopub.execute_input":"2023-01-23T05:48:21.953627Z","iopub.status.idle":"2023-01-23T05:48:21.960060Z","shell.execute_reply.started":"2023-01-23T05:48:21.953577Z","shell.execute_reply":"2023-01-23T05:48:21.959325Z"},"trusted":true},"execution_count":38,"outputs":[]},{"cell_type":"code","source":"model.compile(\n optimizer='adam',\n loss=loss\n)","metadata":{"id":"d1J3AtaM11k-","execution":{"iopub.status.busy":"2023-01-23T05:48:22.838668Z","iopub.execute_input":"2023-01-23T05:48:22.838911Z","iopub.status.idle":"2023-01-23T05:48:22.856775Z","shell.execute_reply.started":"2023-01-23T05:48:22.838884Z","shell.execute_reply":"2023-01-23T05:48:22.856104Z"},"trusted":true},"execution_count":39,"outputs":[]},{"cell_type":"code","source":"EPOCHS = 35\nhistory = model.fit(dataset, epochs=EPOCHS, callbacks = [checkpoint_callback])","metadata":{"id":"z3ZPuTza168O","execution":{"iopub.status.busy":"2023-01-23T05:48:23.341195Z","iopub.execute_input":"2023-01-23T05:48:23.341457Z","iopub.status.idle":"2023-01-23T05:53:33.370272Z","shell.execute_reply.started":"2023-01-23T05:48:23.341429Z","shell.execute_reply":"2023-01-23T05:53:33.369333Z"},"trusted":true},"execution_count":40,"outputs":[{"name":"stdout","text":"Epoch 1/35\n172/172 [==============================] - 10s 41ms/step - loss: 3.2216\nEpoch 2/35\n172/172 [==============================] - 9s 41ms/step - loss: 2.0509\nEpoch 3/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.7478\nEpoch 4/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.5806\nEpoch 5/35\n172/172 [==============================] - 9s 42ms/step - loss: 1.4736\nEpoch 6/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.4061\nEpoch 7/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.3548\nEpoch 8/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.3132\nEpoch 9/35\n172/172 [==============================] - 9s 42ms/step - loss: 1.2787\nEpoch 10/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.2442\nEpoch 11/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.2064\nEpoch 12/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.1746\nEpoch 13/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.1417\nEpoch 14/35\n172/172 [==============================] - 9s 42ms/step - loss: 1.1077\nEpoch 15/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.0724\nEpoch 16/35\n172/172 [==============================] - 9s 42ms/step - loss: 1.0369\nEpoch 17/35\n172/172 [==============================] - 9s 41ms/step - loss: 1.0011\nEpoch 18/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.9657\nEpoch 19/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.9257\nEpoch 20/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.8903\nEpoch 21/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.8564\nEpoch 22/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.8274\nEpoch 23/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.7986\nEpoch 24/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.7736\nEpoch 25/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.7469\nEpoch 26/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.7277\nEpoch 27/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.7115\nEpoch 28/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.6967\nEpoch 29/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.6821\nEpoch 30/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.6732\nEpoch 31/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.6618\nEpoch 32/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.6527\nEpoch 33/35\n172/172 [==============================] - 9s 41ms/step - loss: 0.6437\nEpoch 34/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.6404\nEpoch 35/35\n172/172 [==============================] - 9s 42ms/step - loss: 0.6350\n","output_type":"stream"}]},{"cell_type":"code","source":"lossPlot = pd.DataFrame(history.history)\nlossPlot.plot()","metadata":{"id":"ciJjklck2EME","execution":{"iopub.status.busy":"2023-01-23T05:53:35.864744Z","iopub.execute_input":"2023-01-23T05:53:35.867516Z","iopub.status.idle":"2023-01-23T05:53:36.122448Z","shell.execute_reply.started":"2023-01-23T05:53:35.867466Z","shell.execute_reply":"2023-01-23T05:53:36.121666Z"},"trusted":true},"execution_count":41,"outputs":[{"execution_count":41,"output_type":"execute_result","data":{"text/plain":"<AxesSubplot:>"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"<Figure size 432x288 with 1 Axes>","image/png":"iVBORw0KGgoAAAANSUhEUgAAAXoAAAD7CAYAAABkO19ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAndUlEQVR4nO3de3zU9Z3v8dcnyeSeQO73cPGCIgJCRK0Wta0U77fW1W272Bu7Pban7enp2W67Z9t1221P3a3b3XbXsq1b7dbrikqtF9CqaFcrAcJdEBFIQkgCISQQEnL5nD9msBETMoGBmcy8n4/HPPKb7+83M5/5PfQ9P76/7+/3NXdHRETiV1K0CxARkZNLQS8iEucU9CIicU5BLyIS5xT0IiJxTkEvIhLnUkbawMyqgPuBEsCBRe7+46O2+TrwiUHveTZQ5O5tZrYd6AT6gT53r4lc+SIiMhIbaRy9mZUBZe6+ysxygJXADe6+cZjtrwW+6u4fCj3fDtS4+56IVi4iImEZ8Yje3ZuAptByp5ltAiqAIYMeuA148ESKKiws9IkTJ57IW4iIJJSVK1fucfeiodaNGPSDmdlE4DzgD8OszwTmA18c1OzAUjNz4Gfuvmikz5k4cSK1tbWjKU1EJKGZ2Y7h1oUd9GaWDTwGfMXdO4bZ7Frg9+7eNqjtEndvNLNiYJmZvenuy4d4/4XAQoDq6upwyxIRkRGENerGzAIEQ/7X7r74GJveylHdNu7eGPrbAjwOzBnqhe6+yN1r3L2mqGjIf32IiMhxGDHozcyAXwCb3P1Hx9huHHAp8OSgtqzQCVzMLAuYB6w/0aJFRCR84XTdXAx8ClhnZnWhtm8C1QDufk+o7UZgqbsfHPTaEuDx4G8FKcAD7v5sBOoWETmm3t5eGhoa6O7ujnYpEZWenk5lZSWBQCDs14Qz6uZVwMLY7pfAL49q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nM6oAWYBnBnoB2d+8LbRJz2XF0ze5+ZD9/L7Sf7zaztGO9R7wE/Vh1ibvPAq4E7jCzudEuaLQ8+G/KsTB069+A04CZQBPwj1GtZghmlg08BnzF3TsGr4vV/TxEzTG9n929391nApUEewLOim5FIzu6ZjObBvwVwdrPB/KBvzzWe8RL0DcCVYOeV4baYpq7N4b+tgCPE/wPbyxoNrMygNDflijXMyJ3bw79DzMA/Dsxtq/NLEAwMH/t7otDzTG9n4eqOdb38xHu3g68CFwEjDezlNCqmM2OQTXPD3Wdubv3AP/BCPs5XoJ+BXBG6Ox5KnArsCTKNR2TmWWZWc6RZWAesP7Yr4oZS4AFoeUFwJNRrCUsRwIz5EZiaF+bmQG/ADa5+48GrYrZ/TxczTG+n4vMbHxoOQO4guC5hReBj4U2i7X9PFTNbw46ADCC5xSOuZ/j5oKp0DCufyI4Auded/9edCs6NjObTPAoHiAFeCAWazazB4HLCN4xrxn4NvAEwZEK1QTvMnqLu8fMyc9har6MYHeCExzt9OeD+r+jyswuAV4B1gEDoeZvEuzzjsn9fIyabyN29/N0gidbkwke5D7i7neG/l98iGAXyGrgk6Ej5ag7Rs2/A4oIjsqpA/5i0Enb979PvAS9iIgMLV66bkREZBgKehGROKegFxGJcwp6EZE4p6AXEYlzCnoRkTinoBcRiXMKehGROPf/AZJU1FEm9kB0AAAAAElFTkSuQmCC\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"code","source":"tf.train.latest_checkpoint(checkpoint_dir)\n\nmodel = build_model(vocab_size, embedding_dim, rnn_units, batch_size=1)\n\nmodel.load_weights(tf.train.latest_checkpoint(checkpoint_dir))\n\nmodel.build(tf.TensorShape([1, None]))\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:53:38.925436Z","iopub.execute_input":"2023-01-23T05:53:38.925714Z","iopub.status.idle":"2023-01-23T05:53:39.188346Z","shell.execute_reply.started":"2023-01-23T05:53:38.925686Z","shell.execute_reply":"2023-01-23T05:53:39.186962Z"},"trusted":true},"execution_count":42,"outputs":[{"name":"stdout","text":"Model: \"sequential_3\"\n_________________________________________________________________\nLayer (type) Output Shape Param # \n=================================================================\nembedding_3 (Embedding) (1, None, 256) 16640 \n_________________________________________________________________\ngru_3 (GRU) (1, None, 1024) 3938304 \n_________________________________________________________________\ndense_3 (Dense) (1, None, 65) 66625 \n=================================================================\nTotal params: 4,021,569\nTrainable params: 4,021,569\nNon-trainable params: 0\n_________________________________________________________________\n","output_type":"stream"}]},{"cell_type":"code","source":"model.save('model.h5')","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:53:40.113042Z","iopub.execute_input":"2023-01-23T05:53:40.113336Z","iopub.status.idle":"2023-01-23T05:53:40.163870Z","shell.execute_reply.started":"2023-01-23T05:53:40.113305Z","shell.execute_reply":"2023-01-23T05:53:40.162900Z"},"trusted":true},"execution_count":43,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.models.load_model('model.h5')","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:55:04.484716Z","iopub.execute_input":"2023-01-23T05:55:04.484998Z","iopub.status.idle":"2023-01-23T05:55:04.716204Z","shell.execute_reply.started":"2023-01-23T05:55:04.484967Z","shell.execute_reply":"2023-01-23T05:55:04.715394Z"},"trusted":true},"execution_count":51,"outputs":[]},{"cell_type":"code","source":"def generate_text(model, start_string=u'ROMEO:', num_generate=1000, temperature=0.7):\n input_eval = [char2idx[s] for s in start_string]\n input_eval = tf.expand_dims(input_eval, 0)\n\n text_generated = []\n\n model.reset_states()\n for i in range(num_generate):\n predictions = model(input_eval)\n predictions = tf.squeeze(predictions, 0)\n predictions = predictions / temperature\n predicted_id = tf.random.categorical(predictions, num_samples=1)[-1,0].numpy()\n input_eval = tf.expand_dims([predicted_id], 0)\n text_generated.append(idx2char[predicted_id])\n\n return (start_string + ''.join(text_generated))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:59:17.611210Z","iopub.execute_input":"2023-01-23T05:59:17.611527Z","iopub.status.idle":"2023-01-23T05:59:17.618325Z","shell.execute_reply.started":"2023-01-23T05:59:17.611490Z","shell.execute_reply":"2023-01-23T05:59:17.617438Z"},"trusted":true},"execution_count":58,"outputs":[]},{"cell_type":"code","source":"print(generate_text(model))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T05:59:17.959537Z","iopub.execute_input":"2023-01-23T05:59:17.959774Z","iopub.status.idle":"2023-01-23T05:59:21.962224Z","shell.execute_reply.started":"2023-01-23T05:59:17.959748Z","shell.execute_reply":"2023-01-23T05:59:21.961442Z"},"trusted":true},"execution_count":59,"outputs":[{"name":"stdout","text":"ROMEO:\nWhy, many, sir, what place can witness and the man of some unreverent sinking.\nThe news to say to me, he brings the men of Greece\nAnd bear the self-same tongue; as at the store of men,\nThe queen is coming.\n\nPERDITA:\nSo will, I do not\nThus proclaim us from our hands whose wars death is a devil.\n\nLADY MOPt not from him;\nBut thou the king, post to thy beauty,\nAnd made Verona's sake, Sir John, who being so happy?\n\nThird Servant:\nThat is the best of our friends with silence,\nOr else new form'd him.\n\nSICINIUS:\nShall lie alone;\nLest I rest to say, Signior Prince of Warwick,\nAnd he shall she the belly sir.\n\nCORIOLANUS:\nAway!\n\nSecond Servant:\nOr seeming, COMINIUS:\nFor my peace is mine.\n\nKING RICHARD II:\nWhy straight did I think the weakest world,\nThat we will plant so wide as aught and hazard of the father's voice,\nThat at the boy, if mine own carver man: if she have recourse us.\n\nMessenger:\nShe whom I love.\n\nSecond Murderer:\nO sir, you were possess'd, when thou camest here in the\nThe truth, o\n","output_type":"stream"}]}]}
\ No newline at end of file diff --git a/client.py b/client.py new file mode 100644 index 0000000..7b14701 --- /dev/null +++ b/client.py @@ -0,0 +1,33 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + +import tensorflow as tf + +model = tf.keras.models.load_model('model.h5', compile=False) + +char2idx = {'\n': 0, ' ': 1, '!': 2, '$': 3, '&': 4, "'": 5, ',': 6, '-': 7, '.': 8, '3': 9, ':': 10, ';': 11, '?': 12, 'A': 13, 'B': 14, 'C': 15, 'D': 16, 'E': 17, 'F': 18, 'G': 19, 'H': 20, 'I': 21, 'J': 22, 'K': 23, 'L': 24, 'M': 25, 'N': 26, 'O': 27, 'P': 28, 'Q': 29, 'R': 30, 'S': 31, 'T': 32, 'U': 33, 'V': 34, 'W': 35, 'X': 36, 'Y': 37, 'Z': 38, 'a': 39, 'b': 40, 'c': 41, 'd': 42, 'e': 43, 'f': 44, 'g': 45, 'h': 46, 'i': 47, 'j': 48, 'k': 49, 'l': 50, 'm': 51, 'n': 52, 'o': 53, 'p': 54, 'q': 55, 'r': 56, 's': 57, 't': 58, 'u': 59, 'v': 60, 'w': 61, 'x': 62, 'y': 63, 'z': 64} +idx2char = ['\n', ' ', '!', '$', '&', "'", ',', '-', '.', '3', ':', ';', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + +def generate_text(model, start_string=u'ROMEO:', num_generate=1000, temperature=0.7): + num_generate = 1000 + + input_eval = [char2idx[s] for s in start_string] + input_eval = tf.expand_dims(input_eval, 0) + + text_generated = [] + + temperature = 0.7 + + model.reset_states() + for i in range(num_generate): + predictions = model(input_eval) + predictions = tf.squeeze(predictions, 0) + predictions = predictions / temperature + predicted_id = tf.random.categorical(predictions, num_samples=1)[-1,0].numpy() + print(predicted_id) + input_eval = tf.expand_dims([predicted_id], 0) + text_generated.append(idx2char[predicted_id]) + + return (start_string + ''.join(text_generated)) + +print(generate_text(model)) diff --git a/convert.sh b/convert.sh new file mode 100755 index 0000000..b8f780d --- /dev/null +++ b/convert.sh @@ -0,0 +1,2 @@ +#!/bin/bash +tensorflowjs_converter --input_format keras model.h5 jsmodel diff --git a/jsmodel/group1-shard1of4.bin b/jsmodel/group1-shard1of4.bin Binary files differnew file mode 100644 index 0000000..50f742e --- /dev/null +++ b/jsmodel/group1-shard1of4.bin diff --git a/jsmodel/group1-shard2of4.bin b/jsmodel/group1-shard2of4.bin Binary files differnew file mode 100644 index 0000000..f60c458 --- /dev/null +++ b/jsmodel/group1-shard2of4.bin diff --git a/jsmodel/group1-shard3of4.bin b/jsmodel/group1-shard3of4.bin Binary files differnew file mode 100644 index 0000000..e682033 --- /dev/null +++ b/jsmodel/group1-shard3of4.bin diff --git a/jsmodel/group1-shard4of4.bin b/jsmodel/group1-shard4of4.bin Binary files differnew file mode 100644 index 0000000..200da57 --- /dev/null +++ b/jsmodel/group1-shard4of4.bin diff --git a/jsmodel/model.json b/jsmodel/model.json new file mode 100644 index 0000000..0de300d --- /dev/null +++ b/jsmodel/model.json @@ -0,0 +1 @@ +{"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v4.2.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [1, null], "dtype": "float32", "sparse": false, "ragged": false, "name": "embedding_1_input"}}, {"class_name": "Embedding", "config": {"name": "embedding_1", "trainable": true, "batch_input_shape": [1, null], "dtype": "float32", "input_dim": 65, "output_dim": 256, "embeddings_initializer": {"class_name": "RandomUniform", "config": {"minval": -0.05, "maxval": 0.05, "seed": null}}, "embeddings_regularizer": null, "activity_regularizer": null, "embeddings_constraint": null, "mask_zero": false, "input_length": null}}, {"class_name": "GRU", "config": {"name": "gru_1", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": true, "unroll": false, "time_major": false, "units": 1024, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2, "reset_after": false}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 65, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}}}, "weightsManifest": [{"paths": ["group1-shard1of4.bin", "group1-shard2of4.bin", "group1-shard3of4.bin", "group1-shard4of4.bin"], "weights": [{"name": "dense_1/kernel", "shape": [1024, 65], "dtype": "float32"}, {"name": "dense_1/bias", "shape": [65], "dtype": "float32"}, {"name": "embedding_1/embeddings", "shape": [65, 256], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/kernel", "shape": [256, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/recurrent_kernel", "shape": [1024, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/bias", "shape": [3072], "dtype": "float32"}]}]}
\ No newline at end of file diff --git a/model.h5 b/model.h5 Binary files differnew file mode 100644 index 0000000..fa63950 --- /dev/null +++ b/model.h5 diff --git a/web/favicon.ico b/web/favicon.ico new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/web/favicon.ico diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..3fcc91d --- /dev/null +++ b/web/index.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta http-equiv="X-UA-Compatible" content="ie=edge"> + <title>MyApp</title> + <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script> + </head> + <body> + <h1>Hello</h1> + <script src="script.js"></script> + </body> +</html> diff --git a/web/jsmodel/group1-shard1of4.bin b/web/jsmodel/group1-shard1of4.bin Binary files differnew file mode 100644 index 0000000..50f742e --- /dev/null +++ b/web/jsmodel/group1-shard1of4.bin diff --git a/web/jsmodel/group1-shard2of4.bin b/web/jsmodel/group1-shard2of4.bin Binary files differnew file mode 100644 index 0000000..f60c458 --- /dev/null +++ b/web/jsmodel/group1-shard2of4.bin diff --git a/web/jsmodel/group1-shard3of4.bin b/web/jsmodel/group1-shard3of4.bin Binary files differnew file mode 100644 index 0000000..e682033 --- /dev/null +++ b/web/jsmodel/group1-shard3of4.bin diff --git a/web/jsmodel/group1-shard4of4.bin b/web/jsmodel/group1-shard4of4.bin Binary files differnew file mode 100644 index 0000000..200da57 --- /dev/null +++ b/web/jsmodel/group1-shard4of4.bin diff --git a/web/jsmodel/model.json b/web/jsmodel/model.json new file mode 100644 index 0000000..0de300d --- /dev/null +++ b/web/jsmodel/model.json @@ -0,0 +1 @@ +{"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v4.2.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [1, null], "dtype": "float32", "sparse": false, "ragged": false, "name": "embedding_1_input"}}, {"class_name": "Embedding", "config": {"name": "embedding_1", "trainable": true, "batch_input_shape": [1, null], "dtype": "float32", "input_dim": 65, "output_dim": 256, "embeddings_initializer": {"class_name": "RandomUniform", "config": {"minval": -0.05, "maxval": 0.05, "seed": null}}, "embeddings_regularizer": null, "activity_regularizer": null, "embeddings_constraint": null, "mask_zero": false, "input_length": null}}, {"class_name": "GRU", "config": {"name": "gru_1", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": true, "unroll": false, "time_major": false, "units": 1024, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2, "reset_after": false}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 65, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}}}, "weightsManifest": [{"paths": ["group1-shard1of4.bin", "group1-shard2of4.bin", "group1-shard3of4.bin", "group1-shard4of4.bin"], "weights": [{"name": "dense_1/kernel", "shape": [1024, 65], "dtype": "float32"}, {"name": "dense_1/bias", "shape": [65], "dtype": "float32"}, {"name": "embedding_1/embeddings", "shape": [65, 256], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/kernel", "shape": [256, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/recurrent_kernel", "shape": [1024, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/bias", "shape": [3072], "dtype": "float32"}]}]}
\ No newline at end of file diff --git a/web/script.js b/web/script.js new file mode 100644 index 0000000..07fdd6b --- /dev/null +++ b/web/script.js @@ -0,0 +1,27 @@ +async function generate_text(model, idx2char, char2idx, start_string = 'ROMEO:', num_generate = 1000, temperature = 0.7) { + let input_eval = start_string.split('').map(s => char2idx[s]); + input_eval = tf.tensor1d(input_eval); + input_eval = tf.reshape(input_eval, [1, input_eval.size]); + + let text_generated = []; + + model.resetStates(); + for (let i = 0; i < num_generate; i++) { + let predictions = model.predict(input_eval); + predictions = predictions.squeeze(); + predictions = predictions.div(temperature); + let predicted_id = await tf.multinomial(predictions, 1).dataSync()[0]; + input_eval = tf.expandDims([predicted_id], 0); + text_generated.push(idx2char[predicted_id]); + console.log(i) + } + + console.log(text_generated.join('')); +} + +async function runModel() { + char2idx = {'\n': 0, ' ': 1, '!': 2, '$': 3, '&': 4, "'": 5, ',': 6, '-': 7, '.': 8, '3': 9, ':': 10, ';': 11, '?': 12, 'A': 13, 'B': 14, 'C': 15, 'D': 16, 'E': 17, 'F': 18, 'G': 19, 'H': 20, 'I': 21, 'J': 22, 'K': 23, 'L': 24, 'M': 25, 'N': 26, 'O': 27, 'P': 28, 'Q': 29, 'R': 30, 'S': 31, 'T': 32, 'U': 33, 'V': 34, 'W': 35, 'X': 36, 'Y': 37, 'Z': 38, 'a': 39, 'b': 40, 'c': 41, 'd': 42, 'e': 43, 'f': 44, 'g': 45, 'h': 46, 'i': 47, 'j': 48, 'k': 49, 'l': 50, 'm': 51, 'n': 52, 'o': 53, 'p': 54, 'q': 55, 'r': 56, 's': 57, 't': 58, 'u': 59, 'v': 60, 'w': 61, 'x': 62, 'y': 63, 'z': 64} + idx2char = ['\n', ' ', '!', '$', '&', "'", ',', '-', '.', '3', ':', ';', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + const model = await tf.loadLayersModel('/jsmodel/model.json'); + generate_text(model, idx2char, char2idx); +} |