def train_ner(nlp, train_data, output_dir):
// Add new words to vocabfor raw_text, _ in train_data:
doc = nlp.make_doc(raw_text)for word in doc:
_ = nlp.vocab[word.orth]
random.seed(0)
// You may need to change the learning rate. It"s generally difficult to// guess what rate you should set, especially when you have limited data.
nlp.entity.model.learn_rate = 0.001for itn in range(1000):
random.shuffle(train_data)
loss = 0.
for raw_text, entity_offsets in train_data:
gold = GoldParse(doc, entities=entity_offsets)// By default, the GoldParse class assumes that the entities// described by offset are complete, and all other words should// have the tag "O". You can tell it to make no assumptions// about the tag of a word by giving it the tag "-".
After Change
def train_ner(nlp, train_data, output_dir):
random.seed(0)
optimizer = nlp.begin_training(lambda: [])
nlp.meta["name"] = "en_ent_animal"for itn in range(50):
losses = {}
for batch in minibatch(get_gold_parses(nlp.make_doc, train_data), size=3):