---
title: 'GLiNER2: Unified CPU-Efficient IE System'
url: https://www.emergentmind.com/topics/gliner2
type: topic
---

# GLiNER2: Unified CPU-Efficient IE System

GLiNER2 is a unified, CPU-efficient information extraction (IE) system designed to perform named entity recognition (NER), text classification, and arbitrary hierarchical structured data extraction within a single, compact model. Building upon the original GLiNER encoder–prompting paradigm, GLiNER2 broadens the scope of schema-driven, zero-shot IE while maintaining high throughput and minimal hardware requirements. The system exposes a declarative, JSON-style interface that allows joint specification of extraction and classification tasks, executed in a single forward pass [2507.18546].

## 1. Architecture and Pretraining

GLiNER2 is implemented as a bidirectional Transformer encoder adopting a “base-plus” configuration: 12 layers, 768 hidden dimensions, 12 attention heads, 2,048 token context, and approximately 205 million parameters. Model initialization leverages a general-purpose pretrained encoder in the style of DeBERTa-v3-base, with key vocabulary extensions for four purpose-specific token types: [P] (prompt), [E] (entity), [C] (child/field), and [L] (label). All special token embeddings are randomly initialized and updated jointly with task-specific layers.

The sole pretraining objective is masked language modeling (MLM):

$$
L_{MLM} =  - \mathbb{E}_{x}\left[ \sum_{i\in M} \log P(x_i \mid x_{\setminus i}) \right]
$$

No task-specific or domain-adaptive pretraining is introduced beyond MLM. This design preserves generality and compatibility with the schema-driven prompting framework [2507.18546].

## 2. Unified Prompting and Multi-Task Schema Interface

All GLiNER2 tasks utilize a shared “prompt ⊕ text” interface. The prompt encodes schema and task specifications, while text is the sequence to be processed. Prompt variants for the primary tasks are as follows:

- **Named Entity Recognition:**  
  `[P] entities ( [E] e₁ [E] e₂ … [E] e_n ) [SEP] text`  
  Each [E] token encodes an entity type $e_j$, with span representations $h_{s_i}$ computed for candidate spans $s_i$. Scoring is via
  $$
  \text{score}(s_i, e_j) = \sigma( h_{s_i} \cdot h_{e_j} )
  $$
  Candidate spans with scores above 0.5 are predicted as entities.

- **Hierarchical Structured Data Extraction:**  
  `[P] parent ( [C] a₁ [C] a₂ … [C] a_m ) [SEP] text`  
  [P] token is processed with a small MLP to predict the instance count $K$ (as a classification over integers 0–19). Each field [C] $a_k$ and each occurrence $k=1...K$ receive a distinct embedding by combining the field and occurrence embeddings. Attribute extraction proceeds as in NER with dot-product/sigmoid matching.

- **Text Classification:**  
  `[P] task ( [L] ℓ₁ [L] ℓ₂ … [L] ℓ_k ) [SEP] text`  
  [L] tokens specify candidate labels $\ell_i$, whose embeddings $h_{\ell_i}$ are transformed via an MLP to produce logits ($\text{logit}_i = \text{MLP}(h_{\ell_i})$). Softmax over logits applies for single-label, and independent sigmoid for multi-label settings.

- **Task Composition:**  
  Multiple prompts can be concatenated: `[Prompt₁] ⊕ [SEP] ⊕ [Prompt₂] ⊕ … [SEP] ⊕ text`, enabling simultaneous multi-task execution within a single run.

## 3. Training Protocol

GLiNER2 is trained on a composite dataset:

- **Real-world:** 135,698 text samples from newswire, Wikipedia, legal documents, PubMed, and arXiv.
- **Synthetic:** 118,636 GPT-4o-generated examples targeting business and personal domains.
- **Aggregate:** 254,334 annotated examples, with GPT-4o assisting all annotations (NER, hierarchical fields, and classification).

Optimization targets the combined loss:
$$
L_\text{total} = L_\text{NER} + L_\text{struct} + L_\text{cls}
$$

- $L_\text{NER}$: Binary cross-entropy over all span–type scores.
- $L_\text{struct}$: Sum of cross-entropy for instance counting (20-way) and binary cross-entropy for each field’s span–field score.
- $L_\text{cls}$: Multi-class cross-entropy for single-label tasks (over softmax outputs); binary cross-entropy for multi-label tasks (over sigmoid outputs).

Key hyperparameters include 5 epochs, AdamW optimizer, encoder LR $1\times10^{-5}$, task head LR $2\times10^{-5}$, weight decay 0.01, 1,000 warmup steps, and gradient clipping at 1.0 [2507.18546].

## 4. Evaluation and Performance

GLiNER2 exhibits competitive zero-shot performance in both classification and NER tasks, while maintaining low inference latency on standard CPUs. Table summaries:

### Zero-Shot Text Classification Accuracy

| Dataset         | GPT-4o | GLiClass | DeBERTa-v3 | GLiNER2 |
|-----------------|--------|----------|------------|---------|
| SNIPS           | 0.97   | 0.80     | 0.77       | 0.83    |
| Banking77       | 0.78   | 0.21     | 0.42       | 0.70    |
| Amazon Intent   | 0.72   | 0.51     | 0.59       | 0.53    |
| SST-2           | 0.94   | 0.90     | 0.92       | 0.86    |
| IMDB            | 0.95   | 0.92     | 0.89       | 0.87    |
| AG News         | 0.85   | 0.68     | 0.68       | 0.74    |
| 20 Newsgroups   | 0.68   | 0.36     | 0.54       | 0.49    |
| **Average**     | 0.84   | 0.63     | 0.69       | 0.72    |

### CrossNER Zero-Shot F1 (NER)

| Domain     | GPT-4o | GLiNER-M | GLiNER2 |
|------------|--------|----------|---------|
| AI         | 0.547  | 0.518    | 0.526   |
| Literature | 0.561  | 0.597    | 0.564   |
| Music      | 0.736  | 0.694    | 0.632   |
| Politics   | 0.632  | 0.686    | 0.679   |
| Science    | 0.518  | 0.581    | 0.547   |
| **Avg**    | 0.599  | 0.615    | 0.590   |

### CPU-based Inference Latency (ms)

| # Labels | GPT-4o | DeBERTa | GLiClass | GLiNER2 |
|----------|--------|---------|----------|---------|
| 5        | 358    | 1714    | 137      | 130     |
| 10       | 382    | 3404    | 131      | 132     |
| 20       | 425    | 6758    | 140      | 163     |
| 50       | 463    | 16897   | 190      | 208     |
| **Speedup** | 1.00× | 0.10×  | 2.75×    | 2.62×   |

These results demonstrate that GLiNER2 matches or exceeds open-source baselines across tasks, operating below 200 ms inference latency on commodity CPUs for up to 50 labels.

## 5. Deployment, API, and Practical Use

GLiNER2 is distributed via pip (`pip install gliner2`) and integrates with Hugging Face Transformers. The software exposes a simple API with support for entity, classification, and hierarchical schema extraction. Usage consists of importing and loading a pretrained model, then submitting extraction calls with JSON-style schemas.

Example schema usages:
- **NER:** `{"entities": ["PERSON","LOCATION"]}`
- **Hierarchical Extraction:** 
  ```python
  {"product": {"fields": {"name::str::Product name": {}, "price::str::Product price": {}}}}
  ```
- **Classification:** `{"sentiment": ["positive", "negative", "neutral"]}`
- **Mixed Tasks:** 
  ```python
  {
      "entities":["ORGANIZATION"],
      "sentiment":["positive","negative"],
      "invoice":{ "fields":{ "total::str::Total amount":{} } }
  }
  ```

All extractions within the schema are performed in a single, real-time (≈150 ms) forward pass on CPU. Hardware requirements are minimal, supporting on-premise and privacy-preserving deployments [2507.18546].

## 6. Limitations and Future Directions

- Absence of established zero-shot benchmarks for hierarchical structured extraction; thus, generalization in the wild remains unevaluated for this task type.
- The current instance count prediction is limited to 19 (via 20-way classification), posing constraints for very large or deeply nested schemas ($K \gg 20$, $m \gg 10$).
- Domain transfer to highly specialized text types (for example, legal-to-medical) likely requires further adapter-style fine-tuning.
- Future research avenues include formalizing structured extraction benchmarks, extending count prediction beyond 19, and incorporating relation- and table-extraction under the schema-driven paradigm.

## 7. Context and Assessment

GLiNER2 unifies multiple IE paradigms—zero-shot NER, flexible classification, and unconstrained hierarchical schema extraction—within a single, efficient, 205 M-parameter encoder. The schema-driven prompting and minimal CPU requirements lower the barrier to deployment in resource-constrained settings. Zero-shot flexibility is retained from GLiNER, and only minimal performance degradation (~1–2 F1 points in NER) is observed relative to dedicated models, even as additional task capabilities are integrated. GLiNER2 represents an advancement in schema-driven IE, enabling joint, interpretable extraction and labeling routines from natural text via an efficient, extensible library [2507.18546].

Source: https://www.emergentmind.com/topics/gliner2