{"id":19345174,"url":"https://github.com/kklemon/keras-loves-torchtext","last_synced_at":"2025-09-24T00:25:47.033Z","repository":{"id":62573984,"uuid":"150797835","full_name":"kklemon/keras-loves-torchtext","owner":"kklemon","description":"Make Torchtext work with Keras.","archived":false,"fork":false,"pushed_at":"2019-04-03T05:25:45.000Z","size":8,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T11:32:37.547Z","etag":null,"topics":["data-science","deep-learning","keras","natural-language-processing","pytorch","tensorflow","torchtext"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kklemon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-28T21:48:27.000Z","updated_at":"2022-06-27T18:18:39.000Z","dependencies_parsed_at":"2022-11-03T16:15:19.118Z","dependency_job_id":null,"html_url":"https://github.com/kklemon/keras-loves-torchtext","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklemon%2Fkeras-loves-torchtext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklemon%2Fkeras-loves-torchtext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklemon%2Fkeras-loves-torchtext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklemon%2Fkeras-loves-torchtext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kklemon","download_url":"https://codeload.github.com/kklemon/keras-loves-torchtext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372461,"owners_count":21419719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","deep-learning","keras","natural-language-processing","pytorch","tensorflow","torchtext"],"created_at":"2024-11-10T04:05:14.005Z","updated_at":"2025-09-24T00:25:41.993Z","avatar_url":"https://github.com/kklemon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Keras ❤️ torchtext\n=================\n\n\u003e Keras is love  \nKeras is life  \nKeras loves torchtext\n\n[torchtext](https://github.com/pytorch/text) is a great library, putting a layer of abstraction over the usually very heavy data component in NLP projects, making the work with complex datasets a pace.\nSadly, as torchtext is based and built on PyTorch, using it with Keras is not directly possible.\n\n_Keras ❤️ torchtext_ is to the rescue by providing lightweight wrappers for some Torchtext classes, making them easily work with Keras.\n\nInstallation\n------------\n```bash\npip install keras-loves-torchtext\n```\n\nExamples\n--------\nWrap a `torchtext.data.Iterator` with `WrapIterator` and use it to train a Keras model:\n```python\nfrom torchtext.data import Dataset, Field, Iterator\nfrom kltt import WrapIterator\n\n...\n\nfields  = [('text', Field()),\n           ('label', Field(sequential=False))]\ndataset = Dataset(examples, fields)\niterator = Iterator(dataset, batch_size=32)\n\n# Keras ❤️ torchtext comes to play\ndata_gen = WrapIterator(iterator, x_fields=['text'], y_fields=['label'])\n\nmodel.fit_generator(iter(data_gen), steps_per_epoch=len(data_gen))\n```\n\n\nEasily wrap multiple iterators at once:\n```python\nfrom torchtext.data import Dataset, Field, Iterator\nfrom kltt import WrapIterator\n\n...\n\nfields  = [('text', Field()),\n           ('label', Field(sequential=False))]\ndataset = Dataset(examples, fields)\nsplits = dataset.split()\n\niterators = Iterator.splits(splits, batch_size=32)\ntrain, valid, test = WrapIterator.wraps(iterators, x_fields=['text'], y_fields=['label'])\nmodel.fit_generator(iter(train), steps_per_epoch=len(train),\n                    validation_data=iter(valid), validation_steps=len(valid))\nloss, acc = model.evaluate_generator(iter(test), steps=len(test))\n```\n\nFurther and full working examples can be found in the `examples` folder. \n\nDocumentation\n-------------\nTodo\n\nSee `examples` and inline documentation for now.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklemon%2Fkeras-loves-torchtext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkklemon%2Fkeras-loves-torchtext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklemon%2Fkeras-loves-torchtext/lists"}