【问题标题】:TypeError: __init__() got an unexpected keyword argument 'tensor_type'TypeError: __init__() 得到了一个意外的关键字参数“tensor_type”
【发布时间】:2021-12-30 11:58:06
【问题描述】:

我正在尝试运行与旧版本的 torch 和 torchtext 一起使用的代码。我在代码中进行了很多调整以使其正常工作。我能够预处理和训练我的数据。最后我尝试运行测试脚本,在解决了多个错误后,我收到了这个错误:

Batch size > 1 not implemented! Falling back to batch_size = 1 ...
Traceback (most recent call last):
  File "translate_mm.py", line 166, in <module>
    main()
  File "translate_mm.py", line 84, in main
    onmt.ModelConstructor.load_test_model(opt, dummy_opt.__dict__)
  File "/onmt/ModelConstructor.py", line 145, in load_test_model
    checkpoint['vocab'], data_type=opt.data_type)
  File "/onmt/io/IO.py", line 57, in load_fields_from_vocab
    fields = get_fields(data_type, n_src_features, n_tgt_features)
  File "/onmt/io/IO.py", line 43, in get_fields
    return TextDataset.get_fields(n_src_features, n_tgt_features)
  File "/onmt/io/TextDataset.py", line 218, in get_fields
    postprocessing=make_src, sequential=False)
TypeError: __init__() got an unexpected keyword argument 'tensor_type'

我曾尝试降级到旧版本的 PyTorch,但是这样做时我得到一个 ModuleError 即:

ModuleNotFoundError: No module named 'torchtext.legacy'

我也尝试在 Anaconda 上运行它,根据要求使用适当的 pytorch 和 torchtext 版本,但我得到一个完全不同的错误:

import torch._dl as _dl_flags ImportError: No module named _dl

此时我只需要测试数据,其他一切似乎都已解决。任何帮助将不胜感激。

-U

【问题讨论】:

    标签: python pytorch google-colaboratory torchtext opennmt


    【解决方案1】:

    旧版本的 torchtext 没有遗留模块,因此如果您删除应该修复错误的调用部分。

    torchtext.legacy.___ -> torchtext.___

    【讨论】:

      猜你喜欢
      • 2012-12-11
      • 1970-01-01
      • 2017-10-16
      • 2020-10-22
      • 2021-11-17
      • 2016-11-01
      • 2021-10-21
      • 2021-10-15
      • 2020-08-21
      相关资源
      最近更新 更多