Skip to content
A natural language modeling framework based on PyTorch
Branch: master
Clone or download
borguz and facebook-github-bot Sharded data sources (#456)
Summary:
Pull Request resolved: #456

Moves sharding from Data to DataSouce, so that we can have DataSources that can shard in different ways.

- Move shard() utility to data/utils
- Introduce ShardedDataSource (base class), RowShardedDataSource, and BlockShardedTSVDataSource

Default behavior is to shard the configured DataSource in a RowShardedDataSource, which results in previous behavior.  RowShardedDataSource is a light wrapper which returns shard(data_source.train)

If the configured DataSource is an instance of ShardedDataSource, then it has sharding capability and we don't wrap it.

BlockShardedTSVDataSource is a TSV data source, which divides the file into blocks and returns csv readers over each block for each shard. This is useful for when row order is important in the file, e.g. when rows are sentences of a long document.  Used for MaskedLM training. Blocks are the same byte size, but not guaranteed to have the same number of rows.  Therefore the Data object needs to set epoch_size for distributed training to work correctly.

Introduce epoch_size for base Data object as an option.  If set, epochs are set to be a fixed number of batches.  Underlying dataset is cycled over infinitely.  If not set, behavior is as before.

Remove epoch size from batch samplers, since it's no longer needed.

Consolidate DisjointMultitaskData and CrossLingualLMData to share more code.

Reviewed By: kartikayk

Differential Revision: D14840136

fbshipit-source-id: 1eaba18c730a39a069ee701827195954e77b22fc
Latest commit 8fbf6b7 May 1, 2019

README.md

Overview

CircleCI

PyText is a deep-learning based NLP modeling framework built on PyTorch. PyText addresses the often-conflicting requirements of enabling rapid experimentation and of serving models at scale. It achieves this by providing simple and extensible interfaces and abstractions for model components, and by using PyTorch’s capabilities of exporting models for inference via the optimized Caffe2 execution engine. We are using PyText in Facebook to iterate quickly on new modeling ideas and then seamlessly ship them at scale.

Core PyText features:

Installing PyText

PyText requires Python 3.6.1 or above.

To get started on a Cloud VM, check out our guide.

We recommend using a virtualenv:

  $ python3 -m venv pytext_venv
  $ source pytext_venv/bin/activate
  (pytext_venv) $ pip install pytext-nlp

Detailed instructions and more installation options can be found in our Documentation. If you encounter issues with missing dependencies during installation, please refer to OS Dependencies.

Train your first text classifier

For this first example, we'll train a CNN-based text-classifier that classifies text utterances, using the examples in tests/data/train_data_tiny.tsv. The data and configs files can be obtained either by cloning the repository or by downloading the files manually from GitHub.

  (venv) $ pytext train < demo/configs/docnn.json

By default, the model is created in /tmp/model.pt

Now you can export your model as a caffe2 net:

  (venv) $ pytext export < demo/configs/docnn.json

You can use the exported caffe2 model to predict the class of raw utterances like this:

  (venv) $ pytext --config-file demo/configs/docnn.json predict <<< '{"raw_text": "create an alarm for 1:30 pm"}'

More examples and tutorials can be found in Full Documentation.

Join the community

License

PyText is BSD-licensed, as found in the LICENSE file.

You can’t perform that action at this time.