xberg-gliner 1.3.10

GLiNER inference used by xberg NER: span-mode ONNX runtime plus an optional Candle GLiNER2 backend.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! `token_gather`; non-parametric utility head.

use candle_core::{Result, Tensor};

/// Stateless token-gather head. Holds no parameters.
pub struct TokenGather;

impl TokenGather {
    /// `hidden_states[0, word_indices, :]` → `[1, num_words, H]`.
    pub fn forward(&self, hidden_states: &Tensor, word_indices: &Tensor) -> Result<Tensor> {
        let h = hidden_states.squeeze(0)?;
        let gathered = h.index_select(word_indices, 0)?;
        gathered.unsqueeze(0)
    }
}