Skip to content

Commit d3708fc

Browse files
authored
v0.1 release
* Update README * Update version to `v0.1` in version.py, setup.py, CHANGELOG.md
2 parents b07501a + 719eaa6 commit d3708fc

File tree

5 files changed

+90
-77
lines changed

5 files changed

+90
-77
lines changed

CHANGELOG.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11

2-
## [Unreleased]
2+
## [v0.1.0](https://github.com/asyml/texar-pytorch/releases/tag/v0.1.0) (2019-10-15)
33

4-
### New features
5-
6-
### Feature improvements
7-
8-
### Fixes
4+
The first formal release of Texar-PyTorch
95

106
## [v0.0.1](https://github.com/asyml/texar-pytorch/releases/tag/v0.0.1) (2019-08-02)
117

README.md

+85-68
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,105 @@
99
[![Documentation Status](https://readthedocs.org/projects/texar-pytorch/badge/?version=latest)](https://texar-pytorch.readthedocs.io/en/latest/?badge=latest)
1010
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/asyml/texar-pytorch/blob/master/LICENSE)
1111

12-
*(Note: This is the alpha release of Texar-PyTorch.)*
13-
14-
**Texar-PyTorch** is an open-source toolkit based on PyTorch, aiming to support a broad set of machine learning, especially text generation tasks, such as machine translation, dialog, summarization, content manipulation, language modeling, and so on. Texar is designed for both researchers and practitioners for fast prototyping and experimentation.
1512

16-
*If you work with TensorFlow, be sure to check out **[Texar (TensorFlow)](https://github.com/asyml/texar)** which has (mostly) the **same functionalities and interfaces**.*
13+
**Texar-PyTorch** is a toolkit aiming to support a broad set of machine learning, especially natural language processing and text generation tasks. Texar provides a library of easy-to-use ML modules and functionalities for composing whatever models and algorithms. The tool is designed for both researchers and practitioners for fast prototyping and experimentation.
1714

18-
With the design goals of **modularity, versatility, and extensibility** in mind, Texar extracts the common patterns underlying the diverse tasks and methodologies, creates a library of highly reusable modules and functionalities, and facilitates **arbitrary model architectures and algorithmic paradigms**, e.g.,
19-
* encoder(s) to decoder(s), sequential- and self-attentions, memory, hierarchical models, classifiers, ...
20-
* maximum likelihood learning, reinforcement learning, adversarial learning, probabilistic modeling, ...
21-
* **pre-trained models** such as **BERT**, **GPT2**, **XLNet**, ...
15+
Texar-PyTorch integrates many of the best features of TensorFlow into PyTorch, delivering highly usable and customizable modules superior to PyTorch native ones.
2216

23-
With Texar, cutting-edge complex models can be easily constructed, freely enriched with best modeling/training practices, readily fitted into standard training/evaluation pipelines, and quickly experimented and evolved by, e.g., plugging in and swapping out different modules.
17+
### Key Features
18+
* **Two Versions, (Mostly) Same Interfaces**. Texar-PyTorch (this repo) and **[Texar-TF](https://github.com/asyml/texar)** have mostly the same interfaces. Both further combine the best design of TF and PyTorch:
19+
- Interfaces and variable sharing in *PyTorch convention*
20+
- Excellent factorization and rich functionalities in *TF convention*.
21+
* **Versatile** to support broad needs:
22+
- data processing, model architectures, loss functions, training and inference algorithms, evaluation, ...
23+
- encoder(s) to decoder(s), sequential- and self-attentions, memory, hierarchical models, classifiers, ...
24+
- maximum likelihood learning, reinforcement learning, adversarial learning, probabilistic modeling, ...
25+
* **Fully Customizable** at multiple abstraction level -- both novice-friendly and expert-friendly.
26+
- Free to plug in whatever external modules, since Texar is fully compatible with the native PyTorch APIs.
27+
* **Modularized** for maximal re-use and clean APIs, based on principled decomposition of *Learning-Inference-Model Architecture*.
28+
* **Rich Pre-trained Models, Rich Usage with Uniform Interfaces**. BERT, GPT2, XLNet, etc, for encoding, classification, generation, and composing complex models with other Texar components!
29+
* Clean, detailed [documentation](https://texar-pytorch.readthedocs.io) and rich [examples](./examples).
2430

2531
<div align="center">
2632
<img src="./docs/_static/img/texar_stack.png"><br><br>
2733
</div>
2834

29-
30-
### Key Features
31-
* **Versatility**. Texar contains a wide range of modules and functionalities for composing arbitrary model architectures and implementing various learning algorithms, as well as for data processing, evaluation, prediction, etc.
32-
* **Modularity**. Texar decomposes diverse, complex machine learning models and algorithms into a set of highly-reusable modules. In particular, model **architecture, losses, and learning processes** are fully decomposed.
33-
Users can construct their own models at a high conceptual level, just like assembling building blocks. It is convenient to plug in or swap out modules, and configure rich options for each module. For example, switching between maximum-likelihood learning and reinforcement learning involves only changing several lines of code.
34-
* **Extensibility**. It is straightforward to integrate any user-customized, external modules. Also, Texar is fully compatible with the native PyTorch interfaces and can take advantage of the rich PyTorch features, and resources from the vibrant open-source community.
35-
* Interfaces with different functionality levels. Users can customize a model through 1) simple **Python/YAML configuration files** of provided model templates/examples; 2) programming with **Python Library APIs** for maximal customizability.
36-
* Easy-to-use APIs; rich configuration options for each module, all with default values.
37-
* Well-structured high-quality code of uniform design patterns and consistent styles.
38-
* Clean, detailed [documentation](https://texar-pytorch.readthedocs.io) and rich [examples](./examples).
35+
<div align="center">
36+
<img src="./docs/_static/img/texar_modules_big.png"><br><br>
37+
</div>
3938

4039

4140
### Library API Example
42-
A code portion that builds a (self-)attentional sequence encoder-decoder model:
41+
A code example that builds and trains a **Conditional GPT2** model (e.g., for machine translation and text summarization):
4342
```python
4443
import texar.torch as tx
45-
46-
class Seq2Seq(tx.ModuleBase):
47-
def __init__(self, data):
48-
self.embedder = tx.modules.WordEmbedder(
49-
data.target_vocab.size, hparams=hparams_emb)
50-
self.encoder = tx.modules.TransformerEncoder(
51-
hparams=hparams_encoder) # config through `hparams`
52-
self.decoder = tx.modules.AttentionRNNDecoder(
53-
token_embedder=self.embedder,
54-
input_size=self.embedder.dim,
55-
encoder_output_size=self.encoder.output_size,
56-
vocab_size=data.target_vocab.size,
57-
hparams=hparams_decoder)
58-
59-
def forward(self, batch):
60-
outputs_enc = self.encoder(
61-
inputs=self.embedder(batch['source_text_ids']),
62-
sequence_length=batch['source_length'])
63-
64-
outputs, _, _ = self.decoder(
65-
memory=outputs_enc,
66-
memory_sequence_length=batch['source_length'],
67-
helper=self.decoder.get_helper(decoding_strategy='train_greedy'),
68-
inputs=batch['target_text_ids'],
69-
sequence_length=batch['target_length']-1)
70-
71-
# Loss for maximum likelihood learning
72-
loss = tx.losses.sequence_sparse_softmax_cross_entropy(
73-
labels=batch['target_text_ids'][:, 1:],
74-
logits=outputs.logits,
75-
sequence_length=batch['target_length']-1) # Automatic masking
76-
77-
return loss
78-
79-
80-
data = tx.data.PairedTextData(hparams=hparams_data)
81-
iterator = tx.data.DataIterator(data)
82-
83-
model = Seq2seq(data)
84-
for batch in iterator:
85-
loss = model(batch)
86-
# ...
44+
from texar.torch.run import *
45+
46+
# (1) Modeling
47+
class ConditionalGPT2Model(nn.Module):
48+
"""An encoder-decoder model with GPT-2 as the decoder."""
49+
def __init__(self, vocab_size):
50+
super().__init__()
51+
# Use hyperparameter dict for model configuration
52+
self.embedder = tx.modules.WordEmbedder(vocab_size, hparams=emb_hparams)
53+
self.encoder = tx.modules.TransformerEncoder(hparams=enc_hparams)
54+
self.decoder = tx.modules.GPT2Decoder("gpt2-small") # With pre-trained weights
55+
56+
def _get_decoder_output(self, batch, train=True):
57+
"""Perform model inference, i.e., decoding."""
58+
enc_states = self.encoder(inputs=self.embedder(batch['source_text_ids']),
59+
sequence_length=batch['source_length'])
60+
if train: # Teacher-forcing decoding at training time
61+
return self.decoder(
62+
inputs=batch['target_text_ids'], sequence_length=batch['target_length'] - 1,
63+
memory=enc_states, memory_sequence_length=batch['source_length'])
64+
else: # Beam search decoding at prediction time
65+
start_tokens = torch.full_like(batch['source_text_ids'][:, 0], BOS)
66+
return self.decoder(
67+
beam_width=5, start_tokens=start_tokens,
68+
memory=enc_states, memory_sequence_length=batch['source_length'])
69+
70+
def forward(self, batch):
71+
"""Compute training loss."""
72+
outputs = self._get_decoder_output(batch)
73+
loss = tx.losses.sequence_sparse_softmax_cross_entropy( # Sequence loss
74+
labels=batch['target_text_ids'][:, 1:], logits=outputs.logits,
75+
sequence_length=batch['target_length'] - 1) # Automatic masking
76+
return {"loss": loss}
77+
78+
def predict(self, batch):
79+
"""Compute model predictions."""
80+
sequence, _ = self._get_decoder_output(batch, train=False)
81+
return {"gen_text_ids": sequence}
82+
83+
84+
# (2) Data
85+
# Create dataset splits using built-in data loaders
86+
datasets = {split: tx.data.PairedTextData(hparams=data_hparams[split])
87+
for split in ["train", "valid", "test"]}
88+
89+
model = ConditionalGPT2Model(datasets["train"].target_vocab.size)
90+
91+
# (3) Training
92+
# Manage the train-eval loop with the Executor API
93+
executor = Executor(
94+
model=model, datasets=datasets,
95+
optimizer={"type": torch.optim.Adam, "kwargs": {"lr": 5e-4}},
96+
stop_training_on=cond.epoch(20),
97+
log_every=cond.iteration(100),
98+
validate_every=cond.epoch(1),
99+
train_metric=("loss", metric.RunningAverage(10, pred_name="loss")),
100+
valid_metric=metric.BLEU(pred_name="gen_text_ids", label_name="target_text_ids"),
101+
save_every=cond.validation(better=True),
102+
checkpoint_dir="outputs/saved_models/")
103+
executor.train()
104+
executor.test(datasets["test"])
87105
```
88106
Many more examples are available [here](./examples).
89107

90108

91109
### Installation
92-
Texar-PyTorch requires PyTorch 1.0 or higher. Please follow the [official instructions](https://pytorch.org/get-started/locally/#start-locally) to install the appropriate version.
110+
Texar-PyTorch requires `PyTorch>=1.0`. Please follow the [official instructions](https://pytorch.org/get-started/locally/#start-locally) to install the appropriate version.
93111

94112
After PyTorch is installed, please run the following commands to install Texar-PyTorch:
95113
```
@@ -114,16 +132,15 @@ If you use Texar, please cite the [tech report](https://arxiv.org/abs/1809.00794
114132
```
115133
Texar: A Modularized, Versatile, and Extensible Toolkit for Text Generation
116134
Zhiting Hu, Haoran Shi, Bowen Tan, Wentao Wang, Zichao Yang, Tiancheng Zhao, Junxian He, Lianhui Qin, Di Wang, Xuezhe Ma, Zhengzhong Liu, Xiaodan Liang, Wanrong Zhu, Devendra Sachan and Eric Xing
117-
2018
135+
ACL 2019
118136
119-
@article{hu2018texar,
137+
@inproceedings{hu2019texar,
120138
title={Texar: A Modularized, Versatile, and Extensible Toolkit for Text Generation},
121139
author={Hu, Zhiting and Shi, Haoran and Tan, Bowen and Wang, Wentao and Yang, Zichao and Zhao, Tiancheng and He, Junxian and Qin, Lianhui and Wang, Di and others},
122-
journal={arXiv preprint arXiv:1809.00794},
123-
year={2018}
140+
booktitle={ACL 2019, System Demonstrations},
141+
year={2019}
124142
}
125143
```
126144

127-
128145
### License
129146
[Apache License 2.0](./LICENSE)
499 KB
Loading

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setuptools.setup(
1919
name="texar-pytorch",
20-
version="0.0.1",
20+
version="0.1.0",
2121
url="https://github.com/asyml/texar-pytorch",
2222

2323
description="Toolkit for Machine Learning and Text Generation",

texar/torch/version.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
_MAJOR = "0"
16-
_MINOR = "0"
17-
_REVISION = "1-unreleased"
16+
_MINOR = "1"
17+
_REVISION = "0"
1818

1919
VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR)
2020
VERSION = "{0}.{1}.{2}".format(_MAJOR, _MINOR, _REVISION)

0 commit comments

Comments
 (0)