Je vais ajouter de nouvelles entités au propre modèle de données spacy "mymodel". Avant d'avoir installé "mymodel" en utilisant ce tutorial et ça marchait bien. Quand je veux utiliser "mymodel" pour ajouter de nouvelles entités, j'ai un malentendu. S'il vous plaît, aidez-moiPython Erreur Spacy: RuntimeError: Langue non prise en charge
Voici mon code:
import plac
from spacy.en import English
from spacy.gold import GoldParse
import spacy
nlp = spacy.load('mymodel')
def main(out_loc):
nlp = English(parser=False) # Avoid loading the parser, for quick load times
# Run the tokenizer and tagger (but not the entity recognizer)
doc = nlp.tokenizer(u'Lions and tigers and grizzly bears!')
nlp.tagger(doc)
nlp.entity.add_label('ANIMAL') # <-- New in v0.100
# Create a GoldParse object. This should have a better API...
indices = tuple(range(len(doc)))
words = [w.text for w in doc]
tags = [w.tag_ for w in doc]
heads = [0 for _ in doc]
deps = ['' for _ in doc]
# This is the only part we care about. We want BILOU format
ner = ['U-ANIMAL', 'O', 'U-ANIMAL', 'O', 'B-ANIMAL', 'L-ANIMAL', 'O']
# Create the GoldParse
annot = GoldParse(doc, (indices, words, tags, heads, deps, ner))
# Update the weights with the example
# Here we iterate until we get it entirely correct. In practice this is probably a bad idea.
# Note that we've added a class to the existing model here! We "resume"
# training the previous model. Whether this is good or not I can't say, you'll have to
# experiment.
loss = nlp.entity.train(doc, annot)
i = 0
while loss != 0 and i < 1000:
loss = nlp.entity.train(doc, annot)
i += 1
print("Used %d iterations" % i)
nlp.entity(doc)
for ent in doc.ents:
print(ent.text, ent.label_)
nlp.entity.model.dump(out_loc)
if __name__ == '__main__':
plac.call(main)
**Error of output:**
Traceback (most recent call last):
File "/home/vv/webapp/dic_model.py", line 7, in <module>
nlp = spacy.load('mymodel')
File "/usr/local/lib/python3.5/dist-packages/spacy/__init__.py", line 26, in load
lang_name = util.get_lang_class(name).lang
File "/usr/local/lib/python3.5/dist-packages/spacy/util.py", line 27, in get_lang_class
raise RuntimeError('Language not supported: %s' % name)
RuntimeError: Language not supported: mymodel
Je suis confronté au même problème et je serais heureux de recevoir des éclaircissements à ce sujet. Je suis ce script https://github.com/explosion/spaCy/blob/master/examples/training/train_ner.py et avec la méthode 'save_model', je crée un dossier' spaCy_NER' avec les fichiers 'config.json' et 'model', et un sous-dossier appelé' vocab'. J'ai essayé de fournir 'path/to/spaCy_NER/model' et' path/to/spaCy_NER/'comme premier argument de' python -m spacy link'. Mais je reçois le même RuntimeError dans les deux cas. Auriez-vous des suggestions? –