gliner.modeling.context_encoders module¶

Context encoders for already embedded token or word sequences.

class gliner.modeling.context_encoders.BaseContextEncoder(input_size, encoder_size, output_size)[source]¶

Bases: ABC, Module

Common interface for contextualizing dense sequence representations.

__init__(input_size, encoder_size, output_size)[source]¶
abstract property requires_full_recompute: bool¶

Whether appended positions can change all earlier representations.

forward(hidden_states, attention_mask)[source]¶

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class gliner.modeling.context_encoders.DebertaV2ContextEncoder(config, input_size, output_size)[source]¶

Bases: BaseContextEncoder

DeBERTa-v2 encoder stack operating directly on dense representations.

__init__(config, input_size, output_size)[source]¶
property requires_full_recompute: bool¶

Whether appended positions can change all earlier representations.

class gliner.modeling.context_encoders.IdentityContextEncoder(hidden_size)[source]¶

Bases: BaseContextEncoder

No-op encoder used when contextualization is disabled.

__init__(hidden_size)[source]¶
property requires_full_recompute: bool¶

Whether appended positions can change all earlier representations.

class gliner.modeling.context_encoders.ModernBertContextEncoder(config, input_size, output_size)[source]¶

Bases: BaseContextEncoder

ModernBERT model using its public dense inputs_embeds path.

__init__(config, input_size, output_size)[source]¶
property requires_full_recompute: bool¶

Whether appended positions can change all earlier representations.

class gliner.modeling.context_encoders.RNNContextEncoder(config, input_size, output_size)[source]¶

Bases: BaseContextEncoder

Packed LSTM context encoder with optional bidirectionality.

__init__(config, input_size, output_size)[source]¶
property requires_full_recompute: bool¶

Whether appended positions can change all earlier representations.

gliner.modeling.context_encoders.build_context_encoder(encoder_config, *, input_size, output_size=None, dropout=0.0)[source]¶

Build a context encoder with a stable dense-input/dense-output contract.