Skip to main content

Quickstart

Install GLiFormer from PyPI, then load a checkpoint and provide the entity types you want to extract:

pip install gliformer

See Installation for requirements and optional dependencies.

Load a Model

import torch
from gliformer import GLiFormer

model = GLiFormer.from_pretrained(
"knowledgator/gliformer-base-v1",
load_tokenizer=True,
)
model = model.to("cuda" if torch.cuda.is_available() else "cpu").eval()

Replace the model ID with knowledgator/gliformer-large-v1 to use the large checkpoint, or with a local checkpoint directory. See Pretrained Models for their sizes and reported results.

Extract Entities

text = "Alice works at Acme in London."
entities = model.predict_entities(
text,
["person", "organization", "location"],
threshold=0.5,
)

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

Each entity contains text, label, start, end, and score. Offsets are character positions with an exclusive end: text[start:end] gives the extracted mention. Predictions depend on the checkpoint, labels, and threshold.

Run Multiple Tasks

The same checkpoint can extract entities, classify text, and build records in one call:

results = model.inference(
"Alice joined Acme as a software engineer.",
entities=["person", "organization"],
classes=["business", "sports", "technology"],
structures={"employee": ["name", "company"]},
threshold=0.5,
)

print(results["ner"][0])
print(results["classification"][0])
print(results["structuring"][0])

inference returns a dictionary keyed by task, with one result per input text under each key, even for a single string.

Next Steps

  • Usage: classification, joint relations, nested records, batching, and embeddings.
  • Pretrained Models: checkpoint details and evaluation results.
  • Training: adapt a checkpoint to your data.