GLiNER-2-XL

Fine-tuning the Open-Source GLiNER 2 Model

Customize GLiNER 2 on your own data to achieve domain-specific performance for entity extraction, classification, or structured parsing.

Requirements

  • Python ≥ 3.8

  • torch, transformers, datasets, accelerate

  • A GPU (optional but recommended for training)

Loading a Base Model

from gliner2 import GLiNER2

model = GLiNER2.from_pretrained("fastino/gliner2-base-0207")

Preparing Training Data

Each sample requires:

{
  "text": "Apple CEO Tim Cook announced iPhone 15.",
  "entities": {"company": ["Apple"], "person": ["Tim Cook"], "product": ["iPhone 15"]}
}

For classification tasks:

{"text": "The camera quality is excellent.", "labels": {"sentiment": "positive"}}

Fine-tuning Script

from datasets import load_dataset
from gliner2 import GLiNER2Trainer

train_ds = load_dataset("json", data_files="train.json")["train"]
eval_ds  = load_dataset("json", data_files="eval.json")["train"]

trainer = GLiNER2Trainer(
    model_name="fastino/gliner2-base-0207",
    output_dir="./gliner2-finetuned",
    train_dataset=train_ds,
    eval_dataset=eval_ds,
    learning_rate=5e-5,
    batch_size=8,
    num_epochs=3
)

trainer.train()
trainer.save_model()

Evaluation

metrics = trainer.evaluate()
print(metrics)
# {"precision": 0.91, "recall": 0.88, "f1": 0.895}

Export & Deployment

Upload to Hugging Face Hub or serve locally for inference.


Use your fine-tuned checkpoint with Fastino’s /gliner2 endpoint:

{"model": "fastino/gliner2-finance", "task": "extract_entities", ...}

Tips for Domain Adaptation

  • Use domain-specific schemas (e.g., financial_instrument, regulation, issuer).

  • Include negative examples to reduce false positives.

  • Apply progressive unfreezing for smaller datasets.

  • Evaluate on entity-level F1 and schema-completeness metrics.

Citation

If you use GLiNER 2 for research or commercial projects, please cite:

@misc{zaratiana2025gliner2efficientmultitaskinformation,
  title={GLiNER2: An Efficient Multi-Task Information Extraction System with Schema-Driven Interface},
  author={Urchade Zaratiana and Gil Pasternak and Oliver Boyd and George Hurn-Maloney and Ash Lewis},
  year={2025},
  archivePrefix={arXiv},
  eprint={2507.18546},
  primaryClass={cs.CL},
  url={https://arxiv.org/abs/2507.18546}
}

Summary
Fine-tune GLiNER 2 on your own datasets to build domain-optimized extractors and classifiers.
Deploy your custom model through Fastino’s /gliner2 endpoint for low-latency, personalized inference at scale.

On this page