Я пытаюсь обучить модель en_core_web_sm
для добавления новой сущности EMAIL
, используя следующий код:
LABEL = "EMAIL"
TRAIN_DATA = [
(
"My email address is XXXX@gmail.com",
{"entities": [(20, 37, LABEL)]},
),
("you can email me @ XXXXX@ai.xXx.com?", {"entities": [(19, 36, LABEL)]}),
(
"contact me @ XXXX@ai.xXX.com",
{"entities": [(13, 31, LABEL)]},
),
("you can contact me at xxXX@xxXXX.com", {"entities": [(22, 56, LABEL)]})
]
def main(model="en_core_web_sm", new_model_name="en_core_web_sm", output_dir="D:/Train_ai", n_iter=8):
random.seed(0)
if model is not None:
nlp = spacy.load('en_core_web_sm')
print("Loaded model '%s'" % model)
else:
nlp = spacy.blank("en")
print("Created blank 'en' model")
if "ner" not in nlp.pipe_names:
ner = nlp.create_pipe("ner")
nlp.add_pipe(ner)
else:
ner = nlp.get_pipe("ner")
ner.add_label(LABEL)
ner.add_label("VEGETABLE")
if model is None:
optimizer = nlp.begin_training()
else:
optimizer = nlp.resume_training()
Я получаю ошибку:
AttributeError: «Английский» объект не имеет атрибута «resume_training» в строке optimizer = nlp.resume_training()