{ "info": { "author": "Kilian Batzner", "author_email": "tensorlm@kilians.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3 :: Only", "Topic :: Scientific/Engineering :: Artificial Intelligence" ], "description": "tensorlm\n========\n\nGenerate Shakespeare poems with 4 lines of code.\n\nInstallation\n------------\n\n``tensorlm`` is written in / for Python 3.4+ and TensorFlow 1.1+\n\n::\n\n pip3 install tensorlm\n\nBasic Usage\n-----------\n\nUse the ``CharLM`` or ``WordLM`` class:\n\n.. code:: python\n\n import tensorflow as tf\n from tensorlm import CharLM\n \n with tf.Session() as session:\n \n # Create a new model. You can also use WordLM\n model = CharLM(session, \"datasets/sherlock/tinytrain.txt\", max_vocab_size=96,\n neurons_per_layer=100, num_layers=3, num_timesteps=15)\n \n # Train it \n model.train(session, max_epochs=5, max_steps=500)\n \n # Let it generate a text\n generated = model.sample(session, \"The \", num_steps=100)\n print(\"The \" + generated)\n\nThis should output something like:\n\n::\n\n The ee e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e \n\nCommand Line Usage\n------------------\n\n**Train:**\n``python3 -m tensorlm.cli --train=True --level=char --train_text_path=datasets/sherlock/tinytrain.txt --max_vocab_size=96 --neurons_per_layer=100 --num_layers=2 --batch_size=10 --num_timesteps=15 --save_dir=out/model --max_epochs=300 --save_interval_hours=0.5``\n\n**Sample:**\n``python3 -m tensorlm.cli --sample=True --level=char --neurons_per_layer=400 --num_layers=3 --num_timesteps=160 --save_dir=out/model``\n\n**Evaluate:**\n``python3 -m tensorlm.cli --evaluate=True --level=char --evaluate_text_path=datasets/sherlock/tinyvalid.txt --neurons_per_layer=400 --num_layers=3 --batch_size=10 --num_timesteps=160 --save_dir=out/model``\n\nSee ``python3 -m tensorlm.cli --help`` for all options.\n\nAdvanced Usage\n--------------\n\nCustom Input Data\n~~~~~~~~~~~~~~~~~\n\nThe inputs and targets don\u2019t have to be text. ``GeneratingLSTM`` only\nexpects token ids, so you can use any data type for the sequences, as\nlong as you can encode the data to integer ids.\n\n.. code:: python\n\n # We use integer ids from 0 to 19, so the vocab size is 20. The range of ids must always start\n # at zero.\n batch_inputs = np.array([[1, 2, 3, 4], [15, 16, 17, 18]]) # 2 batches, 4 time steps each\n batch_targets = np.array([[2, 3, 4, 5], [16, 17, 18, 19]])\n\n # Create the model in a TensorFlow graph\n model = GeneratingLSTM(vocab_size=20, neurons_per_layer=10, num_layers=2, max_batch_size=2)\n\n # Initialize all defined TF Variables\n session.run(tf.global_variables_initializer())\n\n for _ in range(5000):\n model.train_step(session, batch_inputs, batch_targets)\n\n sampled = model.sample_ids(session, [15], num_steps=3)\n print(\"Sampled: \" + str(sampled))\n\nThis should output something like:\n\n::\n\n Sampled: [16, 18, 19]\n\nCustom Training, Dropout etc.\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nUse the ``GeneratingLSTM`` class directly. This class is agnostic to the\ndataset type. It expects integer ids and returns integer ids.\n\n.. code:: python\n\n import tensorflow as tf\n from tensorlm import Vocabulary, Dataset, GeneratingLSTM\n\n BATCH_SIZE = 20\n NUM_TIMESTEPS = 15\n\n with tf.Session() as session:\n # Generate a token -> id vocabulary based on the text\n vocab = Vocabulary.create_from_text(\"datasets/sherlock/tinytrain.txt\", max_vocab_size=96,\n level=\"char\")\n\n # Obtain input and target batches from the text file\n dataset = Dataset(\"datasets/sherlock/tinytrain.txt\", vocab, BATCH_SIZE, NUM_TIMESTEPS)\n\n # Create the model in a TensorFlow graph\n model = GeneratingLSTM(vocab_size=vocab.get_size(), neurons_per_layer=100, num_layers=2,\n max_batch_size=BATCH_SIZE, output_keep_prob=0.5)\n\n # Initialize all defined TF Variables\n session.run(tf.global_variables_initializer())\n\n # Do the training\n epoch = 1\n step = 1\n for epoch in range(20):\n for inputs, targets in dataset:\n loss = model.train_step(session, inputs, targets)\n\n if step % 100 == 0:\n # Evaluate from time to time\n dev_dataset = Dataset(\"datasets/sherlock/tinyvalid.txt\", vocab,\n batch_size=BATCH_SIZE, num_timesteps=NUM_TIMESTEPS)\n dev_loss = model.evaluate(session, dev_dataset)\n print(\"Epoch: %d, Step: %d, Train Loss: %f, Dev Loss: %f\" % (\n epoch, step, loss, dev_loss))\n\n # Sample from the model from time to time\n print(\"Sampled: \\\"The \" + model.sample_text(session, vocab, \"The \") + \"\\\"\")\n\n step += 1\n\nThis should output something like:\n\n::\n\n Epoch: 3, Step: 100, Train Loss: 3.824941, Dev Loss: 3.778008\n Sampled: \"The \"\n Epoch: 7, Step: 200, Train Loss: 2.832825, Dev Loss: 2.896187\n Sampled: \"The \"\n Epoch: 11, Step: 300, Train Loss: 2.778579, Dev Loss: 2.830176\n Sampled: \"The eee \"\n Epoch: 15, Step: 400, Train Loss: 2.655153, Dev Loss: 2.684828\n Sampled: \"The ee e e e e e e e e e e e e e e e e e e e e e e e e e e e \"\n Epoch: 19, Step: 500, Train Loss: 2.444502, Dev Loss: 2.479753\n Sampled: \"The an an an on on on on on on on on on on on on on on on on on on on on on o\"\n", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/batzner/tensorlm/archive/v0.4.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/batzner/tensorlm", "keywords": "tensorflow", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "tensorlm", "package_url": "https://pypi.org/project/tensorlm/", "platform": "", "project_url": "https://pypi.org/project/tensorlm/", "project_urls": { "Download": "https://github.com/batzner/tensorlm/archive/v0.4.2.tar.gz", "Homepage": "https://github.com/batzner/tensorlm" }, "release_url": "https://pypi.org/project/tensorlm/0.4.2/", "requires_dist": null, "requires_python": "", "summary": "TensorFlow wrapper for deep neural text generation on character or word level with RNNs / LSTMs", "version": "0.4.2" }, "last_serial": 3747859, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b9110589493680534c72ad0214312c5d", "sha256": "92efa334883fb4e7f25db52af6a144b4c331a485d9666ba6b9bda94827b5656a" }, "downloads": -1, "filename": "tensorlm-0.1.tar.gz", "has_sig": false, "md5_digest": "b9110589493680534c72ad0214312c5d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22711, "upload_time": "2017-08-30T11:55:09", "url": "https://files.pythonhosted.org/packages/6e/31/9bbffe12bd459eea77d2f1886d84e31083dc48ce24429084d07dcad8ef65/tensorlm-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "287fd30c9547f362a0e12ad21f7b23e2", "sha256": "5c9bff74ccc69330d2dca34ef1df92e549436ac191f5aba1328f7d10d85b90e2" }, "downloads": -1, "filename": "tensorlm-0.2.tar.gz", "has_sig": false, "md5_digest": "287fd30c9547f362a0e12ad21f7b23e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21703, "upload_time": "2017-08-30T12:06:48", "url": "https://files.pythonhosted.org/packages/1d/5a/7b97bf9a5e825db537ffd7a87a37ac12523c580dce604dc32fe1e526643f/tensorlm-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "bf4e68f29e761fcec95c85cfa4c00d1e", "sha256": "fe5ba4d28f3021a7223a3d5c22ebf4687ef84e7c820895ac5373212ff9366d17" }, "downloads": -1, "filename": "tensorlm-0.3.tar.gz", "has_sig": false, "md5_digest": "bf4e68f29e761fcec95c85cfa4c00d1e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21808, "upload_time": "2017-08-30T12:10:55", "url": "https://files.pythonhosted.org/packages/40/10/29ad0fa9f0fde4a287aaf01f6defc6755ccfffa319ab20c33a04bd9c6ab8/tensorlm-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "38d9e5ddcbb93cc6f8c2c684e3206eae", "sha256": "7d9156a60e7299c807916cafbf3ff8d4aaccc51729a4b8439da4c89d40a66cc1" }, "downloads": -1, "filename": "tensorlm-0.4.tar.gz", "has_sig": false, "md5_digest": "38d9e5ddcbb93cc6f8c2c684e3206eae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23327, "upload_time": "2018-04-09T08:09:20", "url": "https://files.pythonhosted.org/packages/ac/79/20e12938b9cebd3f0ac173526d1ff1528b3d1dfeb395e9713c878489f318/tensorlm-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "8287e1647c5ba306559c06b74cba92b5", "sha256": "49c5d436537978b08a8b93412dfd7280d833dab5f663f123fe2b715f1899f5a3" }, "downloads": -1, "filename": "tensorlm-0.4.1.tar.gz", "has_sig": false, "md5_digest": "8287e1647c5ba306559c06b74cba92b5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23380, "upload_time": "2018-04-09T08:31:38", "url": "https://files.pythonhosted.org/packages/be/7d/e773a4dda8ddf8b42538cc62bf5b212aa8caf6170f02881c1edac0eafe2f/tensorlm-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "13fc437a0d9fe7fae1a2567a352e9831", "sha256": "323286c7231d56b18c68896fad114333342e6389b8ffb190127d753038c865cf" }, "downloads": -1, "filename": "tensorlm-0.4.2.tar.gz", "has_sig": false, "md5_digest": "13fc437a0d9fe7fae1a2567a352e9831", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23202, "upload_time": "2018-04-09T08:36:33", "url": "https://files.pythonhosted.org/packages/74/23/844fab370dcf69182fb7088e1738f30871a34bc1b2fe5ee592c15f2bb541/tensorlm-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "13fc437a0d9fe7fae1a2567a352e9831", "sha256": "323286c7231d56b18c68896fad114333342e6389b8ffb190127d753038c865cf" }, "downloads": -1, "filename": "tensorlm-0.4.2.tar.gz", "has_sig": false, "md5_digest": "13fc437a0d9fe7fae1a2567a352e9831", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23202, "upload_time": "2018-04-09T08:36:33", "url": "https://files.pythonhosted.org/packages/74/23/844fab370dcf69182fb7088e1738f30871a34bc1b2fe5ee592c15f2bb541/tensorlm-0.4.2.tar.gz" } ] }