February 2018
Intermediate to advanced
262 pages
6h 59m
English
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 ...