gliner.modeling.outputs module¶

class gliner.modeling.outputs.GLiNERBaseOutput(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None)[source]¶

Bases: ModelOutput

Base output class for GLiNER models.

This class contains the fundamental outputs produced by GLiNER models, including loss, logits, and embeddings for both prompts (entity types) and input words/tokens.

loss¶

The total loss for training. Shape: scalar tensor.

Type:

Optional[torch.FloatTensor]

logits¶

The prediction scores for entity spans or other outputs. Shape varies depending on the model configuration, typically [batch_size, num_spans, num_classes] or similar.

Type:

Optional[torch.FloatTensor]

prompts_embedding¶

Embeddings for the entity type prompts/labels. Shape: [batch_size, num_classes, hidden_size].

Type:

Optional[torch.FloatTensor]

prompts_embedding_mask¶

Attention mask for prompt embeddings. Shape: [batch_size, num_classes].

Type:

Optional[torch.LongTensor]

words_embedding¶

Embeddings for input words/tokens. Shape: [batch_size, seq_len, hidden_size].

Type:

Optional[torch.FloatTensor]

mask¶

Attention mask for input tokens. Shape: [batch_size, seq_len].

Type:

Optional[torch.LongTensor]

loss: FloatTensor | None = None¶
logits: FloatTensor | None = None¶
prompts_embedding: FloatTensor | None = None¶
prompts_embedding_mask: LongTensor | None = None¶
words_embedding: FloatTensor | None = None¶
mask: LongTensor | None = None¶
__init__(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None)¶
class gliner.modeling.outputs.GLiNERDecoderOutput(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None, decoder_loss=None, decoder_embedding=None, decoder_embedding_mask=None, decoder_span_idx=None)[source]¶

Bases: GLiNERBaseOutput

Output class for GLiNER models with decoder components.

Extends GLiNERBaseOutput with additional decoder-specific outputs, including decoder embeddings and span indices. This is typically used in GLiNER variants that include an explicit decoder module.

loss¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

logits¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

prompts_embedding¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

prompts_embedding_mask¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.LongTensor]

words_embedding¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

mask¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.LongTensor]

decoder_loss¶

Loss specific to the decoder component. Shape: scalar tensor.

Type:

Optional[torch.FloatTensor]

decoder_embedding¶

Output embeddings from the decoder. Shape: [batch_size, num_decoder_tokens, hidden_size].

Type:

Optional[torch.FloatTensor]

decoder_embedding_mask¶

Attention mask for decoder embeddings. Shape: [batch_size, num_decoder_tokens].

Type:

Optional[torch.LongTensor]

decoder_span_idx¶

Indices of spans processed by the decoder. Shape: [batch_size, num_spans, 2], where the last dimension contains [start_idx, end_idx].

Type:

Optional[torch.LongTensor]

decoder_loss: FloatTensor | None = None¶
decoder_embedding: FloatTensor | None = None¶
decoder_embedding_mask: LongTensor | None = None¶
decoder_span_idx: LongTensor | None = None¶
__init__(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None, decoder_loss=None, decoder_embedding=None, decoder_embedding_mask=None, decoder_span_idx=None)¶
class gliner.modeling.outputs.GLiNERRelexOutput(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None, rel_idx=None, rel_logits=None, rel_mask=None)[source]¶

Bases: GLiNERBaseOutput

Output class for GLiNER models with relation extraction.

Extends GLiNERBaseOutput with relation-specific outputs for models that perform both entity recognition and relation extraction (Relex). This enables joint modeling of entities and their relationships.

loss¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

logits¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

prompts_embedding¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

prompts_embedding_mask¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.LongTensor]

words_embedding¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.FloatTensor]

mask¶

Inherited from GLiNERBaseOutput.

Type:

Optional[torch.LongTensor]

rel_idx¶

Indices of entity pairs for which relations are predicted. Shape: [batch_size, num_relations, 2], where the last dimension contains indices of the two entities.

Type:

Optional[torch.LongTensor]

rel_logits¶

Prediction scores for relations between entity pairs. Shape: [batch_size, num_relations, num_relation_types].

Type:

Optional[torch.FloatTensor]

rel_mask¶

Mask indicating valid relation predictions. Shape: [batch_size, num_relations].

Type:

Optional[torch.FloatTensor]

rel_idx: LongTensor | None = None¶
rel_logits: FloatTensor | None = None¶
rel_mask: FloatTensor | None = None¶
__init__(loss=None, logits=None, prompts_embedding=None, prompts_embedding_mask=None, words_embedding=None, mask=None, rel_idx=None, rel_logits=None, rel_mask=None)¶