Summarization
Generate extractive summaries from text using the Knowledgator Python SDK.
Example Usage
from knowledgator import Knowledgator
kg = Knowledgator(api_key="YOUR_API_KEY")
result = kg.extract.summary(
text="""
The study examined the effects of climate change on coastal ecosystems.
Researchers found significant coral bleaching in tropical regions.
Temperature increases of 2°C led to 40% habitat loss.
The team recommends immediate conservation efforts.
Further research is needed to validate these results across different regions.
""",
prompt="Extract the main findings and recommendations.",
threshold=0.5,
adapter_id="your-lora-adapter-id" # Optional LoRA adapter
)
for summary_span in result.summary.value:
print(f"[{summary_span.score:.2f}] {summary_span.text}")
Expected Output
[0.91] Researchers found significant coral bleaching in tropical regions.
[0.86] Temperature increases of 2°C led to 40% habitat loss.
[0.84] The team recommends immediate conservation efforts.
Result Object Structure
{
"outputs": {
"summary": {
"type": "span",
"value": [
{
"text": "Researchers found significant coral bleaching in tropical regions.",
"start": 82,
"end": 149,
"score": 0.91
},
{
"text": "Temperature increases of 2°C led to 40% habitat loss.",
"start": 154,
"end": 207,
"score": 0.86
},
{
"text": "The team recommends immediate conservation efforts.",
"start": 212,
"end": 263,
"score": 0.84
}
]
}
}
}