Text utilities and datasets for PyTorch
Project description
torchtext
This repository consists of:
torchtext.datasets: The raw text iterators for common NLP datasets
torchtext.data: Some basic NLP building blocks (tokenizers, metrics, functionals etc.)
torchtext.nn: NLP related modules
torchtext.vocab: Vocab and Vectors related classes and factory functions
examples: Example NLP workflows with PyTorch and torchtext library.
Note: The legacy code discussed in torchtext v0.7.0 release note has been retired to torchtext.legacy folder. Those legacy code will not be maintained by the development team, and we plan to fully remove them in the future release. See torchtext.legacy folder for more details.
Installation
We recommend Anaconda as a Python package management system. Please refer to pytorch.org for the details of PyTorch installation. The following are the corresponding torchtext versions and supported Python versions.
PyTorch version |
torchtext version |
Supported Python version |
---|---|---|
nightly build |
main |
>=3.6, <=3.9 |
1.9 |
0.10 |
>=3.6, <=3.9 |
1.8 |
0.9 |
>=3.6, <=3.9 |
1.7.1 |
0.8.1 |
>=3.6, <=3.9 |
1.7 |
0.8 |
>=3.6, <=3.8 |
1.6 |
0.7 |
>=3.6, <=3.8 |
1.5 |
0.6 |
>=3.5, <=3.8 |
1.4 |
0.5 |
2.7, >=3.5, <=3.8 |
0.4 and below |
0.2.3 |
2.7, >=3.5, <=3.8 |
Using conda:
conda install -c pytorch torchtext
Using pip:
pip install torchtext
Optional requirements
If you want to use English tokenizer from SpaCy, you need to install SpaCy and download its English model:
pip install spacy python -m spacy download en_core_web_sm
Alternatively, you might want to use the Moses tokenizer port in SacreMoses (split from NLTK). You have to install SacreMoses:
pip install sacremoses
For torchtext 0.5 and below, sentencepiece:
conda install -c powerai sentencepiece
Building from source
To build torchtext from source, you need git, CMake and C++11 compiler such as g++.:
git clone https://github.com/pytorch/text torchtext cd torchtext git submodule update --init --recursive # Linux python setup.py clean install # OSX MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py clean install # or ``python setup.py develop`` if you are making modifications.
Note
When building from source, make sure that you have the same C++ compiler as the one used to build PyTorch. A simple way is to build PyTorch from source and use the same environment to build torchtext. If you are using the nightly build of PyTorch, checkout the environment it was built with conda (here) and pip (here).
Documentation
Find the documentation here.
Datasets
The datasets module currently contains:
Language modeling: WikiText2, WikiText103, PennTreebank, EnWik9
Machine translation: IWSLT2016, IWSLT2017, Multi30k
Sequence tagging (e.g. POS/NER): UDPOS, CoNLL2000Chunking
Question answering: SQuAD1, SQuAD2
Text classification: AG_NEWS, SogouNews, DBpedia, YelpReviewPolarity, YelpReviewFull, YahooAnswers, AmazonReviewPolarity, AmazonReviewFull, IMDB
For example, to access the raw text from the AG_NEWS dataset:
>>> from torchtext.datasets import AG_NEWS >>> train_iter = AG_NEWS(split='train') >>> next(train_iter) >>> # Or iterate with for loop >>> for (label, line) in train_iter: >>> print(label, line) >>> # Or send to DataLoader >>> from torch.utils.data import DataLoader >>> train_iter = AG_NEWS(split='train') >>> dataloader = DataLoader(train_iter, batch_size=8, shuffle=False)
Tutorials
To get started with torchtext, users may refer to the following tutorials available on PyTorch website.
[Prototype] Experimental Code
We have re-written several building blocks under torchtext.experimental:
Transforms: some basic data processing building blocks
Vectors: the vectors to convert tokens into tensors.
These prototype building blocks in the experimental folder are available in the nightly release only. The nightly packages are accessible via Pip and Conda for Windows, Mac, and Linux. For example, Linux users can install the nightly wheels with the following command:
pip install --pre --upgrade torch torchtext -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
For more detailed instructions, please refer to Install PyTorch. It should be noted that the new building blocks are still under development, and the APIs have not been solidified.
[BC Breaking] Legacy
In the v0.9.0 release, we moved the following legacy code to torchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed in Issue #664:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
We have a migration tutorial to help users switch to the torchtext datasets in v0.9.0 release. For the users who still want the legacy components, they can add legacy to the import path.
In the v0.10.0 release, we retire the Vocab class to torchtext.legacy. Users can still access the legacy Vocab via torchtext.legacy.vocab. This class has been replaced by a Vocab module that is backed by efficient C++ implementation and provides common functional APIs for NLP workflows.
Disclaimer on Datasets
This is a utility library that downloads and prepares public datasets. We do not host or distribute these datasets, vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to determine whether you have permission to use the dataset under the dataset’s license.
If you’re a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML community!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for torchtext-0.11.2-cp310-cp310-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1f7c0b5ede8b8dc6d3dab05e5d06748d84163e6bdd723dd29ff2ead2df3e925 |
|
MD5 | a4b5dcb17245b81728195b7eb6e14985 |
|
BLAKE2b-256 | 52bb02bc624552b5d504103cad71ce0bd93b0cdec71360fa5463707554ccf968 |
Hashes for torchtext-0.11.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0754ed06047b8dfd18367718b137f65a9a299dff04f1cb2909eb836ac20de880 |
|
MD5 | d7de48a3327a6e59197eeaf1a7c24240 |
|
BLAKE2b-256 | 1376e09e38a9d1368497ccf49df6e0a3cd45b52abd7d8a3ab5219fce1cac23d1 |
Hashes for torchtext-0.11.2-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a142b3b09d4d4b3f8e2c052dc7fd804f7e29c7357e3d66c024378df45792bd1a |
|
MD5 | 4227c1e0256ad8211aa1698a82af8b7a |
|
BLAKE2b-256 | 6d7c7a5e3d27a1f5577d849ffe560b9b14027cb9d274c739efa71d08f18f4736 |
Hashes for torchtext-0.11.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2934c384735f86ec96bf62e8f5a1d3d75b3863262a41a4deeaf6a5f3a5511401 |
|
MD5 | 664f69c2df2590b00b2193f0649def38 |
|
BLAKE2b-256 | 10f19240650c5370b5c3070c357b66985b1ecedd78347ea850aae464509abdf5 |
Hashes for torchtext-0.11.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba09461742cace23d8de868fbb0959338c953a45eecc3e1fdde1fe69b82aa939 |
|
MD5 | d87368a85a831f0cd63d5bb49a22105c |
|
BLAKE2b-256 | 33b4188e173323a7c1b5415010482813a61ec7a1f954c13b3ab69151971a40cc |
Hashes for torchtext-0.11.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8d0aba473bcee31dccf00a9008a2d47584fa891b4afac963676172050820ca |
|
MD5 | 72c2048f0926bde3a413e0a6c45134d7 |
|
BLAKE2b-256 | 111477679a9e7d0f475020efa4cdef7524719165b7f1247b73ea8222d5cb5cff |
Hashes for torchtext-0.11.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c72386cea08a42b4547059a29c09a1373f8f4deb15ae196a70681a47385d673d |
|
MD5 | 2b51f90a21367d26818cda419ffb5250 |
|
BLAKE2b-256 | 83be2f82880232e8695a7214bfe3c9006140b9be4e51221243f36539c7fda8ea |
Hashes for torchtext-0.11.2-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 484e69eeeaace24d310ccfeb9fab00b54fa9a28746c600ee109ce70258c5ea0a |
|
MD5 | 533a29922c817ba7b47d5c2339ed86a3 |
|
BLAKE2b-256 | 6b33bac3b9dd933b26603d9b7613c664464b54411ad2f8d5d3acaad4eec2f64b |
Hashes for torchtext-0.11.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aa7333ca3e48f35785210921c4ba7a1dba8943aaedd378afdadc668210ac4ce |
|
MD5 | 993bec9b712977297c7e6cf480941b51 |
|
BLAKE2b-256 | 75ffacfb0b81fbb3a477cbab994e2f971992a96a82da8545332ba1c089bdb1e9 |
Hashes for torchtext-0.11.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28a0cfa2117bb42536555cdf21c204004cd7cc68b7780cfd5673049320ecbef6 |
|
MD5 | 7ebf12993f1d72a03b3e6279670feb1f |
|
BLAKE2b-256 | a61d8d09756fc7f12826460b5700c5530d0aace2f28cf9a55111e01a44786931 |
Hashes for torchtext-0.11.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a786fbca0e00e7dbaa7765cb14210dc76236ca17b11cdbf3d19d4ed8ecebba0 |
|
MD5 | a43e1a94d8bd513176738054e8e06941 |
|
BLAKE2b-256 | a672b84b6da037fada3cc6e21085cc10c4d4b5e7d2068099882d5540d24c72ae |
Hashes for torchtext-0.11.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94ff8dbdb99585d52c527a42bc726e24af56beffee34a5be0057baf94fe6483e |
|
MD5 | c151b8490688dd15c0ed55743d09979a |
|
BLAKE2b-256 | c62d2788b2a64c5479fa51f60a9d61587a8d94eb594c3ed23d53b53bbccfdb85 |
Hashes for torchtext-0.11.2-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3447fbe846f145d9129b5f23062ae0747aa9660034f6de32fe1ebba3c6b54d03 |
|
MD5 | b3b965a98b8dc6984b3036a038c423e5 |
|
BLAKE2b-256 | 5320f795c3112665aa22c3d69fd91a468c569b367ce42cb45eac661b1927562a |
Hashes for torchtext-0.11.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9cd7f344bffceff0e98eb53afd2c66170e30af3f235cc0a58d9871df678691 |
|
MD5 | b8f43ba75045f2c9a7fb900b45dcef0b |
|
BLAKE2b-256 | e04ebfd51736e3c2db4dad54b577e30ecf67f582e5829b091857670c4a3f8cc3 |
Hashes for torchtext-0.11.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3734ecf6456a4a75d99706b23866b87a64b27afb47154cd740c4bc6d54a0591b |
|
MD5 | f144ea6945a92f29f910bf7dd63a62ce |
|
BLAKE2b-256 | 89ed24fc12cfd6e3d4490395ebbe1d601db539dc7570a7f22099caf45229ff72 |
Hashes for torchtext-0.11.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41fdfc0d8b9d571ec912113b7fa0ec860e225cd4c41957ca954391782e565ecf |
|
MD5 | f8169e5b13b7884149b483b91f257bcf |
|
BLAKE2b-256 | 4566c4811a99f380433661c21cf6d22685b19f5ded17f4737c2696633f30839f |
Hashes for torchtext-0.11.2-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c60c1d73a99b2b7bbaea64248c34e252a22723697cba24dc5ebf08de6df10bc |
|
MD5 | c7ff02009d0294dca94d6e873a8f87ed |
|
BLAKE2b-256 | ddc8f22fa226176d5bc36bb467f075555a4f4db1bc2a505bb8198d5ed6bae6d4 |
Hashes for torchtext-0.11.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff71180bd697d187b5a80de4c7ea98c3c404bdc79020c5ce82120e4260ba6506 |
|
MD5 | 18b9607b002066b3c8f83d443942bb36 |
|
BLAKE2b-256 | 2d8252f69aaea78fd60fcd7259a0abe6c41a26a83dc8bc840bf4ebfc82e4bf8b |
Hashes for torchtext-0.11.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac6ac9032af3de8ae0c760ede91e5114df0d1f8bf1d6607a01c8957855bf451b |
|
MD5 | e6ed0002fbb62ec4fee76a523999284f |
|
BLAKE2b-256 | c8de8948c04b01a9e21c5788c4ebda6c276211e1f82291700d478e07d51992cd |