urchade / GLiNER

Generalist and Lightweight Model for Named Entity Recognition (Extract any entity types from texts) @ NAACL 2024
https://arxiv.org/abs/2311.08526
Apache License 2.0
1.48k stars 127 forks source link

Return confidence in predict_entities #69

Closed SergheiDinu closed 5 months ago

SergheiDinu commented 7 months ago

Hi,

I see as possible to return confidence from 'predict' into 'predict_entities'. That way False Positive cases could be eliminated.

Best regards Dinu Serghei

urchade commented 7 months ago

Hi @SergheiDinu , I am not sure to understand. Could you please state it differently ?

SergheiDinu commented 7 months ago

Ah.. I mean to return confidence if it's possible.

vk-maurya commented 7 months ago

Hi @SergheiDinu ,

It is already in library you can use below code get scores.

from gliner import GLiNER
model = GLiNER.from_pretrained("urchade/gliner_medium")
model.eval()

text = """
Libretto by Marius Petipa, based on the 1822 novella ``Trilby, ou Le Lutin d'Argail`` by Charles Nodier, first presented by the Ballet of the Moscow Imperial Bolshoi Theatre on January 25/February 6 (Julian/Gregorian calendar dates), 1870, in Moscow with Polina Karpakova as Trilby and Ludiia Geiten as Miranda and restaged by Petipa for the Imperial Ballet at the Imperial Bolshoi Kamenny Theatre on January 17–29, 1871 in St. Petersburg with Adèle Grantzow as Trilby and Lev Ivanov as Count Leopold.
"""

labels = ["person", "book", "location", "date", "actor", "character"]

entities = model.predict_entities(text, labels, threshold=0.4)
# print(entities)
for entity in entities:
    print(entity["text"], "=>", entity["label"],"=>", entity["score"])  
wjbmattingly commented 6 months ago

I have added this into gliner spacy for v. 0.0.8