BatchWrapper

Before we delve into BatchWrapper, let me tell you what the problem with batch objects is. Our batch iterator returns a custom datatype, torchtext.data.Batch. This has a similar to multiple example.Example. This returns with a batch of data from each field as attributes. This custom datatype makes code reuse difficult since, each time the column names change, we need to modify the code. This also makes torchtext hard to use with other libraries such as torchsample and fastai.

So, how do we solve this?

We will convert the batch into a tuple in the form (x, y). x is the input to the model and y is the target – or, more conventionally, x is the independent variable while y is the dependent variable. One way to think about this ...

Get Natural Language Processing with Python Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.