gpt4 book ai didi

python-3.6 - 应用简单训练模型时未命名向量上的 Spacy 错误

转载 作者:行者123 更新时间:2023-12-02 00:06:07 25 4
gpt4 key购买 nike

我正在使用 spacy 示例 NER 代码进行测试。这是直接从spacy网站复制的https://spacy.io/usage/training 。我只是自己添加 import spacy 和 random

import spacy
import random

TRAIN_DATA = [
("Uber blew through $1 million a week", {'entities': [(0, 4, 'ORG')]}),
("Google rebrands its business apps", {'entities': [(0, 6, "ORG")]})]

nlp = spacy.blank('en')
optimizer = nlp.begin_training()
for i in range(20):
random.shuffle(TRAIN_DATA)
for text, annotations in TRAIN_DATA:
nlp.update([text], [annotations], sgd=optimizer)
nlp.to_disk('/model')

但是,当我运行代码时。它显示错误。

Warning: Unnamed vectors -- this won't allow multiple vectors models to be loaded. (Shape: (0, 0))

我在社区中搜索过,但没有任何线索。谢谢您的帮助

最佳答案

在优化器之前放置nlp.vocab.vectors.name = 'spacy_pretrained_vectors'就足够了

import spacy
import random

TRAIN_DATA = [
("Uber blew through $1 million a week", {'entities': [(0, 4, 'ORG')]}),
("Google rebrands its business apps", {'entities': [(0, 6, "ORG")]})]

nlp = spacy.blank('en')
nlp.vocab.vectors.name = 'spacy_pretrained_vectors'
optimizer = nlp.begin_training()
for i in range(20):
random.shuffle(TRAIN_DATA)
for text, annotations in TRAIN_DATA:
nlp.update([text], [annotations], sgd=optimizer)
nlp.to_disk('/model')

关于python-3.6 - 应用简单训练模型时未命名向量上的 Spacy 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52215109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com