Spacy VALUERROR:无法读取文件:models/modelbest/accurity.json

2024-05-17 06:32:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在瑞典UD Treebank上训练一个Spacy模型

为此,我按照spacy页面上的说明进行操作: https://spacy.io/usage/training#spacy-train-cli

训练本身运行正常,但最后它试图打开一个由于某种原因不存在的文件。至少不是在这个地方

USER@Ubuntu18:~/spacy_models/sv$ python -m spacy train sv models talbanken-json/sv_talbanken-ud-train.json talbanken-json/sv_talbanken-ud-dev.json 
⚠ Output directory is not empty
This can lead to unintended side effects when saving the model. Please use an
empty directory or a different path instead. If the specified output path
doesn't exist, the directory will be created for you.
Training pipeline: ['tagger', 'parser', 'ner']
Starting with blank model 'sv'
Counting training words (limit=0)

Itn  Tag Loss    Tag %    Dep Loss    UAS     LAS    NER Loss   NER P   NER R   NER F   Token %  CPU WPS
---  ---------  --------  ---------  ------  ------  ---------  ------  ------  ------  -------  -------
  1  23722.240    87.792  74889.173  67.796  56.740      0.000   0.000   0.000   0.000  100.000    15740                                                                                                                             
....                                                                                                                          
 30    780.531    93.508  13930.092  81.295  75.906      0.000   0.000   0.000   0.000  100.000    15569                                                                                                                             
✔ Saved model to output directory
models/model-final

Traceback (most recent call last):
  File "/home/USER/miniconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/USER/miniconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/spacy/__main__.py", line 33, in <module>
    plac.call(commands[command], sys.argv[1:])
  File "/home/USER/miniconda3/lib/python3.7/site-packages/plac_core.py", line 328, in call
    cmd, result = parser.consume(arglist)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/plac_core.py", line 207, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/spacy/cli/train.py", line 497, in train
    best_model_path = _collate_best_model(meta, output_path, nlp.pipe_names)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/spacy/cli/train.py", line 559, in _collate_best_model
    bests[component] = _find_best(output_path, component)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/spacy/cli/train.py", line 578, in _find_best
    accs = srsly.read_json(epoch_model / "accuracy.json")
  File "/home/USER/miniconda3/lib/python3.7/site-packages/srsly/_json_api.py", line 50, in read_json
    file_path = force_path(location)
  File "/home/USER/miniconda3/lib/python3.7/site-packages/srsly/util.py", line 21, in force_path
    raise ValueError("Can't read file: {}".format(location))
ValueError: Can't read file: models/model-best/accuracy.json

相应的文件夹本身只包含一个meta.json文件:

$ ls models/model-best/
meta.json  ner  parser  tagger  tokenizer  vocab

幸运的是,模型本身的训练不受此问题的影响。不过,如果我能在不撞车的情况下运行它,那就太好了

我能做些什么来解决这个问题吗?


Tags: pathinpyjsonhomemodelspacylib
2条回答

我注意到一些实体不存在于有效数据集中,但存在于列车数据集中。这就是我解决上述问题的方法

注意脚本显示的警告,并从空输出目录开始:

⚠ Output directory is not empty
This can lead to unintended side effects when saving the model. Please use an
empty directory or a different path instead. If the specified output path
doesn't exist, the directory will be created for you.

相关问题 更多 >