Multitask Models
Overview
Multitask models are powerful and efficient neural networks trained to handle multiple natural language processing (NLP) tasks with a single unified GLiNER architecture.
Supported Tasks
GLiNER multitask models support the following tasks:
- Classification: Categorize text into predefined classes for tasks like sentiment analysis, topic classification, or content categorization
- Question-Answering: Extract answers to natural language questions from given text passages
- Relation Extraction: Identify and extract relationships between entities in text
- Open Information Extraction: Extract structured information from text using custom prompts and label definitions
- Summarization: Generate concise summaries of longer text passages
Benefits
- Efficiency: Use a single model for multiple tasks instead of managing separate models
- Consistency: Shared representations ensure consistent understanding across different tasks
- Flexibility: Easily switch between tasks without loading different models
- Resource-Friendly: Reduced memory footprint and deployment complexity
Multitask Models
| Name | Encoder | Size (GB) | Zero-Shot F1 Score▼ |
|---|---|---|---|
| gliner-multitask-v1.0 | deberta-v2-xlarge | 3.64 | 0.6325 |
| gliner-multitask-large-v0.5 | deberta-v3-large | 1.76 | 0.6276 |
| gliner-llama-multitask-1B-v1.0 | Llama-encoder-1.0B | 4.24 | 0.6153 |
Classification
from gliner import GLiNER
from gliner.multitask import GLiNERClassifier
model_id = 'knowledgator/gliner-multitask-v1.0'
model = GLiNER.from_pretrained(model_id)
classifier = GLiNERClassifier(model=model)
text = "SpaceX successfully launched a new rocket into orbit."
labels = ['science', 'technology', 'business', 'sports']
predictions = classifier(text, classes=labels, multi_label=False)
print(predictions)
Expected Output
[[{'label': 'technology', 'score': 0.3839840292930603}]]
Question-Answering
from gliner import GLiNER
from gliner.multitask import GLiNERQuestionAnswerer
model_id = 'knowledgator/gliner-multitask-v1.0'
model = GLiNER.from_pretrained(model_id)
answerer = GLiNERQuestionAnswerer(model=model)
text = "SpaceX successfully launched a new rocket into orbit."
question = 'Which company launched a new rocket?'
predictions = answerer(text, questions=question)
print(predictions)
Expected Output
[[{'answer': 'SpaceX', 'score': 0.998126208782196}]]
Relation Extraction
from gliner import GLiNER
from gliner.multitask import GLiNERRelationExtractor
model_id = 'knowledgator/gliner-multitask-v1.0'
model = GLiNER.from_pretrained(model_id)
relation_extractor = GLiNERRelationExtractor(model=model)
text = "Elon Musk founded SpaceX in 2002 to reduce space transportation costs."
relations = ['founded', 'owns', 'works for']
entities = ['person', 'company', 'year']
predictions = relation_extractor(text, entities=entities, relations=relations)
print(predictions)
Expected Output
[[{'source': 'Elon Musk', 'relation': 'founded', 'target': 'SpaceX', 'score': 0.9583475589752197}]]
Open Information Extraction
from gliner import GLiNER
from gliner.multitask import GLiNEROpenExtractor
model_id = 'knowledgator/gliner-multitask-v1.0'
model = GLiNER.from_pretrained(model_id)
extractor = GLiNEROpenExtractor(model=model, prompt="Extract all companies related to space technologies")
text = "Elon Musk founded SpaceX in 2002 to reduce space transportation costs. Also Elon is founder of Tesla, NeuroLink and many other companies."
labels = ['company']
predictions = extractor(text, labels=labels)
print(predictions)
Expected Output
[[{'start': 72, 'end': 78, 'text': 'SpaceX', 'label': 'company', 'score': 0.9622299075126648}, {'start': 149, 'end': 154, 'text': 'Tesla', 'label': 'company', 'score': 0.9357912540435791}, {'start': 156, 'end': 165, 'text': 'NeuroLink', 'label': 'company', 'score': 0.9122058749198914}]]
Summarization
from gliner import GLiNER
from gliner.multitask import GLiNERSummarizer
model_id = 'knowledgator/gliner-multitask-v1.0'
model = GLiNER.from_pretrained(model_id)
summarizer = GLiNERSummarizer(model=model)
text = "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014."
summary = summarizer(text, threshold=0.1)
print(summary)
Expected Output
['Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.']