<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Texar on Medium]]></title>
        <description><![CDATA[Stories by Texar on Medium]]></description>
        <link>https://medium.com/@texar?source=rss-3228ffec7a48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CMskksvNtYOZnstFRj07cw.png</url>
            <title>Stories by Texar on Medium</title>
            <link>https://medium.com/@texar?source=rss-3228ffec7a48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 23 Jun 2026 09:39:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@texar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Introducing Texar-PyTorch: An ML Library Integrating the Best of TensorFlow into PyTorch]]></title>
            <link>https://medium.com/@texar/introducing-texar-pytorch-an-ml-library-integrating-the-best-of-tensorflow-into-pytorch-d89c2c2d1d61?source=rss-3228ffec7a48------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89c2c2d1d61</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[natural-language-process]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[text-generation]]></category>
            <dc:creator><![CDATA[Texar]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 16:39:31 GMT</pubDate>
            <atom:updated>2019-10-26T21:54:10.313Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPeLl-1oDjP6zqpdVd5xPw.png" /></figure><p><em>Crossposted on the </em><a href="https://petuum.com/2019/10/16/introducing-texar-pytorch-an-ml-library-integrating-the-best-of-tensorflow-into-pytorch/"><em>Petuum blog</em></a><em>.</em></p><p>We are excited to introduce Texar-PyTorch, an open-source general-purpose machine learning toolkit that supports a broad set of applications with a focus on natural language processing (NLP) and text generation tasks.</p><p>Stemming from its already-popular <a href="https://github.com/asyml/texar">Texar TensorFlow equivalent</a>, Texar-PyTorch <strong>integrates many of the best features from Tensorflow into PyTorch</strong>. The toolkit is <strong>highly customizable,</strong> exposing APIs at multiple abstraction levels to <strong>suit both novice and experienced users</strong>.</p><p>In particular, Texar-PyTorch replicates comprehensive useful TensorFlow (TF) modules to significantly enhance PyTorch existing functionalities, including:</p><ul><li><strong>Data:</strong> Best practice of tf.<a href="https://www.tensorflow.org/guide/data">data</a> for <strong>easy</strong> data processing, batching, and iteration, all <strong>efficient</strong> based on buffered shuffling, caching, and lazy-loading. We also replicate <a href="https://www.tensorflow.org/tutorials/load_data/tfrecord">TFRecord</a> to ingest arbitrary complex data types and large files.</li><li><strong>Modeling:</strong> Abundant functions and excellent modularization of ML models, such as the principled design of sequence models including <a href="https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/contrib/seq2seq">text generation decoders</a>, attention mechanisms, and <a href="https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/nn/rnn_cell">RNNs</a>, etc.</li><li><strong>Training:</strong> We replicate high-level APIs of <a href="https://www.tensorflow.org/guide/estimator">TF Estimator</a> and <a href="https://www.tensorflow.org/api_docs/python/tf/keras/Model">keras.Model</a> but with much greater flexibility, for turnkey model training, evaluation, prediction, <a href="https://github.com/lanpa/tensorboardX#screenshots">TensorBoard</a> visualization, and seamless combination with external <em>hyperparameter tuning</em> tools.</li></ul><h3>What Texar-PyTorch Provides</h3><p>With the best TF features integrated into the intuitive PyTorch programming model, Texar-Pytorch provides comprehensive support for building ML applications:</p><ul><li><strong>State-of-the-Art Model Building Blocks</strong> — building an ML model is like assembling Lego bricks. Plugging-in and swapping-out modules as you like. <a href="https://medium.com/p/d89c2c2d1d61#2287">Read more</a></li><li><strong>Easy and Efficient Data Processing</strong> — rich built-in processors for common types of datasets. Simple-but-powerful interfaces for arbitrary <em>custom</em> Best practice integrated, no worry about efficiency. <a href="https://medium.com/p/d89c2c2d1d61#5377">Read more</a></li><li><strong>Turnkey and Flexible Model Training with Executors</strong> — Getting free of boilerplate code for training and evaluation loops, while still highly flexible to customize for your specialized need. <a href="https://medium.com/p/d89c2c2d1d61#3651">Read more</a></li></ul><p>Code Example 1 demonstrates the complete code of using Texar-PyTorch to build and train a state-of-the-art sequence-to-sequence model for, e.g., text summarization and machine translation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*0JCLQljYqNtjpERo.png" /><figcaption><strong>Code Example 1:</strong> Building and training a conditional GPT-2 model (e.g., for text summarization) with Texar-PyTorch.</figcaption></figure><h3>Why Choose Texar?</h3><ul><li><strong>Supports both TensorFlow &amp; PyTorch.</strong> Sometimes it’s not your choice of which underlying framework to use, and learning a new higher-level framework is probably just as time-consuming as writing the parts yourself. Now with Texar, you can use the same interfaces with minimal changes in both frameworks. The two versions can even share pre-trained model weights that you’ve downloaded.</li><li><strong>Provides Natural Language Processing, All in One Kit.</strong> Texar has a comprehensive coverage of neural models on natural language processing tasks, especially <strong>text generation</strong>. Figure 1 gives a snapshot of Texar modules. With Texar, not only will you have access to a complete range of state-of-the-art pre-trained models, but you’ll also find all the utilities you need, from data processing to modeling to training and evaluation. We’ve got you covered.</li><li><strong>Facilitates Novice- and Expert-Friendly.</strong> Whether you’ve just picked up deep learning, or you’re an experienced researcher, you’ll find Texar easy to use. Texar provides state-of-the-art built-in components but remains flexible enough for customizations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*xIyLxGjKM0rBbCf1.png" /><figcaption><strong>Figure 1:</strong> Texar provides a comprehensive set of modules for data processing, model architectures, loss functions, training, evaluation, as well as a range of state-of-the-art pre-trained ML/NLP models (e.g., BERT, GPT-2, etc).</figcaption></figure><p>In the following, we provide more details of the three key parts with Texar-PyTorch, including modeling, data, and training.</p><h3>Modeling</h3><p>As shown in Figure 1, Texar-Pytorch offers a full set of ML modules. With the well-designed interfaces, users can freely build arbitrary models by assembling the building blocks.</p><p>The following example shows how flexible the module interfaces are to meet the needs of different learning algorithms, such as maximum-likelihood learning and adversarial learning. Moreover, Texar provides <strong>interfaces at multiple abstraction levels</strong> for users of different expertise. For example:</p><ul><li>It’s straightforward to invoke a <em>common inference</em> method, e.g., teacher-forcing decoding, by simply setting the decoder argument `decoding_strategy=’train_greedy’`.</li><li>OTOH, to perform <em>advanced inference</em>, e.g., Gumbel softmax decoding for adversarial learning, users can use a GumbelSoftmaxHelper. Expert users can further define new Helpers to customize whatever decoding strategies.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*2PKg2fytyS_23Lmw.png" /><figcaption><strong>Code Example 2:</strong> Building a pre-trained GPT-2 language model, fine-tuning with maximum-likelihood learning and adversarial learning (using BERT as the discriminator).</figcaption></figure><p>To summarize, modeling with Texar-PyTorch features the following key advantages:</p><ul><li><strong>Excellent modularization</strong> — switching between different learning contexts is enabled by simply plugging in/swapping out a couple of modules.</li><li><strong>Multi-level interfaces </strong>— high-level intuitive interfaces for novice users and low-level highly-customizable ones for expert users.</li><li><strong>Built-in state-of-the-art pre-trained models</strong> — BERT, GPT-2, RoBERTa, XLNet and more, for tasks of text encoding, classification, sequence tagging, and generation.</li></ul><h3>Data</h3><p>Texar-Pytorch data modules are designed for <strong>easy, efficient,</strong> and <strong>customizable</strong>data access for any ML and NLP tasks. Combining the best practices from TensorFlow <a href="https://www.tensorflow.org/guide/data">tf.data</a>, the modules greatly enhances the PyTorch native <a href="https://pytorch.org/docs/stable/data.html">DataLoader</a> by:</p><ul><li>Decoupling <em>single instance processing</em> and <em>batching</em> — for clearer program logic and easier customization</li><li>Buffer-based shuffling, caching, and lazy-loading — for greater efficiency</li><li>Extensive dataset iterators — no extra user configuration needed</li><li>More intuitive APIs — no expertise needed to get the best practices in your project</li></ul><p><strong>Texar-PyTorch Built-in Datasets</strong></p><p>For common types of datasets, Texar-Pytorch already includes ready-to-use modules, as shown in Figure 2 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*F3qwemXkiiFahD7G.png" /><figcaption><strong>Figure 2:</strong> Texar-Pytorch built-in datasets for a majority of ML and NLP tasks.</figcaption></figure><p>In particular, <strong>RecordData</strong> is Texar’s equivalent to Tensorflow’s well-known <a href="https://www.tensorflow.org/tutorials/load_data/tfrecord">TFRecordData</a>, which reads files in binary format and thus allows arbitrary data types ranging from text to images. Cool, isn’t it! What’s more — The usage pattern is very similar to TFRecordData. The example below says it all.</p><p>Let’s say you want to train an image captioning model. Each data example would typically contain an image, a caption, and other meta info. Below is how you would do it in Texar-Pytorch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*SWXuPcSjDgXjTK7-.png" /><figcaption><strong>Code Example 3</strong>: Loading complex image captioning data with Texar-Pytorch RecordData.</figcaption></figure><p><strong>Creating Custom Datasets</strong></p><p>Users can customize how to process and batch data instances, and Texar will take care of caching, lazy processing, iterating for you. The toy example below explains it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*IH3fC1QUwB4znOpq.png" /><figcaption><strong>Code Example 4</strong>: A customized dataset that performs BPE tokenization for input text.</figcaption></figure><h3>Executor</h3><p>Have you ever been bored by writing the training-evaluation loop, again and again, each time when starting a new project? Have you desired a single API to automate the loop, equipped with logging, checkpointing, visualization, and hyperparameter tuning? Do you even want the API to be flexible enough for your non-traditional algorithms, e.g., alternating multiple losses in adversarial learning? Texar Executor is here for you.</p><p>Executor is the PyTorch equivalent of the widely-used <a href="https://www.tensorflow.org/guide/estimator">TF Estimator</a> and <a href="https://www.tensorflow.org/api_docs/python/tf/keras/Model">tf.keras.Model</a>, but is designed to be lightweight and much more customizable.</p><p>To demonstrate the power of Executor, we show an example of a hand-written train-eval loop v.s. Executor:</p><p>Let’s say we want the following functions in our project:</p><ul><li>Print logs every `logging_steps` iteration to the console, a log file, and Tensorboard.</li><li>Perform validation every `validate_steps` iteration, by evaluating the model output with the BLEU metric.</li><li>If validation results improve, save the current checkpoint. If results failed to improve for `patience` consecutive trials, load the previous checkpoint, and scale the learning rate.</li></ul><p>The steps above describe a pretty universal training loop. Here’s what a hand-written training loop would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*PTbhvZBLmtGjPwGT.png" /><figcaption><strong>Code Example 5:</strong> A typical hand-written train-eval loop.</figcaption></figure><p>The code is very lengthy and tedious. Things can get even more troublesome when you need to add or change some functionalities. Now, what will the code look like, if we used Executors?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*hkPf4r7aVKz2kBcy.png" /><figcaption><strong>Code Example 6:</strong> The same train-eval loop with Executor.</figcaption></figure><p>And this is how Executor logs look in the command line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*usCrF3f70bwZJme2.gif" /></figure><p>Here you can observe that the validation BLEU is updated in-place, based on the previously predicted values. This is thanks to the Executor streaming metrics, which allows incremental computation of metric values. No need to wait until the end to see results on a large validation set!</p><p>As we can see, code with Executor is much more structured and readable. It is also much more extensible:</p><ul><li><strong>Q:</strong> What if we also want to do validation after each epoch?<br><strong>A:</strong> Simply change `validate_every` to:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*MqZKWjX3z95sNInd.png" /></figure><ul><li><strong>Q:</strong> What if we want to perform early stopping after we’ve scaled the learning rate `early_stop_patience` times?<br><strong>A:</strong> Simply change `action_on_plateau` to:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*WEva6KT9ijnqJej_.png" /></figure><ul><li><strong>Q:</strong> What if we also want to measure the word-level loss?<br><strong>A:</strong> Simply add a new metric to `valid_metrics`:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*sH3ByCVgfv8z1_MC.png" /></figure><ul><li><strong>Q:</strong> What if we want to do hyperparameter tuning and train the model multiple times?<br><strong>A:</strong> Simply create an Executor for each set of hyperparameters that you want to test. Since Executor takes care of everything besides model creation, you don’t need to worry about consuming extra memory or accidentally retaining objects from previous runs. Here’s an example of <a href="https://github.com/asyml/texar-pytorch/blob/master/examples/bert/bert_with_hypertuning_main.py">using Executor with hyperopt</a>.</li><li><strong>Q:</strong> What if, at the end of each epoch, we want to upload the current checkpoint to the server, send an email containing the training progress, and take the dog out for a walk?<br><strong>A:</strong> Weird, but okay. Simply register a custom action on a condition of your choice, and do whatever you wish:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*NN8ruu_lc1IibqPz.png" /></figure><h3>Switching from Texar-TF to Texar-PyTorch</h3><p>If you are a previous Texar-TF user, switching to Texar-PyTorch requires only minimal effort. Compared to Texar TensorFlow, Texar PyTorch has almost the same interfaces, making transitions between backends easy.</p><p>Although having similar interfaces, we also follow coding conventions for each framework, so you wouldn’t feel like learning a new sub-language. To this end, we changed some of the lower-level extensible interfaces to match the native design of respective frameworks more closely . Most of the changes lie in the data and executor modules, but as you’ve already seen, they’re still pretty easy to pick up.</p><h3>Getting Started</h3><p>To get started, visit our <a href="https://github.com/asyml/texar-pytorch">GitHub repository</a> and follow the installation instructions. Useful resources include:</p><ul><li><a href="https://texar-pytorch.readthedocs.io/en/latest/">Documentation</a>: We have detailed documentation for every module and function.</li><li><a href="https://github.com/asyml/texar-pytorch/blob/master/examples/README.md">Examples</a>: We strongly encourage you to check out our examples to get a basic idea of how Texar is used in practice. The examples are clearly documented and cover rich use cases.</li><li><a href="https://asyml.io/">ASYML Library</a>: Find quick links to all Texar resources in one place.</li></ul><p><em>*</em>Petuum<em> is a corporate sponsor of Texar. Petuum engineers are continuously contributing to the Texar code base and have been pivotal in this release.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89c2c2d1d61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting the Dots Between MLE and RL for Sequence Generation]]></title>
            <link>https://medium.com/@texar/connecting-the-dots-between-mle-and-rl-for-sequence-generation-d65830b0eaf6?source=rss-3228ffec7a48------2</link>
            <guid isPermaLink="false">https://medium.com/p/d65830b0eaf6</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[natural-language-process]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Texar]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 20:09:19 GMT</pubDate>
            <atom:updated>2019-01-10T04:09:03.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cS9qlhvAnw_JXSJB9mrjEA.png" /></figure><p><em>Crossposted on the </em><a href="https://medium.com/@Petuum/connecting-the-dots-between-mle-and-rl-for-sequence-generation-c6a50295cae"><em>Petuum blog</em></a><em>.</em></p><p>Sequence generation is a ubiquitous problem in many applications, such as machine translation, text summarization, image captioning, and so forth.</p><p>Recently, we published a <a href="https://arxiv.org/abs/1811.09740">paper</a> on a unified perspective of a variety of well-used learning algorithms for sequence generation, based on a generalized entropy regularized policy optimization formulation. We show that these algorithms are mathematically equivalent to specifying certain hyperparameter configurations in the framework. The new principled treatment provides systematic understanding and comparison among the algorithms and inspires further enhancement. We also propose a new interpolation algorithm based on the universal framework, which shows consistent improvement in machine translation and text summarization.</p><p>The development of sequence models such as recurrent neural networks (RNNs) with diﬀerent cells and attention mechanisms has enabled great advances in tasks requiring sequence generation. These models can be trained with a variety of learning algorithms, which we’ll outline below.</p><h3>Popular Algorithms (The Dots)</h3><p>The standard training algorithm is based on maximum-likelihood estimation (MLE), which seeks to maximize the log-likelihood of ground-truth sequences. Despite its computational simplicity and efﬁciency, MLE training suﬀers from <em>exposure bias</em> — that is, the model is trained to predict the next token given the ground-truth tokens that came before. Since the resulting model does not have access to the ground truth, at test time, the tokens generated by the model itself are used to make the next prediction instead. This discrepancy between training and testing can cause mistakes in prediction to quickly accumulate.</p><p>There have been several efforts to alleviate this issue, many of which resort to reinforcement learning (RL) techniques. For example, <a href="https://arxiv.org/abs/1511.06732">Ranzato et al., 2015</a>, adopt a policy gradient algorithm that avoids the training/testing discrepancy by using the same decoding strategy at both training and test time. However, RL-based approaches for sequence generation can face prohibitively poor sample efﬁciency and high variance.</p><p>For more practical training, others have developed a diverse set of methods that are in a middle ground between the MLE and RL paradigms. For example, RAML (<a href="https://papers.nips.cc/paper/6547-reward-augmented-maximum-likelihood-for-neural-structured-prediction">Norouzi et al., 2016</a>) adds reward-aware perturbation to the MLE data examples, SPG (<a href="https://papers.nips.cc/paper/6874-cold-start-reinforcement-learning-with-softmax-policy-gradient.pdf">Ding &amp; Soricut, 2017</a>) leverages reward distribution for eﬀective sampling of policy gradient, and other approaches such as data noising (<a href="https://openreview.net/forum?id=H1VyHY9gg">Xie et al., 2017</a>) also show improved results.</p><p><strong>Maximum Likelihood Estimation (MLE)</strong></p><p>Maximum likelihood estimation is the most widely-used approach to train a sequence generation model due to its simplicity and eﬃciency. MLE aims to ﬁnd the optimal parameter value that maximizes the data log-likelihood:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g8jRX4fYtBeLAjwd" /></figure><p><strong>Reward Augmented Maximum Likelihood (RAML)</strong></p><p>RAML was originally proposed to incorporate task metric rewards into MLE training and has shown superior performance to vanilla MLE. Speciﬁcally, RAML introduces an exponentiated reward distribution <strong><em>e(y|y*) ∝ exp{R(y|y*)}</em></strong> where <strong><em>R</em></strong>, as in vanilla policy optimization, is a task metric such as <a href="https://en.wikipedia.org/wiki/BLEU">BLEU</a>. RAML maximizes the following objective:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zpqfh2sDUUSx4Pk_" /></figure><p>The RAML objective reduces to the vanilla MLE objective if we replace the task reward <strong><em>R</em></strong> in <strong><em>e(y|y*)</em></strong> with the MLE <strong><em>δ</em></strong>-reward, which is a reward function defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UJAxqVQ_mXM9eIdH" /></figure><p><strong>Data Noising</strong></p><p>Adding noise to training data is a widely adopted technique for regularizing models. Previous work has proposed several data noising strategies in the sequence generation context. For example, unigram noising with probability <strong><em>γ</em></strong> replaces each token in data<strong> <em>y*</em></strong> with a sample from the unigram frequency distribution. The resulting noisy data is then used in MLE training. Formally, it is equivalent to using a reward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sPL-0t9Y3xod88x0" /></figure><p>where <strong><em>u(·)</em></strong> is the unigram frequency distribution. With a relaxed (i.e., smoothed) reward, data noising expands the exploration space of vanilla MLE locally. The effect is essentially the same as the RAML algorithm, except that RAML expands the exploration space based on the task metric reward.</p><p><strong>Softmax Policy Gradient (SPG)</strong></p><p>SPG was developed with the purpose of adapting the vanilla policy gradient to use as the reward for sampling. SPG has the following objective:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/0*q8lEh8IjrlrVtVcg" /></figure><p>where R is a common reward. As a variant of the standard policy gradient algorithm, SPG aims to address the exposure bias problem and shows promising results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GsJXJRcXulKwQDSwZ6CZQ.png" /><figcaption>Figure 1. Effective exploration space of different algorithms. (a): The exploration space of MLE is exactly the set of training examples. (b): RAML and Data Noising use smooth rewards and allow larger exploration space surrounding the training examples. ©: Common policy optimization such as SPG basically allows the whole exploration space.</figcaption></figure><h3>Connecting the Dots</h3><p>We establish a uniﬁed perspective of this broad set of learning algorithms. Speciﬁcally, we present a generalized <em>entropy regularized </em>policy optimization (ERPO) framework and show that the apparently diverse algorithms, such as MLE, RAML, SPG, and data noising, can all be re-formulated as special instances of the framework with the only diﬀerence being <em>the</em><strong><em> </em></strong><em>choice of reward </em>and<em> the values of a couple of hyperparameters</em>.</p><p>In addition to a new understanding of existing algorithms, our uniﬁed perspective also facilitates the development of new algorithms for improved learning. We present an example new algorithm that, as training proceeds, gradually expands the exploration space by annealing the reward and hyperparameter values. The annealing, in eﬀect, dynamically interpolates among the existing algorithms. Experiments on machine translation and text summarization show that the interpolation algorithm achieves signiﬁcant improvement over the various existing methods.</p><h3>The General Framework</h3><p>Our general framework is aimed at unifying all of the above algorithms with a common mathematical formulation. The framework is based on <em>policy optimization,</em> which, in general, maximizes the expected reward under the model distribution. A rich line of research into <em>entropy regularized</em> policy optimization (ERPO) has stabilized learning by augmenting policy optimization with information theoretic regularizers. Here, we present a <em>generalized</em> formulation of ERPO. Specifically, assuming a variational distribution <strong><em>q(y|x)</em></strong>, we adopt the objective:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MRQ6ljZkQosiqBMq" /></figure><p>where <strong><em>(x, y*)</em></strong> is the pair from training data; y is the sentence sampled following distribution <strong><em>q(y|x)</em></strong>; <strong><em>KL(·||·)</em></strong> is the KL divergence; <strong><em>H(·)</em></strong> is the Shannon Entropy; <strong><em>α</em></strong> and <strong><em>β</em></strong> are balancing weights of the respective terms; and <strong><em>pθ</em></strong> is the sequence generation model parameterized with <strong><em>θ</em></strong>.</p><p>Using the <a href="https://en.wikipedia.org/wiki/Lagrange_multiplier">Lagrange multipliers method</a>, this objective can be maximized with an <a href="https://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm">EM-style procedure</a> that iterates two coordinate ascent steps optimizing <strong><em>q</em></strong> and <strong><em>θ</em></strong>, respectively. At iteration <strong><em>n</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dBJeAgn6HdofBfpn" /></figure><h3>Other Algorithms as Special Instances</h3><p>By assuming the ERPO framework, we can characterize other sequence generation algorithms as special instances within it.</p><p><strong>Maximum Likelihood Estimation (MLE)</strong></p><p>Let <strong><em>(R = Rδ, α → 0, β = 1)</em></strong>. From the E-step of ERPO, we have<strong><em> q(y|x) = 1 </em></strong>if <strong><em>y = y*</em></strong>, and <strong><em>0</em></strong> otherwise. The M-step is therefore equivalent to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_K8LAm1CnrVxkp0b" /></figure><p>which recovers precisely the MLE objective.</p><p>That is, MLE can be seen as an instance of the policy optimization algorithm with the <strong><em>δ</em></strong>-reward and the above weight values. Any sample <strong><em>y</em></strong> that fails to match precisely the data <strong><em>y*</em></strong> will receive a negative inﬁnite reward and never contribute to model learning.</p><p><strong>Reward Augmented Maximum Likelihood (RAML)</strong></p><p>As we discussed, the RAML objective reduces to the vanilla MLE objective if we replace the task reward <strong><em>R</em></strong> in <strong><em>e(y|y*)</em></strong> with the MLE <strong><em>δ</em></strong>-reward. The relation between MLE and RAML still holds within ERPO. Similar to the way we recovered MLE from ERPO, if we let <strong><em>(α → 0, β = 1)</em></strong>, but set <strong><em>R</em></strong> to the task metric reward, then the M-step of ERPO is precisely equivalent to maximizing the above RAML objective.</p><p><strong>Data Noising</strong></p><p>Though previous literature has covered techniques such as including a data pre-processing step that differs from the above learning algorithms, the ERPO framework can also subsume data noising as a special instance. Speciﬁcally, starting from the ERPO reformulation of MLE, which takes <strong><em>(R = Rδ, α → 0, β = 1)</em></strong>, data noising can be formulated as using the unigram-relaxed <strong><em>Rδ</em></strong> discussed above.</p><p><strong>Softmax Policy Gradient (SPG)</strong></p><p>SPG can also readily ﬁt into our ERPO framework. By taking the gradient of the objective of SPG w.r.t <strong><em>θ</em></strong>, we immediately get the same update rule as in ERPO with <strong><em>(α = 1, β = 0, R = common reward)</em></strong>.</p><p>Note that the only difference between the SPG and RAML conﬁguration is that now<strong><em> α = 1</em></strong>. SPG thus moves a step further than RAML by leveraging both the reward and the model distribution for full exploration. Sufﬁcient exploration at training time would, in theory, boost the test-time performance. However, with the increased learning difﬁculty, additional sophisticated optimization and approximation techniques must be used (Ding &amp; Soricut, 2017) in order to make the training practical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faBpmFTKtxdNaohrElZxWw.png" /><figcaption>Figure 2. A unified formulation of different learning algorithms. Each algorithm is a special instance of the general ERPO framework taking certain specifications of the hyperparameters (<em>R, α, β).</em></figcaption></figure><h3>Application: Interpolation Algorithm</h3><p>In our generalized ERPO framework, a series of well-used learning algorithms can all be understood as instances of the framework with certain speciﬁcations of the three hyperparameters <strong><em>(R, α, β)</em></strong>. Each of the algorithms can be seen as a point in the hyperparameter space (Figure 1). Generally, a point with a more restricted reward function <strong><em>R</em></strong> and a very small <strong><em>α</em></strong> tends to have a smaller effective exploration space and allow efﬁcient learning (e.g., MLE), while in contrast, a point with smooth <strong><em>R</em></strong> and a larger <strong><em>α</em></strong> would lead to a more difﬁcult learning problem, but permit more sufﬁcient exploration and better test-time performance (e.g., (softmax) policy gradient). In our paper, we also explore an example algorithm that interpolates the existing ones.</p><p>The interpolation algorithm exploits the natural idea of starting learning from the most restricted yet easiest problem conﬁguration, and gradually expands the exploration space to reduce the discrepancy from the test time — the easy-to-hard learning paradigm. As we have mapped common algorithms to points in the hyperparameter space, interpolation becomes very straightforward and only requires annealing of the hyperparameter values.</p><h3>Experimental Results</h3><p>We evaluate the above interpolation algorithm on the tasks of <em>machine translation</em> and <em>text summarization</em>. The proposed algorithm consistently improves over a variety of previous methods, as shown in the figures below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvjKZgGRAy6_PFwRZM9fHA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*XcuOwy0Pb6gzMbOtKOBClA.png" /><figcaption>Figure 3. The graph on the left is the convergence curve of different learning algorithms in the machine translation task. On the right is the improvement on text summarization in comparison to MLE.</figcaption></figure><h3>Code</h3><p>Our code for experiments is available <a href="https://github.com/asyml/texar/tree/master/examples/seq2seq_exposure_bias">here</a>. Implementations are based on <a href="https://texar.io/">Texar</a>, a general-purpose and easy-to-use text generation toolkit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d65830b0eaf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Texar: A Modularized, Versatile, and Extensible Toolkit for Text Generation and Beyond]]></title>
            <link>https://medium.com/@texar/introducing-texar-a-modularized-versatile-and-extensible-toolkit-for-text-generation-and-beyond-589a5832b023?source=rss-3228ffec7a48------2</link>
            <guid isPermaLink="false">https://medium.com/p/589a5832b023</guid>
            <category><![CDATA[text-generation]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[aritificial-intelligence]]></category>
            <dc:creator><![CDATA[Texar]]></dc:creator>
            <pubDate>Tue, 18 Sep 2018 18:41:13 GMT</pubDate>
            <atom:updated>2018-09-18T19:10:03.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OYKZ4SN7JCIyQTIUGrICpw.png" /></figure><p><em>Crossposted on the </em><a href="https://medium.com/@Petuum/introducing-texar-a-modularized-versatile-and-extensible-toolkit-for-text-generation-and-beyond-b4e3289d5205"><em>Petuum blog</em></a><em>.</em></p><p>We are excited to introduce Texar, an open-source, general-purpose toolkit that supports a broad set of machine learning applications with a focus on text generation tasks. Texar is particularly suitable for researchers and practitioners of fast model prototyping and experimentation.</p><h3>Text Generation at a Glance</h3><p>Text generation spans a broad set of natural language processing (NLP) tasks that aim to generate natural language from input data or machine representations. Such tasks include machine translation, dialog systems, text summarization, article writing, text paraphrasing and manipulation, image captioning, and more. While this field has undergone rapid progress in both academic and industry settings, in part due to the integration of modern deep learning approaches, considerable research efforts are still needed in order to improve techniques and enable real-world applications.</p><p>Text generation tasks have many common properties and share two central goals:</p><ul><li><em>Generating human-like, grammatical, and readable text.</em></li><li><em>Generating text that contains all relevant information inferred from inputs. </em>For example, in machine translation, the translated sentence that is generated must express the same meaning as the source sentence.</li></ul><p>To this end, a few key techniques are increasingly widely-used, such as neural encoder- decoders, attentions, memory networks, adversarial methods, reinforcement learning, and structured supervision, as well as optimization, data pre-processing and result post-processing procedures, evaluations, and etc. These techniques are often combined together in various ways to tackle different problems (<strong>Figure 1</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xuDRWk7sp5HqYgzF" /><figcaption>Figure 1. An example of various model architectures used in text generation tasks, where E refers to encoder, D to decoder, C to Classifier, A to attention, Prior to prior distribution, and M to memory.</figcaption></figure><p>It is therefore highly desirable to have an open-source platform that unifies the development of these diverse yet closely-related text generation applications, backed with clean and consistent implementations of the core algorithms. Such a unified platform would <strong>enable reuse of common components and functionalities; standardize design, implementation, and experimentation; foster reproducible research</strong>; and, importantly, <strong>encourage technique sharing</strong> <strong>among different text generation tasks</strong> so that an algorithmic advance developed for a specific task can quickly be evaluated and generalized to many other tasks.</p><h3>Introducing Texar</h3><p>To that end, we have developed <a href="https://texar.io">Texar</a>, an open-source toolkit focused on text generation tasks, using the TensorFlow language. Texar is modular, versatile, and extensible. It extracts common patterns underlying the diverse tasks and methodologies within text generation and creates a library of highly reusable modules and functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vuwm06TMPOoVo6sR" /><figcaption>Figure 2. Texar’s main modules and functionalities.</figcaption></figure><h4>Versatility</h4><p>Texar contains a wide range of modules and functionalities for composing arbitrary model architectures and implementing various learning algorithms such as maximum likelihood learning, reinforcement learning, adversarial learning, probabilistic modeling, and so forth (Figure 2).</p><h4>Modularity</h4><p>Texar decomposes diverse complex machine learning models/algorithms into highly-reusable model architecture, loss, and learning process modules, among others.</p><p>Users can easily construct their own models at a high conceptual level by assembling Texar’s modules like building blocks. Texar makes plugging-in and swapping-out modules simple — for example, switching between maximum likelihood learning and reinforcement learning only involves changing a few lines of code.</p><h4>Extensibility</h4><p>Texar can be effortlessly integrated with any user-customized, external modules, and is fully compatible with the TensorFlow open source community, including TensorFlow-native interfaces, features, and resources.</p><h4>Usability</h4><p>With Texar, users can customize models with templates/examples and simple <strong>Python/YAML configuration files</strong>, or program from Texar’s <strong>Python Library APIs</strong> for maximal customizability.</p><p>Texar provides convenient automatic variable reuse (no need to worry about complicated TensorFlow variable scopes), simple function-like calls to perform module logic, and rich configuration options with sensible default values for every module.</p><p>Texar emphasizes well-structured, highly-readable code with uniform design patterns and consistent styles, along with clean documentation and rich tutorial examples.</p><p>Texar is currently supporting several research and engineering projects at Petuum, Inc. We hope the toolkit can also empower the community to accelerate technique development in text generation and beyond. We also invite researchers and practitioners to join and further enrich the toolkit so that, together, we can advance text generation research and applications.</p><p><strong>Please check out the following resources to learn more about Texar:</strong></p><p>Website: <a href="https://texar.io">https://texar.io</a></p><p>GitHub: <a href="https://github.com/asyml/texar">https://github.com/asyml/texar</a></p><p>Examples: <a href="https://github.com/asyml/texar/blob/master/examples">https://github.com/asyml/texar/blob/master/examples</a></p><p>Documentation: <a href="https://texar.readthedocs.io/">https://texar.readthedocs.io/</a></p><p>Tech report: <a href="https://arxiv.org/pdf/1809.00794.pdf">https://arxiv.org/pdf/1809.00794.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=589a5832b023" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>