Solve the problem of AttributeError: module 'torchtext.data' has no attribute 'Field' (Datasets, Example, etc.)

1. Torchtext installation version corresponding

torch version: 1.xy

torchtext version: 1.x+1,y

 

2. Solve the problem of AttributeError: module 'torchtext.data' has no attribute 'Field'

 After torchtext=0.9.0 version, all data will be moved under "legacy", so add "legacy" before data

# 修改前
torchtext.data.Field()
# 修改后
torchtext.legacy.data.Field()

Guess you like

Origin blog.csdn.net/m0_45447650/article/details/132270718