gpt4 book ai didi

python - 属性错误 : module 'torchtext.data' has no attribute 'Field'

转载 作者:行者123 更新时间:2023-12-03 15:21:00 24 4
gpt4 key购买 nike

我想运行一个 git project使用 pytorch 和 torchtext 但是当我运行它时,它会引发错误:

  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'
火炬版本 = 1.8.0
火炬文本版本 = 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)]
)

最佳答案

来自 TorchText 0.9.0 Release Notes

torchtext.data.Field -> torchtext.legacy.data.Field
This means, all features are still available, but within torchtext.legacy instead of torchtext.

torchtext.data.Field已移至 torchtext.legacy.data.Field
进口会以这种方式改变:
from torchtext.legacy import data

关于python - 属性错误 : module 'torchtext.data' has no attribute 'Field' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66516388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com