TakeLab / spacy-udpipe

spaCy + UDPipe
MIT License
159 stars 11 forks source link

Load a pre-trained local udpipe of unsupported language #9

Closed betimd closed 4 years ago

betimd commented 4 years ago

I want to load a local pretrained udpipe model with code like below:

import spacy_udpipe

udpipe_model = spacy_udpipe.UDPipeModel("sq")
nlp = spacy.load("./models_sq", udpipe_model=udpipe_model)

text = "Wikipedia është një uebsite i mirë."

doc = nlp(text)
for token in doc:
    print(token.text, token.lemma_, token.pos_, token.dep_)

but I get Exception: 'sq' language not available

Is it possible to give me direction how to add Albanian language support (or at least skip the exception) and load local udpipe model?

Thank you for your contribution!

asajatovic commented 4 years ago

It should already be possible - please check out #1 and #2 :)

betimd commented 4 years ago

Thanks for a prompt reply.

Is the code above correct or you suggest to load in any other way?

asajatovic commented 4 years ago

Based on the snippet you provided, the following should work:

import spacy_udpipe

nlp = spacy_udpipe.load_from_path(lang="sq",
                                  path="./models_sq",
                                  meta={"description": "Custom sq model"})

text = "Wikipedia është një uebsite i mirë."
doc = nlp(text)
for token in doc:
    print(token.text, token.lemma_, token.pos_, token.dep_)

meta arg is optional info about the model, if not provided, see what it defaults to here.

asajatovic commented 4 years ago

Closing this issue as code snippet 'solution' is added in README.md in #12.