pytorch 错误:模块“functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.functions.f

lsmepo6l  于 2023-11-19  发布在  其他
关注(0)|答案(3)|浏览(127)

我想运行一个使用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 Torch 文本版本= 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)]
    )

mkshixfv

mkshixfv1#

来自TorchText 0.9.0Release Notes
torchtext.data.Field -> torchtext.legacy.data.Field
这意味着,所有功能仍然可用,但在torchtext.legacy而不是torchtext中。
torchtext.data.Field已移动到torchtext.legacy.data.Field
进口会发生这样的变化:

from torchtext.legacy import data

字符串

krcsximq

krcsximq2#

谢谢,@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中。

1bqhqjot

1bqhqjot3#

在0.6版中使用torchtext
pip install torchtext==0.6.0和重新启动内核

相关问题