Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_path - allow to load from disk instead #1

Closed
jwijffels opened this issue Aug 8, 2019 · 4 comments
Closed

get_path - allow to load from disk instead #1

jwijffels opened this issue Aug 8, 2019 · 4 comments

Comments

@jwijffels
Copy link

Would it be possible to allow the language to be the path to the file on disk? Currently this https://github.com/TakeLab/spacy-udpipe/blob/master/spacy_udpipe/language.py#L195 only allows to set a language specified in that json
I have some home-brew udpipe models (e.g. some of them are here: https://github.com/bnosac/udpipe.models.ud, which I basically use alongside the R wrapper of udpipe https://github.com/bnosac/udpipe) and it would be nice to allow them to be read from the location of the file on disk instead.

@asajatovic
Copy link
Collaborator

A quick-and-dirty way of doing it would be to first load the supported model for the same language (e.g. for English):

nlp = spacy_udpipe.load('en')

and then (re)load the custom underlying UDPipe model from the disk path:

from ufal.udpipe import Model

my_model = Model.load(path)
if my_model:
    nlp.udpipe.model = my_model

@jwijffels
Copy link
Author

That's a bit silly :). 2 times loading that .udpipe file. Can't we just do

    def __init__(self, lang, path=None):
        """Load UDPipe model for given language.
        lang (unicode): ISO 639-1 language code or shorthand UDPipe model name.
        RETURNS (UDPipeModel): Language specific UDPipeModel.
        """
        if path is not None:
            path = get_path(lang)

        self.model = Model.load(path)

@asajatovic
Copy link
Collaborator

I added that option in the pull request #2, along with a convenience function load_from_path.
It is also available in a new release on PyPI.

@jwijffels
Copy link
Author

Great! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants