# GLiNER

> Zero-shot named-entity recognition for any entity type, small enough to run on a CPU

- Category: Evaluation & Production Ops / Guardrails & Security
- Language: Python
- Repository: https://github.com/urchade/GLiNER
- Website: https://urchade.github.io/GLiNER
- Canonical page: https://ai-tldr.dev/tools/gliner/

## In short

GLiNER is a framework for training and running small Named Entity Recognition (NER) models that work zero-shot. It sits in the Guardrails & Security category of the Evaluation & Production Ops tools and is open-source, written in Python. To get started: install GLiNER.

## Overview

GLiNER is a framework for training and running small Named Entity Recognition (NER) models that work zero-shot. Instead of being locked to a fixed label set, you pass the entity types you want at inference time (for example "person", "award", "date"), and the model extracts matching spans from the text. It also supports joint entity and relation extraction.

It is built for teams that need entity extraction without the cost of a large language model. The models are tuned to run on CPUs and consumer hardware, and the project reports performance competitive with much larger models like ChatGPT and UniNER. Models can also be fine-tuned on your own data.

In a guardrails and PII context, GLiNER is widely used as a detection backend: you can define sensitive entity types (names, emails, locations) as labels and flag them in user or model text. It is, for instance, used inside Microsoft Presidio for PII detection.

## What it does

- Zero-shot NER: name any entity types at runtime, no retraining needed
- Lightweight, CPU-friendly models suited to consumer hardware
- Supports joint entity and relation extraction beyond plain NER
- Fine-tunable on your own labeled data
- Pretrained models distributed via Hugging Face (e.g. urchade/gliner_medium-v2.1)
- Optional Ray Serve deployment with dynamic batching and multi-replica scaling

## Getting started

Install the package, load a pretrained model, and pass your own entity labels to predict_entities.

1. Install GLiNER

   Install from PyPI with pip (or uv for a faster install).

```bash
pip install gliner
```

2. Load a model and extract entities

   Load a pretrained model with GLiNER.from_pretrained, then call predict_entities with your text and a list of labels.

```python
from gliner import GLiNER

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

text = "Cristiano Ronaldo was born on 5 February 1985 and plays for Al Nassr."

# Define the entity types you want to find
labels = ["Person", "Date", "Teams"]

entities = model.predict_entities(text, labels, threshold=0.5)

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

3. Serve it (optional)

   For production deployment with dynamic batching and multi-replica scaling, install the serving extra, which adds Ray Serve support.

```bash
pip install gliner[serve]
```

## When to use it

- Detect and flag PII (names, emails, locations) in user input or model output as a guardrails backend
- Extract domain-specific entities from documents without labeling data for a fixed schema
- Run NER on CPU or consumer hardware where a large LLM is too costly
- Fine-tune a small NER model on your own entity types for an in-house pipeline
