knowledgator/gliformer-large-v1
- License
- apache-2.0
- Size
- 2.2 GB
- Revision
- main
Mirrored from knowledgator/gliformer-large-v1
All models by knowledgator →Mirrored from knowledgator/gliformer-large-v1
All models by knowledgator →One encoder for PDF layout processing, entity recognition, classification, relation extraction, structured records, and text embeddings.
[Image blocked: GLiFormer supported tasks]
knowledgator/gliformer-large-v1 is the 575.6M-parameter large release of
GLiFormer. It accepts task labels and
extraction schemas at inference time, with task heads sharing a DeBERTa encoder.
The layout-aware architecture supports text and document-layout inputs; the usage
examples and quality results below focus on text tasks.
Or install the GLiFormer framework in a Python 3.10+ environment from the source:
Optional CUDA attention kernels are available with pip install -e ".[flash]".
CPU inference uses eager attention. The following examples reuse model:
For a local copy, replace the model ID with the checkpoint directory.
Specify the entity types at inference time:
Each entity includes text, label, start, end, and score.
Offsets are character positions with an exclusive end.
Pass a list of texts and batch_size=8 for batched extraction.
Named groups are also supported, for example
{"sentiment": ["positive", "negative"], "topic": ["product", "support"]}.
Supply entity and relation labels together to use this checkpoint's joint relation head:
inference returns a dictionary of task outputs, each containing one result per input text.
The separate predict_relations convenience method requires an open relation head;
use joint_relations for this model.
Extract records directly into a Python dictionary:
Nested Pydantic schemas support multilevel records:
The decoder assembles source-grounded fields and parent–child relationships into nested records. Predictions depend on the schema, input, and thresholds; Pydantic validation checks the output schema, not factual correctness.
Dataset means weight datasets equally. NER requires both the entity span and type to match. Classification macro-F1 averages class F1 scores within each dataset. Structuring compares flattened JSON value paths after aligning records without requiring their original order and allowing the evaluator's limited boundary repairs; it is not exact JSON match. The manuscript corrects the structuring evaluation size to 500; historical notes contain obsolete bucket counts totaling 300.
Micro-F1 equals accuracy in these single-label runs. Reported prediction coverage is 97.15% for 20 Newsgroups and 100% for the other datasets. Summary scores retain the original reports' precision; means of the rounded rows can differ by 0.01.
These runs use predicted entities. Gold counts are relation instances, not documents. Base and large were evaluated on different-sized subsets, so their relation scores are not a controlled comparison on identical examples.
CoNLL04 zero-shot typed F1, which also checks endpoint entity types, is 34.73%.
You can find more information on the evaluation methodology here: https://www.knowledgator.com/research
Evaluation entry points are in
gliformer_eval.
For example, after preparing the CrossNER files, run from the framework repository:
Each dataset directory must contain labels.json and test.json. The other task
entry points are eval_classification.py, eval_relex.py, and eval_structuring.py;
use --help for data paths and inference settings. Reproduction requires matching
the original data subsets, schema labels, thresholds, and decoding settings.
The checkpoint uses the backbone listed above with supervised task heads for information extraction, classification, structuring, and embeddings. See the manuscript for the documented multitask training mixtures. Full checkpoint-specific training provenance is not recorded in the saved evaluation reports.
Use this model for extracting labeled mentions, candidate classes, relations, and structured records from text, and for producing text similarity vectors. The available results cover English tasks. Quality on other languages, document-layout inputs, and embedding benchmarks is not established by the tables above.
pip install gliformer -Ugit clone https://github.com/Knowledgator/GLiFormer.gitcd GLiFormerpip install -e .import torchfrom gliformer import GLiFormer
model = GLiFormer.from_pretrained( "knowledgator/gliformer-large-v1", load_tokenizer=True,)model = model.to("cuda" if torch.cuda.is_available() else "cpu").eval()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"])predictions = model.classify( "The new search feature is fast and easy to use.", ["positive", "negative", "neutral"], threshold=0.5,)print(predictions) # Label dictionaries containing class_name and score.results = model.inference( "Alice works at Acme.", joint_relations={ "employment": { "entities": ["person", "organization"], "relations": ["works_at"], } }, threshold=0.5,)for relation in results["joint_relex"][0]: print(relation["head"]["text"], relation["relation"], relation["tail"]["text"])records = model.structure( "Alice works at Acme.", {"employee": ["name", "company"]},)print(records)# {'employee': [{'name': 'Alice', 'company': 'Acme'}]}from pydantic import BaseModel
class Employee(BaseModel): name: str role: str
class Department(BaseModel): name: str employees: list[Employee]
class Company(BaseModel): name: str departments: list[Department]
records = model.structure( "At Acme, Engineering includes Alice, a software engineer, and Bob, " "a designer. Sales includes Carol, an account manager.", {"company": Company}, validate_output=True,)print(records)results = model.inference( "Alice joined Acme as a software engineer.", entities=["person", "organization"], classes=["business", "sports", "technology"], structures={"employee": ["name", "company"]},)print(results["ner"][0])print(results["classification"][0])print(results["structuring"][0])import torch.nn.functional as F
embeddings = model.embed_text([ "A scientist works in a laboratory.", "A researcher conducts an experiment.",])print(embeddings.shape) # torch.Size([2, 1024])print(F.cosine_similarity(embeddings[0:1], embeddings[1:2]).item())python gliformer_eval/eval_ner.py \ --model knowledgator/gliformer-large-v1 \ --data data/NER \ --datasets CrossNER_AI CrossNER_literature CrossNER_music CrossNER_politics CrossNER_science \ --output eval_results/gliformer_large_v1_ner.json