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

Generate batches of vectors

Torchtext provides BucketIterator, which helps in batching all the text and replacing the words with the index number of the words. The BucketIterator instance comes with a lot of useful parameters like batch_size, device (GPU or CPU), and shuffle (whether data has to be shuffled). The following code demonstrates how to create iterators that generate batches for the train and test datasets:

train_iter, test_iter = data.BucketIterator.splits((train, test), batch_size=128, device=-1,shuffle=True)#device = -1 represents cpu , if u want gpu leave it to None.

The preceding code gives a BucketIterator object for train and test datasets. The following code will show how to create a batch and display the results of the ...

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