首页 > 解决方案 > 无法将 iob 转换为 spaCy 二进制格式

问题描述

我尝试将我的 IOB(每行令牌 NER)文件(训练/测试)转换为 Spacy 3 二进制格式。

输入格式示例(带分隔符“\t”,无空白行和编码 utf-8):

Département B-LOCATION
des I-LOCATION
Bouches-du-Rhône    I-LOCATION
.   O
Port    B-INSTALLATION
de  I-INSTALLATION
la  I-INSTALLATION
Ciotat  I-INSTALLATION
.   O
Avant-projet    O
du  O
môle    B-INSTALLATION
Bérouard    I-INSTALLATION
au  O
port    B-INSTALLATION
de  I-INSTALLATION
La  I-INSTALLATION
Ciotat  I-INSTALLATION
.   O

当我运行时:

!python -m spacy convert -c iob -s -n 10 -b fr_core_news_sm /content/ner4archives_v0_train.iob .

!python -m spacy convert -c iob -s -n 10 -b fr_core_news_sm /content/ner4archives_v0_test.iob .

我有这个错误:

ValueError: [E903] The token-per-line NER file is not formatted correctly. Try checking whitespace and delimiters. See https://spacy.io/api/cli#convert

我看到了带有示例数据的 git 目录:https ://github.com/explosion/spaCy/tree/master/extra/example_data/ner_example_data ;但我找不到我的数据和示例之间的区别。

我尝试使用不同类型的分隔符(“\t”、“”、“|”)重新格式化我的文件,但我总是遇到同样的错误。此外,我测试了我是否有空标记或标签,它不是。

有线索的人吗?提前致谢。

标签: pythonnlpspacynamed-entity-recognition

解决方案


我认为您使用的 SpaCy 版本不是3.X,我可以.spacy使用您的输入创建二进制文件,下载后没有任何问题fr_core_news_sm

命令:

python -m spacy convert -c iob -s -n 10 -b fr_core_news_sm C:/git/sof/test.iob .

输出:

[i] Auto-detected token-per-line NER format
[i] Grouping every 10 sentences into a document.
[i] Segmenting sentences with parser from model 'fr_core_news_sm'.
[+] Generated output file (1 documents): test.spacy

SpaCy 版本:3.1.3


推荐阅读