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

models: add support for Hugging Face model hub #1974

Merged
merged 3 commits into from
Nov 25, 2020

Conversation

stefan-it
Copy link
Member

Hi,

this PR allows to use trained sequence tagging from the Hugging Face model hub 🤗

It is only needed to specify the namespace, like stefan-it/flair-ner-conll03 and a model will be downloaded (incl. caching) that can be used in Flair!

Naming convention is, that the model file on the model hub is named model.bin.

The following code snippet shows how to use this new feature:

from flair.data import Sentence
from flair.models import SequenceTagger
tagger: SequenceTagger = SequenceTagger.load("stefan-it/flair-ner-conll03")

It is also possible to pass a specific commit or branch name via @-syntax: stefan-it/flair-ner-conll03@main.

On the Hugging Face model hub itself, it is also possible to add a README file, that gives more details about a trained model:

https://huggingface.co/stefan-it/flair-ner-conll03

Many thanks to the Hugging Face team for the awesome model hub ❤️

@stefan-it stefan-it requested a review from alanakbik November 19, 2020 14:28
@stefan-it
Copy link
Member Author

As discussed with @alanakbik , I changed the cache dir (from huggingface cache dir) to the flair one 🤗

In [2]: tagger: SequenceTagger = SequenceTagger.load("stefan-it/flair-ner-conll03")                                                           
Downloading: 100%|█████████████████████████████████████████████████████████████████████████████████████████| 432M/432M [00:39<00:00, 11.1MB/s]
2020-11-23 12:49:20,577 loading file /home/stefan/.flair/36e1432823a81d0a0e298b5847412de75d780104bc5e2edb2ddd61b63b8f7436.941c7c30b38aef8d8a4eb5c1b6dd7fe8583ff723fef457382589ad6a4e859cfc

In [3]: tagger: SequenceTagger = SequenceTagger.load("stefan-it/flair-ner-conll03")                                                           
2020-11-23 12:49:26,667 loading file /home/stefan/.flair/36e1432823a81d0a0e298b5847412de75d780104bc5e2edb2ddd61b63b8f7436.941c7c30b38aef8d8a4eb5c1b6dd7fe8583ff723fef457382589ad6a4e859cfc

Copy link
Collaborator

@alanakbik alanakbik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you also pin the transformers version between 3.5.0 and 3.5.1 so that this always works?

@alanakbik alanakbik merged commit 183f9b4 into master Nov 25, 2020
@alanakbik alanakbik deleted the add-hf-model-hub-support branch April 22, 2021 13:57
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

Successfully merging this pull request may close these issues.

2 participants