PacktPublishing / Mastering-PyTorch

Mastering PyTorch, published by Packt
MIT License
253 stars 109 forks source link

Issue with torchtext.data.Fields #15

Open ashercn97 opened 1 year ago

ashercn97 commented 1 year ago

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!

HanSLY-GISer commented 11 months ago

I also want to know how to solve it.

arj7192 commented 5 months ago

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.