PacktPublishing/Mastering-PyTorch

Issue with torchtext.data.Fields

Opened this issue · 2 comments

I get the error message:
AttributeError: module 'torchtext.data' has no attribute 'Field'

On:
TEXT = torchtext.data.Field(tokenize=get_tokenizer("basic_english"), lower=True, eos_token='', init_token='')

I have seen in other places that they like removed Fields or something so I tried getting torchtext 0.6.0 and it did not fix it. If anyone has any suggestions I would love help!

I also want to know how to solve it.

This is one of the things we are fixing in the 2nd edition (coming out soon, in less than a month).
In short, indeed torchtext had discontinued Fields since version 0.9.0 and could then be accessed under their torchtext.legacy module. They then discontinued torchtext.legacy completely since version 0.12.0. My recommendation is (and something we are doing in v2 of the book) is to use torchtext==0.10.0 for this exercise, that in turn requires torch==1.9.0.