首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenNMT玩具的问题示例(Python3.9)

OpenNMT玩具的问题示例(Python3.9)
EN

Stack Overflow用户
提问于 2021-04-22 01:58:06
回答 1查看 264关注 0票数 2

我最近安装了OpenNMT,但在执行玩具示例时遇到以下错误。

我安装了macOS Big Sur 11.2.1,安装了python2.7和python3.9。

pip install --upgrade OpenNMT-py==2.0.0rc1

wget https://s3.amazonaws.com/opennmt-trainingdata/toy-ende.tar.gz

tar xf toy-ende.tar.gz

cd toy_ende

代码语言:javascript
复制
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/onmt_build_vocab", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/bin/build_vocab.py", line 63, in main
    build_vocab_main(opts)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/bin/build_vocab.py", line 23, in build_vocab_main
    ArgumentParser.validate_prepare_opts(opts, build_vocab_only=True)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 127, in validate_prepare_opts
    cls._validate_data(opt)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 42, in _validate_data
    cls._validate_file(path_src, info=f'{cname}/path_src')
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 18, in _validate_file
    raise IOError(f"Please check path of your {info} file!")
OSError: Please check path of your corpus_1/path_src file!
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-22 03:37:30

您可以按照以下步骤操作:

代码语言:javascript
复制
pip install --upgrade OpenNMT-py==2.0.0rc1;
wget https://s3.amazonaws.com/opennmt-trainingdata/toy-ende.tar.gz;
tar xf toy-ende.tar.gz;
echo '## Where the samples will be written
save_data: toy-ende/run/example
## Where the vocab(s) will be written
src_vocab: toy-ende/run/example.vocab.src
tgt_vocab: toy-ende/run/example.vocab.tgt
# Prevent overwriting existing files in the folder
overwrite: False

# Corpus opts:
data:
    corpus_1:
        path_src: toy-ende/src-train.txt
        path_tgt: toy-ende/tgt-train.txt
    valid:
        path_src: toy-ende/src-val.txt
        path_tgt: toy-ende/tgt-val.txt
' > toy_en_de.yaml;
mkdir toy-ende/run;
touch toy-ende/run/example.vocab.src;
touch toy-ende/run/example.vocab.tgt;
onmt_build_vocab -config toy_en_de.yaml -n_sample 10000;

echo '# Vocabulary files that were just created
src_vocab: toy-ende/run/example.vocab.src
tgt_vocab: toy-ende/run/example.vocab.tgt

# Train on a single GPU
world_size: 1
gpu_ranks: [0]

# Where to save the checkpoints
save_model: toy-ende/run/model
save_checkpoint_steps: 500
train_steps: 1000
valid_steps: 500
' >> toy_en_de.yaml;
onmt_train -config toy_en_de.yaml;

如果您没有GPU,则需要删除或注释以下行:

代码语言:javascript
复制
# Train on a single GPU
world_size: 1
gpu_ranks: [0]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67201174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档