Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Data loaders and abstractions for text and NLP

License

NotificationsYou must be signed in to change notification settings

classicvalues/text-1

 
 
https://circleci.com/gh/pytorch/text.svg?style=svghttps://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:

Note: The legacy code discussed intorchtext v0.7.0 release note has been retired totorchtext.legacy folder. Those legacy code will not be maintained by the development team, and we plan to fully remove them in the future release. Seetorchtext.legacy folder for more details.

Installation

We recommend Anaconda as a Python package management system. Please refer topytorch.org for the details of PyTorch installation. The following are the correspondingtorchtext versions and supported Python versions.

Version Compatibility
PyTorch versiontorchtext versionSupported Python version
nightly buildmain>=3.7, <=3.9
1.10.00.11.0>=3.6, <=3.9
1.9.10.10.1>=3.6, <=3.9
1.90.10>=3.6, <=3.9
1.8.20.9.2>=3.6, <=3.9
1.8.10.9.1>=3.6, <=3.9
1.80.9>=3.6, <=3.9
1.7.10.8.1>=3.6, <=3.9
1.70.8>=3.6, <=3.8
1.60.7>=3.6, <=3.8
1.50.6>=3.5, <=3.8
1.40.52.7, >=3.5, <=3.8
0.4 and below0.2.32.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 fromSpaCy, you need to install SpaCy and download its English model:

pip install spacypython -m spacy download en_core_web_sm

Alternatively, you might want to use theMoses tokenizer port inSacreMoses (split fromNLTK). 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 needgit,CMake and C++11 compiler such asg++.:

git clone https://github.com/pytorch/text torchtextcd torchtextgit submodule update --init --recursive# Linuxpython setup.py clean install# OSXMACOSX_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 withconda (here) andpip (here).

Documentation

Find the documentationhere.

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:

>>>fromtorchtext.datasetsimportAG_NEWS>>>train_iter=AG_NEWS(split='train')>>># Iterate with for loop>>>for (label,line)intrain_iter:>>>print(label,line)>>># Or send to DataLoader>>>fromtorch.utils.dataimportDataLoader>>>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.

[BC Breaking] Legacy

In the v0.9.0 release, we moved the following legacy code totorchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed inIssue #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 amigration tutorial to help users switch to the torchtext datasets inv0.9.0 release. For the users who still want the legacy components, they can addlegacy to the import path.

In the v0.10.0 release, we retire the Vocab class totorchtext.legacy. Users can still access the legacy Vocab viatorchtext.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!

About

Data loaders and abstractions for text and NLP

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python83.2%
  • C++12.8%
  • Shell2.7%
  • Other1.3%

[8]ページ先頭

©2009-2025 Movatter.jp