AttributeError: module 'torchtext.datasets' has no attribute 'text_classification'

774 Views Asked by At
agnews_train, agnews_test = torchtext.datasets.text_classification.DATASETS["AG_NEWS"](root="./datasets")

after running above line I am geting attribute error.

AttributeError Traceback (most recent call last) in ----> 1 agnews_train, agnews_test = torchtext.datasets.text_classification.DATASETS"AG_NEWS"

AttributeError: module 'torchtext.datasets' has no attribute 'text_classification'

1

There are 1 best solutions below

0
On

You are probably just using a different version. What you want is:

agnews_train, agnews_test = torchtext.datasets.AG_NEWS(root='./datasets', split=('train', 'test'))

Documentation