# Texar: a TensorFlow 1.x toolkit for text generation research

> Texar bundles data pipelines, encoder-decoder modules, pre-trained BERT/GPT-2/XLNet wrappers and maximum-likelihood, adversarial and reinforcement-learning losses behind one set of interfaces. It is pinned to TensorFlow below 2.0, and that pin is the whole adoption decision.

**asyml/texar** — Toolkit for Machine Learning, Natural Language Processing, and Text Generation, in TensorFlow.  This is part of the CASL project: http://casl-project.ai/

- Repository: https://github.com/asyml/texar
- Website: https://asyml.io
- Stars: 2,390 · Forks: 367
- Language: Python
- License: Apache-2.0
- Published: 2026-09-10 · Updated: 2026-09-10 · Language: en
- Canonical page: https://hysenlabs.com/projects/asyml-texar

## The problem Texar solves: glue code around text generation models

Building a sequence-to-sequence model in TensorFlow 1.x means writing a lot of code that is not the model. You write a vocabulary loader, a bucket-by-length iterator, a padding mask, a teacher-forcing helper, a beam search loop, and a BLEU script. None of that is what you are researching, and each piece has its own bugs. Texar's pitch is that these pieces already exist as a library of modules with a consistent interface, so you compose them instead of writing them.

The target user is a researcher or a practitioner doing fast prototyping, which the README states directly. The repository layout backs that up: examples/ contains directories for seq2seq_attn, seq2seq_rl, seqgan, hierarchical_dialog, text_style_transfer, vae_text, bert, gpt-2 and language_model_ptb. That is a research-task list, not an application list. There is no serving layer, no model registry, no feature store, and no HTTP API documented in the README. If you need to deploy a text model rather than study one, Texar is addressing a different job.

## How the Learning-Inference-Model decomposition shows up in code

The README describes the architecture as a principled decomposition of Learning, Inference and Model. In practice that maps onto three namespaces. tx.data handles the first: PairedTextData takes a hparams dict, DataIterator wraps it, and get_next() returns a batch dict with keys like source_text_ids, source_length, target_text_ids and target_length. The length keys are what let downstream losses apply sequence masks automatically.

tx.modules is the model layer. WordEmbedder, TransformerEncoder and TransformerDecoder are called as functions rather than through a session-run graph API, and the README notes that its interfaces follow PyTorch convention while keeping TensorFlow's factorization. Variable sharing is explicit: the decoder example passes output_layer=tf.transpose(embedder.embedding) to tie the input embedding to the output projection.

tx.losses and tx.agents are the learning layer. The same decoder object is reused across three different training regimes in the README: sequence_sparse_softmax_cross_entropy for maximum likelihood, binary_adversarial_losses with a BertClassifier as discriminator for adversarial training, and SeqPGAgent for policy-gradient reinforcement learning. That reuse is the actual design claim, and it is the part worth evaluating. Whether it holds for your model depends on whether your decoder fits the expected call signature.

## Installing Texar and running a first encoder-decoder

The README is explicit that Texar>0.2.3 requires Python 3.6 or 3.7, and that older Python versions must use Texar<=0.2.3. Install TensorFlow and TensorFlow Probability first, following the official instructions the README links to. The version windows are narrow: tensorflow >= 1.10.0 and < 2.0.0, tensorflow_probability >= 0.3.0 and < 0.8.0.

```bash
pip install texar
```

setup.py also pins numpy<1.17.0, so if another package in your environment wants a newer numpy, pip will either downgrade it or fail to resolve. Installing from source is the documented path for unreleased features:

```bash
git clone https://github.com/asyml/texar.git
cd texar
pip install .
```

A first real use is the encoder-decoder from the README's Library API Example. The data side builds a paired text pipeline and pulls a mini-batch:

```python
import texar.tf as tx

data = tx.data.PairedTextData(hparams=hparams_data)
iterator = tx.data.DataIterator(data)
batch = iterator.get_next()
```

What you should see after this block is a batch dict with the source and target id tensors and their length tensors. The model side then embeds, encodes and decodes:

```python
embedder = tx.modules.WordEmbedder(data.target_vocab.size, hparams=hparams_emb)
encoder = tx.modules.TransformerEncoder(hparams=hparams_enc)
outputs_enc = encoder(inputs=embedder(batch['source_text_ids']),
                      sequence_length=batch['source_length'])

decoder = tx.modules.TransformerDecoder(
    output_layer=tf.transpose(embedder.embedding),
    hparams=hparams_decoder)
outputs, _, _ = decoder(memory=outputs_enc,
                        memory_sequence_length=batch['source_length'],
                        inputs=embedder(batch['target_text_ids']),
                        sequence_length=batch['target_length']-1,
                        decoding_strategy='greedy_train')
```

The decoding_strategy value greedy_train selects teacher forcing. At inference you call tx.modules.beam_search_decode with the same decoder object, passing start_tokens and end_token from the vocabulary. Note that the README's example passes memory=output_enc while the encoder output variable is named outputs_enc; that inconsistency is in the source snippet, so expect to fix the name yourself.

## Where Texar stops being the right tool

The dependency ceiling is the headline limitation. tensorflow >= 1.10.0 and < 2.0.0 means Texar cannot run on TensorFlow 2.x at all. TensorFlow 1.15 is the last 1.x release line, and it is not receiving new features. If your team has standardized on tf.keras or tf.function, adopting Texar means maintaining a separate Python environment with an older TensorFlow, older tensorflow-probability and numpy below 1.17.0. That is a real operational cost, not a footnote.

The release cadence reinforces the point. The most recent release listed is v0.2.4 from 2019-11-19, preceded by v0.2.3 on 2019-09-26 and v0.2.2 on 2019-08-05. The repository's last push was on 2026-07-21, so the codebase is not frozen, but the released artifact has not moved in years. Anyone adopting Texar from PyPI is adopting the 2019 API surface.

There is also a scope limitation. The README does not document checkpoint conversion, model export, or a serving path. The pre-trained model story is about loading BERT, GPT-2 or XLNet weights for encoding, classification and generation inside a Texar graph, not about shipping them. And because Texar is a composition layer over native TensorFlow APIs, debugging a failure often means reading TensorFlow 1.x graph errors rather than Texar errors. The abstraction does not hide TensorFlow, it organizes it.

## Texar-PyTorch and the plain TensorFlow alternative

The most direct alternative is Texar-PyTorch, which the README describes as having mostly the same interfaces and the same functionalities. The difference is not just the backend. Texar-PyTorch is a separate repository with its own release cycle, so its dependency situation is different from the TensorFlow version's TensorFlow 1.x pin. If your constraint is the framework rather than the API, that repository is where the same design lives.

The other alternative is not a library at all: writing the encoder-decoder directly against TensorFlow 1.x, or against a current framework. The trade-off is concrete. Texar gives you PairedTextData, DataIterator, beam_search_decode, sequence_sparse_softmax_cross_entropy with automatic sequence masks, and a BLEU script bundled at bin/utils/multi-bleu.perl. Writing those yourself is perhaps a few hundred lines, and you control every detail, including the ability to move to a maintained framework later. Texar's value is highest when you are prototyping several generation approaches in sequence, since the shared decoder object across maximum-likelihood, adversarial and RL training is the part that is tedious to rebuild each time.

## Licence and the cost of staying on 0.2.4

Texar is released under Apache License 2.0, and setup.py declares license='Apache License Version 2.0'. Apache-2.0 is a permissive licence with an explicit patent grant, which matters if you are embedding the code in a commercial research pipeline. The repository also bundles bin/utils/multi-bleu.perl as package data, so that Perl script ships with the pip package; check its provenance separately if licence hygiene is a concern for your organization. This is a description of what the repository states, not legal advice.

The upgrade cost is the harder question. Because the last release is v0.2.4 and the dependency window closes below TensorFlow 2.0, there is no upgrade path within Texar itself. Moving forward means moving to Texar-PyTorch, or rewriting against a current framework. The CHANGELOG.md file exists at the repository root, so the release history is available, but the README does not document a migration guide from 0.2.x to anything else. Budget for a rewrite, not an upgrade.

## Conclusion

Texar suits researchers and graduate students who already have a TensorFlow 1.x environment and want to prototype seq2seq, dialog or RL-based generation without rebuilding data pipelines and decoding helpers. It is the wrong tool for anyone starting a new project on TensorFlow 2.x, PyTorch, or a modern transformer stack, because the dependency ceiling is tensorflow >= 1.10.0, < 2.0.0 and the newest release is v0.2.4 from 2019-11-19. Before committing, verify that tensorflow-probability resolves inside the 0.3.0 to 0.8.0 window, check that numpy<1.17.0 does not conflict with your other packages, and read the examples/ directory for the task closest to yours.

## FAQ

### What is the Texar framework?

Texar is a TensorFlow-based toolkit for machine learning and text generation tasks, including machine translation, dialog, summarization and language modeling. The README describes it as designed for both researchers and practitioners for fast prototyping and experimentation, and it is part of the CASL project.

### Which Python and TensorFlow versions does Texar require?

The README states that Texar>0.2.3 requires Python 3.6 or 3.7, and that older Python versions should use Texar<=0.2.3. It also requires tensorflow >= 1.10.0 and < 2.0.0, plus tensorflow_probability >= 0.3.0 and < 0.8.0.

### How do I install Texar?

Install TensorFlow and TensorFlow Probability first, then run pip install texar. To use unreleased features or develop locally, clone the repository and run pip install . from the texar directory.

### Does Texar support pre-trained models like BERT and GPT-2?

Yes. The README lists BERT, GPT2 and XLNet among the pre-trained models available for encoding, classification and generation, and the repository has examples/bert/ and examples/gpt-2/ directories. The adversarial learning example uses tx.modules.BertClassifier as a discriminator.

### What learning methods does Texar support?

The README lists maximum likelihood learning, reinforcement learning, adversarial learning and probabilistic modeling. The same decoder object can be trained with sequence_sparse_softmax_cross_entropy, binary_adversarial_losses with a discriminator, or a SeqPGAgent for policy gradients.

## Sources

- [asyml/texar on GitHub](https://github.com/asyml/texar)
- [License: Apache-2.0](https://github.com/asyml/texar/blob/master/LICENSE)
- [Project website](https://asyml.io)
- [README](https://github.com/asyml/texar/blob/master/README.md)
- [Releases](https://github.com/asyml/texar/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/asyml-texar
