Multimodal Bilingual GLiNER (ES/EN): Healthcare & Privacy (PII) Entity Extraction
Fine-tuned GLiNER (Generalist and Lightweight Model for Named Entity Recognition) specialized in simultaneous zero-shot / few-shot extraction of Personally Identifiable Information (14 PII categories) and medical conditions / diagnoses (health condition) across both Spanish and English.
This model is structurally invariant: it operates with high accuracy across continuous conversational prose, pipe-delimited tables (|), MIME email headers (From/To/Subject/Date), and clinical EHR administrative admission forms.
🌟 Key Highlights
- Structural Invariance: Fine-tuned on diverse multimodal layouts (tables, emails, administrative files, clinical EHR headers, and conversational prose), reaching 99.1% $F_1$ on semi-structured & tabular data.
- Zero Catastrophic Forgetting: Maintains 89.4% Micro $F_1$ on continuous conversational prose (CAPID-ES test set).
- Native Healthcare & Medical Detection: Outperforms general privacy models (e.g., OpenMed v2), achieving 97.7% $F_1$ on health conditions and clinical symptoms, and 76.5% containment $F_1$ on complex biomedical pathologies in the official DisTEMIST benchmark.
- Hospital EHR Generalization (MEDDOCAN): Achieves 93.4% Recall on administrative headers and 83.3% Recall overall on real hospital discharge summaries from the PlanTL / BSC benchmark.
- Selective Mixed-Precision INT8 Support: Supports selective dynamic quantization of Attention and FFN MatMuls (72 linear layers) with 100.0% prediction parity and 0.0000 average score error compared to FP32, eliminating the logit collapse of full INT8.
- Canonical 1:1 Label Taxonomy: Uses 15 clean, mutually disjoint entity labels that prevent cross-encoder attention dilution and lexical competition between near-synonyms.
🏷️ Canonical 15-Entity Taxonomy
health condition— Diagnoses, diseases, symptoms, medical pathologies, disabilities.person name— Full names, first names, and surnames of individuals.age— Numerical ages and age groups.family relation— Kinship and family relationships (spouse, child, parent, sibling).organization— Hospitals, clinics, companies, institutions, universities.location— Addresses, cities, provinces, countries, geographic entities.date or time— Calendar dates, admission timestamps, schedules.identification code— National IDs (DNI, NIE, SSN), medical record numbers (NHC/MRN), emails, phone numbers.job title— Medical specialties, professions, job positions.financial amount— Monetary amounts, salaries, compensations, fees, pensions.academic qualification— University degrees, certificates, academic titles.demographic group— Nationality, ethnic origin, citizenship.physical appearance— Physical characteristics (eye color, height, weight).religious or political belief— Religious faiths, political affiliations.sexual orientation— Sexual orientation and gender identity.
📊 Comprehensive Test Set Evaluation (4,227 Ground Truth Entities)
Evaluated on the 400-document held-out multimodal test suite:
| Evaluation Subset | Docs | GT Entities | Precision | Recall | Micro $F_1$ | Macro $F_1$ |
|---|---|---|---|---|---|---|
| Semi-Structured & Tabular Held-Out | 200 | 3,073 | 99.12% | 99.22% | 99.17% | 99.24% |
| Conversational Continuous Prose (CAPID-ES) | 200 | 1,154 | 88.19% | 90.55% | 89.35% | 89.06% |
| TOTAL UNIFIED TEST BENCHMARK | 400 | 4,227 | 96.08% | 96.85% | 96.47% | 95.74% |
Breakdown by Data Layout Family
| Layout Family | Test Docs | GT Entities | Precision | Recall | $F_1$-Score |
|---|---|---|---|---|---|
| Administrative & Identity Dossiers | 40 | 640 | 99.84% | 99.69% | 99.77% |
| Referral & Consultation Orders | 40 | 520 | 99.62% | 99.81% | 99.71% |
| Clinical EHR Hospital Headers | 40 | 585 | 99.66% | 99.32% | 99.49% |
MIME Email Headers (De/Para/Fecha) | 40 | 560 | 98.93% | 99.29% | 99.11% |
Pipe-Delimited Tables (|) | 40 | 768 | 97.92% | 98.31% | 98.12% |
⚡ Selective Mixed-Precision INT8 / FP32 Quantization
Standard post-training quantization (PTQ) to INT8 collapses GLiNER's cross-encoder probabilities because quantizing the span boundary projectors (span_rep_layer) and prompt label embeddings (prompt_rep_layer) distorts the dot-product similarity matrix.
To solve this, this repository provides Selective Mixed-Precision Quantization:
- INT8 Dynamic Quantization: Applied strictly to the 72 Attention MatMul and FFN MatMul layers of the Transformer encoder (>85% of FLOPs).
- Pure FP32: Preserved for Span Extraction MLPs, Prompt Label Embeddings, Token Embeddings, and LayerNorms.
Empirical Validation on Multimodal Test Data
| Quantization Method | Quantized Layers | Entity Retention | Prediction Parity | Mean Score Error | F1 Impact |
|---|---|---|---|---|---|
| FP32 (Original) | 0 | 24 / 24 (100%) | 100.0% | 0.0000 | Baseline |
| Full INT8 (Naive PTQ) | All Linear Layers | 0 / 24 (0%) | 0.0% | Extreme | Logits Collapsed |
| Selective INT8 (Ours) | 72 Attention + FFN | 24 / 24 (100%) | 100.0% | 0.0000 | 0.0% Loss |
🚀 Quickstart Usage
Install gliner:
pip install gliner
Option A: Standard PyTorch Inference
from gliner import GLiNER
# 1. Load the model from Hugging Face
model = GLiNER.from_pretrained("angel-gitt/gliner-gbai")
# 2. Define the 15 canonical categories
labels = [
"health condition", "person name", "age", "family relation",
"organization", "location", "date or time", "identification code",
"job title", "financial amount", "academic qualification",
"demographic group", "physical appearance", "religious or political belief",
"sexual orientation"
]
# 3. Example: Pipe-delimited tabular record
tabular_text = (
"| ID Registro: 28-28-95185 | Paciente: Itziar Palacios Zabalza (44 años) "
"| Diagnóstico: dilatación de la vía urinaria | Médico: Dra. Carvajal Marín "
"| Hospital: Hospital Reina Sofía | Salario de Baja: 2.850 €/mes | Fecha: 14/05/2023 |"
)
entities = model.predict_entities(tabular_text, labels, threshold=0.25)
for ent in entities:
print(f"[{ent['label'].upper()}] {ent['text']} (confianza: {ent['score']:.1%})")
Option B: Fast CPU Inference with Selective INT8 Quantization
from gliner import GLiNER
from quantize_selective import apply_selective_quantization
# 1. Load model onto CPU
model = GLiNER.from_pretrained("angel-gitt/gliner-gbai", map_location="cpu")
# 2. Apply selective INT8 quantization (Attention + FFN MatMuls only)
model = apply_selective_quantization(model)
# 3. Predict with 100% mathematical fidelity and zero threshold degradation
entities = model.predict_entities(tabular_text, labels, threshold=0.25)
for ent in entities:
print(f"[{ent['label'].upper()}] {ent['text']} (confianza: {ent['score']:.1%})")
Option C: Blazing-Fast CPU Inference with ONNX Runtime (2.5x Speedup, 100% F1)
from gliner import GLiNER
# 1. Load the compiled ONNX model directly from Hugging Face
model = GLiNER.from_pretrained(
"angel-gitt/gliner-gbai",
load_onnx_model=True,
onnx_model_file="model.onnx"
)
# 2. Ultra-fast CPU inference (~54ms/doc, 100% parity with PyTorch FP32)
entities = model.predict_entities(tabular_text, labels, threshold=0.25)
for ent in entities:
print(f"[{ent['label'].upper()}] {ent['text']} (confianza: {ent['score']:.1%})")
📜 Citation & License
- License: Apache-2.0
- Architecture: GLiNER (mDeBERTa-v3-base backbone)
- Developed by: Hiili AI Research / Universidad Carlos III de Madrid