---
title: Relations & Classification
description: Extract relationships between entities and classify text with zero-shot models.
canonical_url: https://superlinked.com/docs/extract/relations
last_updated: 2026-05-20
---

GLiREL and GLiClass models extract relationships and classify text with zero-shot label support.

## Relation Extraction

Source: [packages/sie_server/src/sie_server/adapters/glirel/__init__.py](https://github.com/superlinked/sie/blob/main/packages/sie_server/src/sie_server/adapters/glirel/__init__.py)

GLiREL models extract relationships between entities. Relation types are passed via the `labels` parameter. Entities must be pre-extracted (e.g. with GLiNER) and passed in `item.metadata`:

#### Python

```python
from sie_sdk import SIEClient
from sie_sdk.types import Item

client = SIEClient("http://localhost:8080")

text = "Tim Cook is the CEO of Apple Inc."

# Step 1: Extract entities with GLiNER
ner_result = client.extract(
    "urchade/gliner_multi-v2.1",
    Item(text=text),
    labels=["person", "organization"]
)

# Step 2: Pass entities to GLiREL for relation extraction
result = client.extract(
    "jackboyla/glirel-large-v0",
    Item(text=text, metadata={"entities": ner_result["entities"]}),
    labels=["works_for", "ceo_of", "founded"]
)

for relation in result["relations"]:
    print(f"{relation['head']} --{relation['relation']}--> {relation['tail']}")
# Tim Cook --ceo_of--> Apple Inc.
```

#### TypeScript

```typescript
import { SIEClient } from "@superlinked/sie-sdk";

const client = new SIEClient("http://localhost:8080");

const text = "Tim Cook is the CEO of Apple Inc.";

// Step 1: Extract entities with GLiNER
const nerResult = await client.extract(
  "urchade/gliner_multi-v2.1",
  { text },
  { labels: ["person", "organization"] }
);

// Step 2: Pass entities to GLiREL for relation extraction
const result = await client.extract(
  "jackboyla/glirel-large-v0",
  { text, metadata: { entities: nerResult.entities } },
  { labels: ["works_for", "ceo_of", "founded"] }
);

for (const relation of result.relations) {
  console.log(`${relation.head} --${relation.relation}--> ${relation.tail}`);
}
// Tim Cook --ceo_of--> Apple Inc.

await client.close();
```

### Relation Fields

| Field | Type | Description |
|-------|------|-------------|
| `head` | `str` | Source entity |
| `tail` | `str` | Target entity |
| `relation` | `str` | Relation type |
| `score` | `float` | Confidence score |

## Text Classification

Source: [packages/sie_server/src/sie_server/adapters/gliclass/__init__.py](https://github.com/superlinked/sie/blob/main/packages/sie_server/src/sie_server/adapters/gliclass/__init__.py)

GLiClass models classify text into categories:

#### Python

```python
result = client.extract(
    "knowledgator/gliclass-base-v1.0",
    Item(text="I absolutely loved this movie! The acting was superb."),
    labels=["positive", "negative", "neutral"]
)

for classification in result["classifications"]:
    print(f"{classification['label']}: {classification['score']:.2f}")
# positive: 0.94
# neutral: 0.04
# negative: 0.02
```

#### TypeScript

```typescript
const result = await client.extract(
  "knowledgator/gliclass-base-v1.0",
  { text: "I absolutely loved this movie! The acting was superb." },
  { labels: ["positive", "negative", "neutral"] }
);

for (const classification of result.classifications) {
  console.log(`${classification.label}: ${classification.score.toFixed(2)}`);
}
// positive: 0.94
// neutral: 0.04
// negative: 0.02
```

### Overflow policy

GLiClass models (`gliclass-{small,base,large}-v1.0`) have a 512-token fused context; `text` and the `<<LABEL>>...<<SEP>>` label prompt share the same budget. When input exceeds that budget, the underlying gliclass library can crash or return corrupted output. Set `overflow_policy` per request to control how the server handles overflow before it reaches the library.

`overflow_policy` is gliclass-only today. See the [Python SDK](/docs/reference/sdk/#inputtoolongerror) and [TypeScript SDK](/docs/reference/typescript-sdk/#inputtoolongerror) references for the typed exception, and the [HTTP API](/docs/reference/api/#per-request-options) for the wire-level option.

| Value | Behavior on overflow |
|-------|----------------------|
| `default` *(server default)* | Input passes through as-is. Not recommended for production; use only to reproduce public benchmarks. |
| `truncate_text` | End of `text` is truncated to fit; labels are preserved. Raises `INPUT_TOO_LONG` only if the label prompt alone exceeds the context. |
| `error` | Always raises `INPUT_TOO_LONG` on overflow. |

#### Python

```python
from sie_sdk import SIEClient
from sie_sdk.client.errors import InputTooLongError
from sie_sdk.types import Item

client = SIEClient("http://localhost:8080")

try:
    result = client.extract(
        "knowledgator/gliclass-small-v1.0",
        Item(text=long_review),
        labels=["positive", "negative", "neutral"],
        options={"overflow_policy": "truncate_text"},
    )
except InputTooLongError as e:
    print(f"Input too long for {e.model}: {e}")
```

#### TypeScript

```typescript
import { SIEClient, InputTooLongError } from "@superlinked/sie-sdk";

const client = new SIEClient("http://localhost:8080");

try {
  const result = await client.extract(
    "knowledgator/gliclass-small-v1.0",
    { text: longReview },
    {
      labels: ["positive", "negative", "neutral"],
      adapterOptions: { overflow_policy: "truncate_text" },
    },
  );
} catch (error) {
  if (error instanceof InputTooLongError) {
    console.log(`Input too long for ${error.model}: ${error.message}`);
  }
}
```

## Recommended Models

Source: [packages/sie_server/models/](https://github.com/superlinked/sie/blob/main/packages/sie_server/models/)

### Relation Extraction Models

| Model | Notes |
|-------|-------|
| `jackboyla/glirel-large-v0` | Zero-shot relation extraction |

### NER Models

| Model | Languages | Notes |
|-------|-----------|-------|
| `urchade/gliner_multi-v2.1` | Multilingual | General-purpose NER |
| `urchade/gliner_large-v2.1` | English | Larger model (459M params) |
| `numind/NuNER_Zero` | English | Zero-shot NER |
| `urchade/gliner_multi_pii-v1` | Multilingual | PII detection |

### Classification Models

| Model | Notes |
|-------|-------|
| `knowledgator/gliclass-base-v1.0` | Zero-shot classification |
| `knowledgator/gliclass-small-v1.0` | Faster, smaller |

See [Full model catalog](/models#task=extract) for the complete list.

## Framework Integrations

All extraction types (entities, relations, classifications) are also available through framework integrations. See [LangChain](/docs/integrations/langchain/), [LlamaIndex](/docs/integrations/llamaindex/), [Haystack](/docs/integrations/haystack/), [DSPy](/docs/integrations/dspy/), and [CrewAI](/docs/integrations/crewai/) for framework-specific examples.

## What's Next

- [NER & Entity Extraction](/docs/extract/) - named entity recognition
- [Vision Tasks](/docs/extract/vision/) - image captioning, object detection, and document understanding
- [OCR](/docs/extract/ocr/) - convert document images and PDFs to Markdown
- [Full model catalog](/models#task=extract) - all supported models
