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

Integrate Flair models #9

Closed
julien-c opened this issue Feb 18, 2021 · 3 comments
Closed

Integrate Flair models #9

julien-c opened this issue Feb 18, 2021 · 3 comments

Comments

@julien-c
Copy link
Member

either here or directly in our private repo api-inference

@stefan-it
Copy link
Collaborator

stefan-it commented Feb 18, 2021

Really cool! I have actually worked on a small prototype that mimics the output of the current token classification models:

from flair.data import Sentence
from flair.models import SequenceTagger

tagger: SequenceTagger = SequenceTagger.load("dbmdz/flair-historic-ner-onb")

sentence: Sentence = Sentence(input_text)

# Also show scores for recognized NEs
tagger.predict(sentence, all_tag_prob=True, label_name="predicted")

response = []

entities = []

for span in sentence.get_spans("predicted"):
    idx = [token.idx for token in span.tokens]

    current_entity = {
        "entity_group": span.tag,
        "word": span.to_original_text(),
        "start": idx[0] - 1, # Because Flair starts at 1
        "end": idx[-1],
        "score": span.score
    }

    entities.append(current_entity)


response = {
    "entities": entities
}

return jsonify(response)

Bookmark for token classification API: https://api-inference.huggingface.co/docs/python/html/detailed_parameters.html#named-entity-recognition-ner-task

@julien-c
Copy link
Member Author

Thanks! Yeah it looks pretty easy!

We'll discuss internally to figure out if we would implement this here or directly in our api-inference repo (which hosts the transformers model inference)

@julien-c
Copy link
Member Author

was implemented in our api-inference repo (@Narsil @n1t0) so closing this here

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