{ "info": { "author": "CyberZHG", "author_email": "CyberZHG@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 3.7" ], "description": "# Keras Bi-LM\n\n[![Travis](https://travis-ci.org/CyberZHG/keras-bi-lm.svg)](https://travis-ci.org/CyberZHG/keras-bi-lm)\n[![Coverage](https://coveralls.io/repos/github/CyberZHG/keras-bi-lm/badge.svg?branch=master)](https://coveralls.io/github/CyberZHG/keras-bi-lm)\n\n## Introduction\n\nThe repository contains a class for training a bidirectional language model that extracts features for each position in a sentence.\n\n## Install\n\n```bash\npip install keras-bi-lm\n```\n\n## Usage\n\n### Train and save the Bi-LM model\n\nBefore using it as a feature extraction method, the language model must be trained on a large corpora.\n\n```python\nfrom keras_bi_lm import BiLM\n\nsentences = [\n ['All', 'work', 'and', 'no', 'play'],\n ['makes', 'Jack', 'a', 'dull', 'boy', '.'],\n]\ntoken_dict = {\n '': 0, '': 1, '': 2,\n 'all': 3, 'work': 4, 'and': 5, 'no': 6, 'play': 7,\n 'makes': 8, 'a': 9, 'dull': 10, 'boy': 11, '.': 12,\n}\ntoken_dict_rev = {v: k for k, v in token_dict.items()}\ninputs, outputs = BiLM.get_batch(sentences,\n token_dict,\n ignore_case=True,\n unk_index=token_dict[''],\n eos_index=token_dict[''])\n\nbi_lm = BiLM(token_num=len(token_dict), embedding_dim=10, rnn_units=10)\nbi_lm.model.summary()\nbi_lm.fit(np.repeat(inputs, 2 ** 12, axis=0),\n [\n np.repeat(outputs[0], 2 ** 12, axis=0),\n np.repeat(outputs[1], 2 ** 12, axis=0),\n ],\n epochs=5)\nbi_lm.save_model('bi_lm.h5')\n```\n\n#### `BiLM()`\n\nThe core class that contains the model to be trained and used. Key parameters:\n\n* `token_num`: Number of words or characters.\n* `embedding_dim`: The dimension of embedding layer.\n* `rnn_layer_num`: The number of stacked bidirectional RNNs.\n* `rnn_units`: An integer or a list representing the number of units of RNNs in one direction.\n* `rnn_keep_num`: How many layers are used for predicting the probabilities of the next word.\n* `rnn_type`: Type of RNN, 'gru' or 'lstm'.\n\n#### `BiLM.get_batch()`\n\nA helper function that converts sentences to batch inputs and outputs for training the model.\n\n* `sentences`: A list of list of tokens.\n* `token_dict`: The dict that maps a token to an integer. `` and `` should be preserved.\n* `ignore_case`: Whether ignoring the case of the token.\n* `unk_index`: The index for unknown token.\n* `eos_index`: The index for ending of sentence.\n\n### Load and use the Bi-LM model\n\n```python\nfrom keras_bi_lm import BiLM\n\nbi_lm = BiLM(model_path='bi_lm.h5') # or `bi_lm.load_model('bi_lm.h5')`\ninput_layer, output_layer = bi_lm.get_feature_layers()\nmodel = keras.models.Model(inputs=input_layer, outputs=output_layer)\nmodel.summary()\n```\n\nThe `output_layer` is the time-distributed feature and all the parameters in the layers of the model are not trainable.\n\n### Use ELMo-like Weighted Sum of Trained Layers\n\n```python\nfrom keras_bi_lm import BiLM\n\nbi_lm = BiLM(token_num=20000,\n embedding_dim=300,\n rnn_layer_num=3,\n rnn_keep_num=4,\n rnn_units=300,\n rnn_type='lstm',\n use_normalization=True)\n# ...\n# Train the Bi-LM model\n# ...\n\ninput_layer, output_layer = bi_lm.get_feature_layers(use_weighted_sum=True)\nmodel = keras.models.Model(inputs=input_layer, outputs=output_layer)\nmodel.summary()\n```\n\nWhen `rnn_keep_num` is greater than `rnn_layer_num`, the embedding layer is also used for weighting.\n\n## Demo\n\nSee `demo` directory:\n\n```bash\ncd demo\n./get_data.sh\npip install -r requirements.txt\npython setiment_analysis.py\n```\n\n## Citation\n\nJust cite the paper you've seen.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/CyberZHG/keras-bi-lm", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "keras-bi-lm", "package_url": "https://pypi.org/project/keras-bi-lm/", "platform": "", "project_url": "https://pypi.org/project/keras-bi-lm/", "project_urls": { "Homepage": "https://github.com/CyberZHG/keras-bi-lm" }, "release_url": "https://pypi.org/project/keras-bi-lm/0.23.0/", "requires_dist": null, "requires_python": "", "summary": "Train the Bi-LM model and use it as a feature extraction method", "version": "0.23.0" }, "last_serial": 4923774, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "47d458cba17cc8f25f6025aa6f2cb7ab", "sha256": "70b5d54feb03ec87a219c28ddb31b401f12841cc24e32c0bbd50ae6007fabef5" }, "downloads": -1, "filename": "keras-bi-lm-0.0.1.tar.gz", "has_sig": false, "md5_digest": "47d458cba17cc8f25f6025aa6f2cb7ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3176, "upload_time": "2018-08-06T03:46:59", "url": "https://files.pythonhosted.org/packages/10/c3/a9d4e081d029f2c4059b35d578c28e80089c6d1554fd7e85242270bac2e9/keras-bi-lm-0.0.1.tar.gz" } ], "0.0.10": [ { "comment_text": "", "digests": { "md5": "fea5af4d367ddc97091c0b009400375f", "sha256": "76462d2258668c980ab24b94bfc1503e39100bfcfc3c2f5bf3f05225b51b4541" }, "downloads": -1, "filename": "keras-bi-lm-0.0.10.tar.gz", "has_sig": false, "md5_digest": "fea5af4d367ddc97091c0b009400375f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4706, "upload_time": "2018-08-07T06:23:27", "url": "https://files.pythonhosted.org/packages/a3/b5/198b92ae504587af325096855d89b70b8bfa2ffefb734316f9e50ef30dc8/keras-bi-lm-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "0958cf38efdca317d9a00fd62eda2863", "sha256": "754adcc707efa614d943f70c2c8d4f7f7351f2f105bb4d0e5b3bcaca1035ed66" }, "downloads": -1, "filename": "keras-bi-lm-0.0.11.tar.gz", "has_sig": false, "md5_digest": "0958cf38efdca317d9a00fd62eda2863", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4812, "upload_time": "2018-08-07T06:45:24", "url": "https://files.pythonhosted.org/packages/9e/90/34ecab87817d2e46a4faf8a6181fdeafe0ec054520658b31e85b3b5d5092/keras-bi-lm-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "9b972bd60bb871693c99a67cdccd8bf0", "sha256": "9212ffc4ffa683bf241f8af304f1f016ada564ca0062829d8083e7234a847224" }, "downloads": -1, "filename": "keras-bi-lm-0.0.12.tar.gz", "has_sig": false, "md5_digest": "9b972bd60bb871693c99a67cdccd8bf0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4884, "upload_time": "2018-08-08T08:00:14", "url": "https://files.pythonhosted.org/packages/18/2f/925f76184501139a5ac66e4886e32881a81da73f8576aa3c2267a75d1679/keras-bi-lm-0.0.12.tar.gz" } ], "0.0.13": [ { "comment_text": "", "digests": { "md5": "06eee4acb7ac66d044297dd0c387bf81", "sha256": "42d6c0ecd9f908037884a8c6ad38da73e5322ae3ab6db916c3ec2fd0d7115bf5" }, "downloads": -1, "filename": "keras-bi-lm-0.0.13.tar.gz", "has_sig": false, "md5_digest": "06eee4acb7ac66d044297dd0c387bf81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4945, "upload_time": "2018-08-08T11:35:18", "url": "https://files.pythonhosted.org/packages/33/65/a32f45903e838ab0df65792063ab7c1020e28046bd0c5c913b881ea19695/keras-bi-lm-0.0.13.tar.gz" } ], "0.0.14": [ { "comment_text": "", "digests": { "md5": "ac210dead4cb8d2adb49e7267cc38e0b", "sha256": "2e0a1e115b3bb1bf065912018c10343dc147b24629fde0655395f605aaa8fe84" }, "downloads": -1, "filename": "keras-bi-lm-0.0.14.tar.gz", "has_sig": false, "md5_digest": "ac210dead4cb8d2adb49e7267cc38e0b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4969, "upload_time": "2018-08-09T09:16:29", "url": "https://files.pythonhosted.org/packages/ab/19/7b9d294ecd37f4b21e60f68828108a342baef584aff514577876cfe84f80/keras-bi-lm-0.0.14.tar.gz" } ], "0.0.15": [ { "comment_text": "", "digests": { "md5": "056092b61ad017639528cac3fbf04484", "sha256": "d193a967b5b77b814838ce65a1086097ebe02b3b52c6b32042c45e17902c6e23" }, "downloads": -1, "filename": "keras-bi-lm-0.0.15.tar.gz", "has_sig": false, "md5_digest": "056092b61ad017639528cac3fbf04484", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4959, "upload_time": "2018-08-09T09:17:16", "url": "https://files.pythonhosted.org/packages/7a/b6/a4860290fb4abe34f986568506d6660a271d1dada235aa86dbbad3790dc6/keras-bi-lm-0.0.15.tar.gz" } ], "0.0.16": [ { "comment_text": "", "digests": { "md5": "a20b38d960ac05b2cbc9de6f9d2cbafc", "sha256": "7b388d22182ef339c597704f8f0fa0c0142759043a8f6ed6c3546f93e8d97559" }, "downloads": -1, "filename": "keras-bi-lm-0.0.16.tar.gz", "has_sig": false, "md5_digest": "a20b38d960ac05b2cbc9de6f9d2cbafc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4959, "upload_time": "2018-08-15T07:44:10", "url": "https://files.pythonhosted.org/packages/39/98/e44ab334b966a11d0def41a0b810a5812cda2fc672dbcd0f381c5a118179/keras-bi-lm-0.0.16.tar.gz" } ], "0.0.17": [ { "comment_text": "", "digests": { "md5": "d464815809fc1770cfdfb471ec8891d6", "sha256": "ec02cf8c0cbdcf3356412696b59ecf70bd5519708a90cd32b067f66f61e7edc9" }, "downloads": -1, "filename": "keras-bi-lm-0.0.17.tar.gz", "has_sig": false, "md5_digest": "d464815809fc1770cfdfb471ec8891d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4958, "upload_time": "2018-08-17T09:44:07", "url": "https://files.pythonhosted.org/packages/4e/91/076e83c503bcf1b014353bfe1c688860c787ebf74d3fb9f618def940d857/keras-bi-lm-0.0.17.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "895d16bf6062ad9bec10f9529b33b357", "sha256": "199e1bc755c8d2d88f808341af6d7dfb3f003839dd58e44ac78cff3189eed68e" }, "downloads": -1, "filename": "keras-bi-lm-0.0.2.tar.gz", "has_sig": false, "md5_digest": "895d16bf6062ad9bec10f9529b33b357", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3223, "upload_time": "2018-08-06T05:00:24", "url": "https://files.pythonhosted.org/packages/f6/41/1a601daf0d1fc29ea4b96fa22e1b9fd92782fb635034270d55275ca4e25d/keras-bi-lm-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "2bd28aacf2342dc504f353d1c7756b9a", "sha256": "f163c3d7cd00904405197f3fb397d70f9140b7b4668055efa01804e182cc6300" }, "downloads": -1, "filename": "keras-bi-lm-0.0.3.tar.gz", "has_sig": false, "md5_digest": "2bd28aacf2342dc504f353d1c7756b9a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4499, "upload_time": "2018-08-06T08:01:39", "url": "https://files.pythonhosted.org/packages/32/9d/fef1c36851af4c2f8c1c19a1438dc5568f43edd91d50ba83e7679c0cf17e/keras-bi-lm-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "9ba6aa0194254041a22415077b13ace3", "sha256": "6b09cbe45c6bd12a7754e0c423f96789403d6960fc5d8de79e599f61c16f05bf" }, "downloads": -1, "filename": "keras-bi-lm-0.0.4.tar.gz", "has_sig": false, "md5_digest": "9ba6aa0194254041a22415077b13ace3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4562, "upload_time": "2018-08-06T08:38:37", "url": "https://files.pythonhosted.org/packages/4b/0a/176b375424eeae73c98aec332241ab2a44ccabbd2918d6b7397b00dd0c04/keras-bi-lm-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "2964651023420e0699d2fe8280148abf", "sha256": "b85bda0d1507da88b3b24e1b0b14db65b292ce25277b08926e70586699350b22" }, "downloads": -1, "filename": "keras-bi-lm-0.0.5.tar.gz", "has_sig": false, "md5_digest": "2964651023420e0699d2fe8280148abf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4607, "upload_time": "2018-08-06T11:45:08", "url": "https://files.pythonhosted.org/packages/90/63/c44be5dfac87fbf3414d7d7e1303e5045b1ce43a2cfcdab558f96cc4c0ab/keras-bi-lm-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "fb7ad75f750b97e79a8e3e793b31a117", "sha256": "a9045bf60af3ed82488a5f4d345c9989146bbf97fb1a5c8947d88c7b01ff2199" }, "downloads": -1, "filename": "keras-bi-lm-0.0.6.tar.gz", "has_sig": false, "md5_digest": "fb7ad75f750b97e79a8e3e793b31a117", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4626, "upload_time": "2018-08-06T11:54:23", "url": "https://files.pythonhosted.org/packages/c0/b5/b3aab1b0a5b400e2bd86b1544f3365ddf6e55ec6a101642e8181b5457c33/keras-bi-lm-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "f4cf96e5e130ccfeb970c35ad749a53c", "sha256": "eb81dfdd89d5d945509be3785bf07fe17a1565c2eb54dd4542c63ee7ac1c30dd" }, "downloads": -1, "filename": "keras-bi-lm-0.0.7.tar.gz", "has_sig": false, "md5_digest": "f4cf96e5e130ccfeb970c35ad749a53c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4618, "upload_time": "2018-08-07T02:29:48", "url": "https://files.pythonhosted.org/packages/3e/76/9210fe9d7ab347e045313ee27cfb3a01df843347bfa0878d2710f1f6697a/keras-bi-lm-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "fe6ce6e5230eea5c2cff437aab9fffe3", "sha256": "198f3bb80a13d637129ee806d48cf31c0b303c475569a698e9f83119ba6d3fb9" }, "downloads": -1, "filename": "keras-bi-lm-0.0.8.tar.gz", "has_sig": false, "md5_digest": "fe6ce6e5230eea5c2cff437aab9fffe3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4621, "upload_time": "2018-08-07T03:14:38", "url": "https://files.pythonhosted.org/packages/17/20/4920ab799ee41d492553b25f6ee1e0903b00fa39273c5fe546bec33c9406/keras-bi-lm-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "d7021828995dea42d144837bc1f2b4d0", "sha256": "0b4506c29717423d0f8423b4c1ad5689d7db90a0d4322cdc5156b613fdd88e22" }, "downloads": -1, "filename": "keras-bi-lm-0.0.9.tar.gz", "has_sig": false, "md5_digest": "d7021828995dea42d144837bc1f2b4d0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4631, "upload_time": "2018-08-07T03:22:12", "url": "https://files.pythonhosted.org/packages/f8/28/3c80e467a74bb16c4adb674230a56438eb31891e0e812c6d41d6444b642c/keras-bi-lm-0.0.9.tar.gz" } ], "0.18": [ { "comment_text": "", "digests": { "md5": "fe8e6ee16b3a2d0992bab3ce18d9bf3c", "sha256": "3be3d001aba1863d64bf97e212e1736b2dac9f106aeae1c6907675a0868fb32c" }, "downloads": -1, "filename": "keras-bi-lm-0.18.tar.gz", "has_sig": false, "md5_digest": "fe8e6ee16b3a2d0992bab3ce18d9bf3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4966, "upload_time": "2018-09-13T09:40:54", "url": "https://files.pythonhosted.org/packages/da/28/f34ca426d0b98ffa6228959ea0a77c589e8f5ac46eee3201b960732641ab/keras-bi-lm-0.18.tar.gz" } ], "0.21.0": [ { "comment_text": "", "digests": { "md5": "6b51d1f7245ce56f213ceb8767ea85aa", "sha256": "d21f156467220610eed168410bb0449874da5d7086f93116a95991ad1bbd94cd" }, "downloads": -1, "filename": "keras-bi-lm-0.21.0.tar.gz", "has_sig": false, "md5_digest": "6b51d1f7245ce56f213ceb8767ea85aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6416, "upload_time": "2018-10-30T08:09:49", "url": "https://files.pythonhosted.org/packages/2e/91/255bca665daaf74ef28398ccf5ec38f9a793a8c4fd425c58345da6253b92/keras-bi-lm-0.21.0.tar.gz" } ], "0.22.0": [ { "comment_text": "", "digests": { "md5": "80ed76a72b305d7c97e0a463be14ab43", "sha256": "0adef4c0f247aaac074f61905c60d14de8e480c88438a8c8a67273bc507f349d" }, "downloads": -1, "filename": "keras-bi-lm-0.22.0.tar.gz", "has_sig": false, "md5_digest": "80ed76a72b305d7c97e0a463be14ab43", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6511, "upload_time": "2019-02-01T02:49:47", "url": "https://files.pythonhosted.org/packages/31/eb/67dd6bb521b225236883c9f62a774fc8aa745fc3a0309d6a904c5b073366/keras-bi-lm-0.22.0.tar.gz" } ], "0.23.0": [ { "comment_text": "", "digests": { "md5": "4caff4681d43058170ce24dae6e8e03b", "sha256": "b505570109c238baea4b04de63874dfbdf4af18328eba47a95bb459681237a8e" }, "downloads": -1, "filename": "keras-bi-lm-0.23.0.tar.gz", "has_sig": false, "md5_digest": "4caff4681d43058170ce24dae6e8e03b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6506, "upload_time": "2019-03-11T06:35:43", "url": "https://files.pythonhosted.org/packages/e7/1a/d5fd23328e932d0d28b0582affb6fdf8d479e8243b79e6bf43f675d3210c/keras-bi-lm-0.23.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4caff4681d43058170ce24dae6e8e03b", "sha256": "b505570109c238baea4b04de63874dfbdf4af18328eba47a95bb459681237a8e" }, "downloads": -1, "filename": "keras-bi-lm-0.23.0.tar.gz", "has_sig": false, "md5_digest": "4caff4681d43058170ce24dae6e8e03b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6506, "upload_time": "2019-03-11T06:35:43", "url": "https://files.pythonhosted.org/packages/e7/1a/d5fd23328e932d0d28b0582affb6fdf8d479e8243b79e6bf43f675d3210c/keras-bi-lm-0.23.0.tar.gz" } ] }