Knowing the field

Along with the keyword arguments that we've already mentioned, the Field class will also allow the user to specify special tokens (unk_token for out-of-vocabulary unknown words, pad_token for padding, eos_token for the end of a sentence, and an optional init_token for the start of the sentence).

The preprocessing and postprocessing parameters accept any torchtext.data.Pipeline that it receives. Preprocessing is applied after tokenizing but before numericalizing. Postprocessing is applied after numericalizing, but before converting them into a Tensor.

The docstrings for the Field class are relatively well written, so if you need some advanced preprocessing, you should probe them for more information:

from torchtext.data

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.