Skip to content

Feature Request: Support Dict[str, str] for labels in inference() (label descriptions) #375

Description

@Manikandan-t

Hi team, I am using a custom model built on top of GLiNER (knowledgator/gliner-relex-large-v1.0) and wanted to ask if there are plans to support dictionary-based labels in the base library.

The Context
The model card for the custom knowledgator model instructs users to pass a dictionary (mapping labels to their descriptions) to the inference() method:

entity_labels = {
    "person": "A human individual, including fictional characters",
    "organization": "A company, institution, agency, or other group of people",
}

entities, relations = model.inference(
    texts=[text],
    labels=entity_labels,  # Passing a Dict instead of a List
    # ...
)

The Issue
Running this code currently crashes the base library with a TypeError: unhashable type: 'dict' (or KeyError: 0).

This happens because BaseEncoderGLiNER.prepare_batch() (around line 2069) assumes labels is a list, and evaluating labels[0] on a dictionary triggers a key lookup error. Furthermore, the base type signature for inference() explicitly only accepts Union[str, List[str], List[List[str]]].

Environment:

  • gliner version: 0.2.27
  • Python: 3.13
  • Branch: main

Question
Are there any plans for the base GLiNER library to officially support passing label descriptions as a Dict[str, str]? Or is this a custom feature that downstream model creators should be implementing themselves via custom wrappers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions