Instructions to use talmago/gliformer-base-v1-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiFormer
How to use talmago/gliformer-base-v1-onnx with GLiFormer:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- GLiNER
How to use talmago/gliformer-base-v1-onnx with GLiNER:
from gliner import GLiNER model = GLiNER.from_pretrained("talmago/gliformer-base-v1-onnx") text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal." labels = ["person", "date", "location"] entities = model.predict_entities(text, labels) for entity in entities: print(entity["text"], "=>", entity["label"]) - Notebooks
- Google Colab
- Kaggle
GLiFormer Base v1 ONNX
ONNX weights for knowledgator/gliformer-base-v1, for use with fast_gliner. This repository does not include the PyTorch checkpoint.
FastGLiFormer exposes the same methods as FastGLiNER2. Relations come from the joint head, and structures are flat records.
from fast_gliner import FastGLiFormer
model = FastGLiFormer.from_pretrained("talmago/gliformer-base-v1-onnx")
Named entity recognition
model.predict_entities(
"Marie Curie worked at the University of Paris in France.",
["person", "organization", "location"],
)
[
{"text": "Marie Curie", "label": "person", "score": 0.999533, "start": 0, "end": 11},
{"text": "University of Paris", "label": "organization", "score": 0.999588, "start": 26, "end": 45},
{"text": "France", "label": "location", "score": 0.999018, "start": 49, "end": 55},
]
Text classification
classify returns every label score, highest first.
model.classify(
"The new search feature is fast and easy to use.",
["positive", "negative", "neutral"],
)
[
("positive", 1.0),
("neutral", 0.0),
("negative", 0.0),
]
Relation extraction
Pass entity labels together with the relation schema. Endpoint labels constrain which pairs are kept.
model.extract_relations(
"Alice works at Acme and lives in London.",
["person", "organization", "location"],
[
{
"relation": "works_at",
"subject_labels": ["person"],
"object_labels": ["organization"],
},
{
"relation": "lives_in",
"subject_labels": ["person"],
"object_labels": ["location"],
},
],
)
Alice => works_at => Acme
Alice => lives_in => London
Structured extraction
Flat records use name::str for a single string. A bare field name, or any other suffix, is returned as a list.
model.extract_json(
"Alice joined Acme as a software engineer.",
{"employee": ["name::str", "company::str"]},
)
{
"employee": [
{"name": "Alice", "company": "Acme"}
]
}
Several tasks in one call
schema = (
model.create_schema()
.entities(["person", "organization", "location"])
.classification("sentiment", ["positive", "negative", "neutral"])
.relation("works_at", ["person"], ["organization"])
.relation("lives_in", ["person"], ["location"])
.structure("employee")
.field("name")
.field("company")
)
model.extract("Alice works at Acme and lives in London.", schema)
The result is a dictionary with classifications, entities, relations, and structures. On this sentence the sentiment label is neutral.
Files
onnx/encoder.onnx is the shared encoder. onnx/ner.onnx, onnx/classification.onnx, onnx/relations.onnx, and onnx/structuring.onnx are the task heads. Those heads already include the word-level LSTM, so inference does not open onnx/rnn.onnx.
Model tree for talmago/gliformer-base-v1-onnx
Base model
knowledgator/gliformer-base-v1