Skip to Content
Deep Learning with PyTorch
book

Deep Learning with PyTorch

by Vishnu Subramanian
February 2018
Intermediate to advanced
262 pages
6h 59m
English
Packt Publishing
Content preview from Deep Learning with PyTorch

torchtext.data

The torchtext.data instance defines a class called Field, which helps us to define how the data has to be read and tokenized. Let's look at the following example, which we will use for preparing our IMDB dataset:

from torchtext import dataTEXT = data.Field(lower=True, batch_first=True,fix_length=20)LABEL = data.Field(sequential=False)

In the preceding code, we define two Field objects, one for actual text and another for the label data. For actual text, we expect torchtext to lowercase all the text, tokenize the text, and trim it to a maximum length of 20. If we are building the application for a production environment, we may fix the length to a much larger number. But, for the toy example it works well. The Field constructor ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Deep Learning with PyTorch

Deep Learning with PyTorch

Eli Stevens, Thomas Viehmann, Luca Pietro Giovanni Antiga
Grokking Deep Learning

Grokking Deep Learning

Andrew W. Trask

Publisher Resources

ISBN: 9781788624336Supplemental Content