Skip to main content

General Entity Extraction

Extract named entities and spans from text using prompted entity extraction with the Knowledgator Python SDK.


Example Usage​

from knowledgator import Knowledgator

kg = Knowledgator(api_key="YOUR_API_KEY")

result = kg.extract.it(
text="John Smith works at Acme Corp in New York.",
tasks={
"entities": {
"type": "span",
"labels": ["person", "organization", "location"],
"threshold": 0.5,
}
},
adapter_id="your-lora-adapter-id", # Optional LoRA adapter
)

for entity in result.outputs["entities"].value:
print(f"{entity.span} ({entity.entity}): {entity.score}")
LoRA Adapters vs. Open Models

adapter_id is for fine-tuned LoRA adapters attached to base services. If you trained a standalone Open Model (e.g. GLiClass or GLiNER checkpoint), query it via kg.model(model_id).predict(...) instead.


Expected Output​

John Smith (person): 0.93
Acme Corp (organization): 0.87

Result Object Structure​

{
"outputs": {
"entities": {
"type": "span",
"value": [
{
"span": "John Smith",
"entity": "person",
"start": 0,
"end": 10,
"score": 0.93
},
{
"span": "Acme Corp",
"entity": "organization",
"start": 25,
"end": 34,
"score": 0.87
}
],
"threshold": 0.5
}
}
}