alexandrainst / danlp

DaNLP is a repository for Natural Language Processing resources for the Danish Language.
BSD 3-Clause "New" or "Revised" License
195 stars 33 forks source link

URLError when importing embedding functions #171

Open stinenyhus opened 1 year ago

stinenyhus commented 1 year ago

When I try to use the functions for loading the pretrained word embeddings as shown in documentation (https://github.com/alexandrainst/danlp/blob/master/docs/docs/tasks/embeddings.md), I get an empty URLError.

Specifically, I run

from danlp.models.embeddings import load_context_embeddings_with_flair
from flair.data import Sentence

# Use the wrapper from DaNLP to download and load embeddings with Flair
# You can combine it with the static embeddings
stacked_embeddings = load_context_embeddings_with_flair(word_embeddings='wiki.da.wv')

or

from danlp.models import load_bert_base_model
model = load_bert_base_model()

I get the following error for both versions: image

Environment

terne commented 1 year ago

Hi there, I had the same error. To anyone who might get stuck on this: You can find working links to the models you need in danlp/danlp/download.py. I found and downloaded bert for NER with this link: http://danlp-downloads.alexandra.dk/models/bert.ner.zip

Then, to get the bert NER model working, I took the BertNer class from danlp/danlp/models/bert_models.py (find other models in that folder) and substituted

weights_path = download_model('bert.ner', cache_dir,
                                      process_func=_unzip_process_func,
                                      verbose=verbose)

with

weights_path = "bert.ner" # path to downloaded model

When creating the model from this class, i.e. bert = BertNer(), the rest works as expected.

Hope that helps until the issue is fixed :)