Adding to the natural language processing toolkit

PyTorch-NLP 0.5.0 update adds Python 3.5 support & support for PyTorch 1.2

Sarah Schlothauer
© Shutterstock /yuratosno3

The newest update for PyTorch-NLP is here. The 0.5.0 update adds support for Python 3.5, PyTorch 1.2, rewrites the README to help new users build an NLP pipeline, and adds some new features. See how PyTorch-NLP helps with natural language processing and how PyTorch compares to similar machine learning frameworks such as TensorFlow.

Remember, remember!

The fifth of November,

The Pytorch-NLP and code.

Two years after the initial release of PyTorch-NLP comes the newest version. PyTorch-NLP 0.5.0 released with a few new features and updates in tow.

Let’s see what the update highlights include.

PyTorch-NLP version 0.5.0 updates

Major changes include:

  • Support for Python 3.5 added
  • README rewritten in order to show users how to build an NLP pipeline
  • Support for PyTorch 1.2 added
  • Added torchnlp.random which allows for more control of random state building on fork_rng.
  • Refactored torchnlp.samplers enabling pipelining
  • New corporate sponsorship added. Meet WellSaid Labs!

New additions:

  • torchnlp.samplers.balanced_sampler : Balances sampling and extends WeightedRandomSampler.
  • torchnlp.samplers.deterministic_sampler : Adds deterministic sampling based on torchnlp.random.
  • torchnlp.samplers.distributed_batch_sampler : Used for distributed batch sampling
  • torchnlp.samplers.oom_batch_sampler : Samples large batches first to force an out-of-memory error.
  • torchnlp.utils.lengths_to_mask : Creates masks from a batch of sequences.
  • torchnlp.utils.get_total_parameters : Measures the number of parameters in a model.
  • torchnlp.utils.get_tensors : Measures the size of an object in a number of tensor elements.

PyTorch-NLP requires Python 3.5+ and PyTorch 1.0+.


NLP use cases

NLP stands for natural language processing, which combines the linguistic field with machine learning in order to analyze natural language data.

Common use cases for NLP include automated email response suggestions, spam filters, e-commerce chatbots, automatic text translations, and voice to text messaging. And that’s just the tip of the iceberg, as shown with how mature and complex voice assistants have become.

SEE ALSO: How AI assists in threat analytics and ensures better cybersecurity

PyTorch-NLP is a library of utilities that extends to PyTorch, providing it with the basic functions needed for text data processing. It also includes some utility packages for additional support. These packages include deterministic functions, pre-training word vectors, neural network layers, and NLP metrics.

Read through the documentation and learn more. Or, check out the repo on GitHub.

PyTorch or TensorFlow?

Speaking of PyTorch, how commonly used is it compared to similar frameworks?

An October 2019 report published on The Gradient titled The State of Machine Learning Frameworks in 2019 explores the popularity and usage of ML frameworks.

Research shows that PyTorch is commonly used for research. In 2019, it was mentioned at general machine learning conferences (such as ICLR and ICML) more often than TensorFlow.

SEE ALSO: Top Python use cases: Bringing machine learning to the enterprise

According to the report, PyTorch excels for a few reasons. Developers love its simplicity, great API, and performance.

Simplicity. It’s similar to numpy, very pythonic, and integrates easily with the rest of the Python ecosystem. For example, you can simply throw in a pdb breakpoint anywhere into your PyTorch model and it’ll work. In TensorFlow, debugging the model requires an active session and ends up being much trickier.

Great API. Most researchers prefer PyTorch’s API to TensorFlow’s API. This is partially because PyTorch is better designed and partially because TensorFlow has handicapped itself by switching APIs so many times (e.g. ‘layers’ -> ‘slim’ -> ‘estimators’ -> ‘tf.keras’).

Performance. Despite the fact that PyTorch’s dynamic graphs give strictly less opportunity for optimization, there have been many anecdotal reports that PyTorch is as fast if not faster than TensorFlow. It’s not clear if this is really true, but at the very least, TensorFlow hasn’t gained a decisive advantage in this area.

Explore the interactive charts and see how PyTorch compares to TensorFlow.

Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is the editor for She received her Bachelor's degree from Monmouth University, West Long Branch, New Jersey. She currently lives in Frankfurt, Germany with her husband and cat where she enjoys reading, writing, and medieval reenactment. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Inline Feedbacks
View all comments