我想运行一个使用pytorch和torchtext的git project,但是当我运行它时,它引发了错误:
File "main.py", line 60, in <module>
main()
File "main.py", line 50, in main
train_iters, dev_iters, test_iters, vocab = load_dataset(config)
File "/home/esmailza/style transfer/style-transformer/data.py", line 23, in load_dataset
TEXT = data.Field(batch_first=True, eos_token='<eos>')
AttributeError: module 'torchtext.data' has no attribute 'Field'torch版本= 1.8.0 torchtext版本= 0.9
def load_dataset(config, train_pos='train.pos', train_neg='train.neg',
dev_pos='dev.pos', dev_neg='dev.neg',
test_pos='test.pos', test_neg='test.neg'):
root = config.data_path
TEXT = data.Field(batch_first=True, eos_token='<eos>')
dataset_fn = lambda name: data.TabularDataset(
path=root + name,
format='tsv',
fields=[('text', TEXT)]
)发布于 2021-03-07 23:08:54
来自TorchText 0.9.0 Release Notes
torchtext.data.Field->torchtext.legacy.data.Field
这意味着,所有功能仍然可用,但在torchtext.legacy中,而不是在torchtext中。
torchtext.data.Field已移至torchtext.legacy.data.Field
而导入将以这种方式进行更改:
from torchtext.legacy import data发布于 2021-07-07 07:23:42
谢谢,@Rishabh Kumar也回答,这对我很有效!
来自TorchText 0.9.0的
发行说明
基于v0.9版本的https://github.com/pytorch/text/releases/tag/v0.9.0-rc5
遗留代码的当前用户将经历BC中断,因为我们已经淘汰了遗留代码(#1172,#1181,#1183)。将旧零部件放置在torchtext.legacy.data文件夹中,如下所示:
torchtext.data.Pipeline -> torchtext.legacy.data.Pipeline
torchtext.data.Batch -> torchtext.legacy.data.Batch
torchtext.data.Example -> torchtext.legacy.data.Example
torchtext.data.Field -> torchtext.legacy.data.Field
torchtext.data.Iterator -> torchtext.legacy.data.Iterator
torchtext.data.Dataset -> torchtext.legacy.data.Dataset这意味着,所有功能仍然可用,但在torchtext.legacy中,而不是在torchtext中。
https://stackoverflow.com/questions/66516388
复制相似问题