使用 spaCy 构建自定义模型时出错
an error to build a custom model using spaCy
问题
在 the official instruction 之后,我正在尝试添加额外的训练数据集并在本地 cpu 环境中训练模型。
但我没有更改 base_config.cfg 和 config.cfg 文件的内容。
如何修复这些错误以构建模型并对其进行评估?
错误
我不确定第一个是否有问题,我也不知道要填写 config.cfg 文件。
config.cfg 文件是空的,即使在执行以下过程中的代码后也是如此。
执行train命令时出现错误信息
ℹ Using CPU
✘ Error parsing config overrides
paths -> train not a section value that can be overwritten
代码
$ python3 -m spacy train config.cfg --output ./output --paths.train train.spacy --paths.dev train.spacy
到目前为止的程序
$ python3 -m spacy init fill-config base_config.cfg config.cfg
#former output
configparser.DuplicateSectionError: While reading from '<string>' [line 90]: section 'paths' already exists
#current output
File "/usr/local/lib/python3.9/site-packages/spacy/util.py", line 137, in get
raise RegistryError(
catalogue.RegistryError: [E893] Could not find function 'spacy.MultiHashEmbed.v2' in function registry 'architectures'. If you're using a custom function, make sure the code is available. If the function is provided by a third-party package, e.g. spacy-transformers, make sure the package is installed in your environment.
Available names: spacy-legacy.MaxoutWindowEncoder.v1, spacy-legacy.MishWindowEncoder.v1, spacy-legacy.TextCatEnsemble.v1, spacy-legacy.Tok2Vec.v1, spacy-legacy.WandbLogger.v1, spacy.CharacterEmbed.v1, spacy.EntityLinker.v1, spacy.HashEmbedCNN.v1, spacy.MaxoutWindowEncoder.v2, spacy.MishWindowEncoder.v2, spacy.MultiHashEmbed.v1, spacy.PretrainCharacters.v1, spacy.PretrainVectors.v1, spacy.Tagger.v1, spacy.TextCatBOW.v1, spacy.TextCatCNN.v1, spacy.TextCatEnsemble.v2, spacy.TextCatLowData.v1, spacy.Tok2Vec.v2, spacy.Tok2VecListener.v1, spacy.TorchBiLSTMEncoder.v1, spacy.TransitionBasedParser.v1, spacy.TransitionBasedParser.v2
即使执行了上述代码,config.cfg 文件还是空的。
base_config.cfg 从 the official instruction
上的表格下载
# This is an auto-generated partial config. To use it with 'spacy train'
# you can run spacy init fill-config to auto-fill all default settings:
# python -m spacy init fill-config ./base_config.cfg ./config.cfg
[paths]
train = null
dev = null
[system]
gpu_allocator = null
[nlp]
lang = "en"
pipeline = ["tok2vec","ner"]
batch_size = 1000
[components]
[components.tok2vec]
factory = "tok2vec"
[components.tok2vec.model]
@architectures = "spacy.Tok2Vec.v2"
[components.tok2vec.model.embed]
@architectures = "spacy.MultiHashEmbed.v2"
width = ${components.tok2vec.model.encode.width}
attrs = ["ORTH", "SHAPE"]
rows = [5000, 2500]
include_static_vectors = false
[components.tok2vec.model.encode]
@architectures = "spacy.MaxoutWindowEncoder.v2"
width = 96
depth = 4
window_size = 1
maxout_pieces = 3
[components.ner]
factory = "ner"
[components.ner.model]
@architectures = "spacy.TransitionBasedParser.v2"
state_type = "ner"
extra_state_tokens = false
hidden_width = 64
maxout_pieces = 2
use_upper = true
nO = null
[components.ner.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
[corpora]
[corpora.train]
@readers = "spacy.Corpus.v1"
path = ${paths.train}
max_length = 0
[corpora.dev]
@readers = "spacy.Corpus.v1"
path = ${paths.dev}
max_length = 0
[training]
dev_corpus = "corpora.dev"
train_corpus = "corpora.train"
[training.optimizer]
@optimizers = "Adam.v1"
[training.batcher]
@batchers = "spacy.batch_by_words.v1"
discard_oversize = false
tolerance = 0.2
[training.batcher.size]
@schedules = "compounding.v1"
start = 100
stop = 1000
compound = 1.001
[initialize]
vectors = ${paths.vectors}
您似乎是双粘贴了配置之类的?从错误中您会注意到它说您有两个 [paths]
部分。大约在你的文件中途有这样的评论:
# This is an auto-generated partial config. To use it with 'spacy train'
尝试从那里删除所有内容,然后再做一次。
问题
在 the official instruction 之后,我正在尝试添加额外的训练数据集并在本地 cpu 环境中训练模型。
但我没有更改 base_config.cfg 和 config.cfg 文件的内容。
如何修复这些错误以构建模型并对其进行评估?
错误
我不确定第一个是否有问题,我也不知道要填写 config.cfg 文件。
config.cfg 文件是空的,即使在执行以下过程中的代码后也是如此。
执行train命令时出现错误信息
ℹ Using CPU
✘ Error parsing config overrides
paths -> train not a section value that can be overwritten
代码
$ python3 -m spacy train config.cfg --output ./output --paths.train train.spacy --paths.dev train.spacy
到目前为止的程序
$ python3 -m spacy init fill-config base_config.cfg config.cfg
#former output
configparser.DuplicateSectionError: While reading from '<string>' [line 90]: section 'paths' already exists
#current output
File "/usr/local/lib/python3.9/site-packages/spacy/util.py", line 137, in get
raise RegistryError(
catalogue.RegistryError: [E893] Could not find function 'spacy.MultiHashEmbed.v2' in function registry 'architectures'. If you're using a custom function, make sure the code is available. If the function is provided by a third-party package, e.g. spacy-transformers, make sure the package is installed in your environment.
Available names: spacy-legacy.MaxoutWindowEncoder.v1, spacy-legacy.MishWindowEncoder.v1, spacy-legacy.TextCatEnsemble.v1, spacy-legacy.Tok2Vec.v1, spacy-legacy.WandbLogger.v1, spacy.CharacterEmbed.v1, spacy.EntityLinker.v1, spacy.HashEmbedCNN.v1, spacy.MaxoutWindowEncoder.v2, spacy.MishWindowEncoder.v2, spacy.MultiHashEmbed.v1, spacy.PretrainCharacters.v1, spacy.PretrainVectors.v1, spacy.Tagger.v1, spacy.TextCatBOW.v1, spacy.TextCatCNN.v1, spacy.TextCatEnsemble.v2, spacy.TextCatLowData.v1, spacy.Tok2Vec.v2, spacy.Tok2VecListener.v1, spacy.TorchBiLSTMEncoder.v1, spacy.TransitionBasedParser.v1, spacy.TransitionBasedParser.v2
即使执行了上述代码,config.cfg 文件还是空的。
base_config.cfg 从 the official instruction
上的表格下载# This is an auto-generated partial config. To use it with 'spacy train'
# you can run spacy init fill-config to auto-fill all default settings:
# python -m spacy init fill-config ./base_config.cfg ./config.cfg
[paths]
train = null
dev = null
[system]
gpu_allocator = null
[nlp]
lang = "en"
pipeline = ["tok2vec","ner"]
batch_size = 1000
[components]
[components.tok2vec]
factory = "tok2vec"
[components.tok2vec.model]
@architectures = "spacy.Tok2Vec.v2"
[components.tok2vec.model.embed]
@architectures = "spacy.MultiHashEmbed.v2"
width = ${components.tok2vec.model.encode.width}
attrs = ["ORTH", "SHAPE"]
rows = [5000, 2500]
include_static_vectors = false
[components.tok2vec.model.encode]
@architectures = "spacy.MaxoutWindowEncoder.v2"
width = 96
depth = 4
window_size = 1
maxout_pieces = 3
[components.ner]
factory = "ner"
[components.ner.model]
@architectures = "spacy.TransitionBasedParser.v2"
state_type = "ner"
extra_state_tokens = false
hidden_width = 64
maxout_pieces = 2
use_upper = true
nO = null
[components.ner.model.tok2vec]
@architectures = "spacy.Tok2VecListener.v1"
width = ${components.tok2vec.model.encode.width}
[corpora]
[corpora.train]
@readers = "spacy.Corpus.v1"
path = ${paths.train}
max_length = 0
[corpora.dev]
@readers = "spacy.Corpus.v1"
path = ${paths.dev}
max_length = 0
[training]
dev_corpus = "corpora.dev"
train_corpus = "corpora.train"
[training.optimizer]
@optimizers = "Adam.v1"
[training.batcher]
@batchers = "spacy.batch_by_words.v1"
discard_oversize = false
tolerance = 0.2
[training.batcher.size]
@schedules = "compounding.v1"
start = 100
stop = 1000
compound = 1.001
[initialize]
vectors = ${paths.vectors}
您似乎是双粘贴了配置之类的?从错误中您会注意到它说您有两个 [paths]
部分。大约在你的文件中途有这样的评论:
# This is an auto-generated partial config. To use it with 'spacy train'
尝试从那里删除所有内容,然后再做一次。