Skip to main content

Text utilities, models, transforms, and datasets for PyTorch.

Project description

docs/source/_static/img/torchtext_logo.png https://circleci.com/gh/pytorch/text.svg?style=svg https://codecov.io/gh/pytorch/text/branch/main/graph/badge.svg https://img.shields.io/badge/dynamic/json.svg?label=docs&url=https%3A%2F%2Fpypi.org%2Fpypi%2Ftorchtext%2Fjson&query=%24.info.version&colorB=brightgreen&prefix=v

torchtext

This repository consists of:

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.

Version Compatibility

PyTorch version

torchtext version

Supported Python version

nightly build

main

>=3.8, <=3.11

1.14.0

0.15.0

>=3.8, <=3.11

1.13.0

0.14.0

>=3.7, <=3.10

1.12.0

0.13.0

>=3.7, <=3.10

1.11.0

0.12.0

>=3.6, <=3.9

1.10.0

0.11.0

>=3.6, <=3.9

1.9.1

0.10.1

>=3.6, <=3.9

1.9

0.10

>=3.6, <=3.9

1.8.1

0.9.1

>=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
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).

Additionally, datasets in torchtext are implemented using the torchdata library. Please take a look at the installation instructions to download the latest nightlies or install from source.

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: SST2, AG_NEWS, SogouNews, DBpedia, YelpReviewPolarity, YelpReviewFull, YahooAnswers, AmazonReviewPolarity, AmazonReviewFull, IMDB

  • Model pre-training: CC-100

Models

The library currently consist of following pre-trained models:

Tokenizers

The transforms module currently support following scriptable tokenizers:

Tutorials

To get started with torchtext, users may refer to the following tutorial available on PyTorch website.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

torchtext-0.16.2-cp312-cp312-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

torchtext-0.16.2-cp312-cp312-manylinux1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.12

torchtext-0.16.2-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

torchtext-0.16.2-cp312-cp312-macosx_10_13_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.12 macOS 10.13+ x86-64

torchtext-0.16.2-cp311-cp311-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

torchtext-0.16.2-cp311-cp311-manylinux1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.11

torchtext-0.16.2-cp311-cp311-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

torchtext-0.16.2-cp311-cp311-macosx_10_13_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.11 macOS 10.13+ x86-64

torchtext-0.16.2-cp310-cp310-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

torchtext-0.16.2-cp310-cp310-manylinux1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.10

torchtext-0.16.2-cp310-cp310-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

torchtext-0.16.2-cp310-cp310-macosx_10_13_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.13+ x86-64

torchtext-0.16.2-cp39-cp39-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

torchtext-0.16.2-cp39-cp39-manylinux1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.9

torchtext-0.16.2-cp39-cp39-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

torchtext-0.16.2-cp39-cp39-macosx_10_13_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.9 macOS 10.13+ x86-64

torchtext-0.16.2-cp38-cp38-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

torchtext-0.16.2-cp38-cp38-manylinux1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.8

torchtext-0.16.2-cp38-cp38-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

torchtext-0.16.2-cp38-cp38-macosx_10_13_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.8 macOS 10.13+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page