use candle_core::{Result, Tensor};
pub struct SchemaGather;
pub struct SchemaGatherOutput {
pub pc_emb: Tensor,
pub field_embs: Tensor,
}
impl SchemaGather {
pub fn forward(&self, hidden_states: &Tensor, schema_indices: &Tensor) -> Result<SchemaGatherOutput> {
let h = hidden_states.squeeze(0)?;
let all = h.index_select(schema_indices, 0)?;
let pc_emb = all.narrow(0, 0, 1)?;
let n = all.dim(0)?;
let hidden_dim = all.dim(1)?;
let field_embs = if n > 1 {
all.narrow(0, 1, n - 1)?
} else {
Tensor::zeros((0, hidden_dim), all.dtype(), all.device())?
};
Ok(SchemaGatherOutput { pc_emb, field_embs })
}
}