应用简单训练模型时未命名向量的空间错误

Pla*_*nor 2 spacy python-3.6

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

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')
Run Code Online (Sandbox Code Playgroud)

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

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

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

Pla*_*nor 7

放在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')
Run Code Online (Sandbox Code Playgroud)