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

Building vocabulary

When we created one-hot encoding for thor_review, we created a word2idx dictionary, which is referred to as the vocabulary since it contains all the details of the unique words in the documents. The torchtext instance makes that easier for us. Once the data is loaded, we can call build_vocab and pass the necessary arguments that will take care of building the vocabulary for the data. The following code shows how the vocabulary is built:

TEXT.build_vocab(train, vectors=GloVe(name='6B', dim=300),max_size=10000,min_freq=10)LABEL.build_vocab(train)

In the preceding code, we pass in the train object on which we need to build the vocabulary, and we also ask it to initialize vectors with pretrained embeddings of dimensions

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