ZeroShot NER with GliNER

GliNER is not perfect, but it is a dead simple way to get started with NER. Just give it some label names and go.

# /// script
# dependencies = [
#   "gliner==0.2.10"
# ]
# ///

from gliner import GLiNER

model = GLiNER.from_pretrained("urchade/gliner_small-v2.1")

text = """Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, 
has recently published a paper in the prestigious journal "Nature Neuroscience". 
His research focuses on a rare genetic mutation, found in less than 0.01% of 
the population, that appears to prevent the development of Alzheimer's disease. 
Collaborating with researchers at the University of California, San Francisco, 
the team is now working to understand the mechanism by which this mutation confers 
its protective effect. Funded by the National Institutes of Health, their research 
could potentially open new avenues for Alzheimer's treatment."""

labels = ["person", "date"]
entities = model.predict_entities(text, labels)

for entity in entities:
    print(entity["text"], "=>", entity["label"])

What is pretty cool here is that labels can also be made more elaborate. So they do not need to be single words.