-
Notifications
You must be signed in to change notification settings - Fork 57
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
Comments
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 |
Thanks! Yeah it looks pretty easy! We'll discuss internally to figure out if we would implement this here or directly in our |
either here or directly in our private repo
api-inference
The text was updated successfully, but these errors were encountered: