pub struct Embedding<E> { /* private fields */ }Expand description
The embedding lookup table.gather(selection): one [vocab, dim]
parameter behind the gather that is the whole formula.
The input is a one-hot [count, vocab] selection — feed a
Tensor::selection as a per-run input
so one recorded graph serves any batch of indices — and the output
is the selected [count, dim] rows. Layout beyond the lookup
(concatenating a context window, adding a position table) stays
with the caller; a position table is simply a second Embedding.
Tying goes through the exposed table symbol,
like Linear::weights: a tied
language-model head is a matmul with the resolved table, not a
second module.
Implementations§
Source§impl<E: Element> Embedding<E>
impl<E: Element> Embedding<E>
Sourcepub fn new(tape: &Tape<E>, table: Tensor<E>) -> Self
pub fn new(tape: &Tape<E>, table: Tensor<E>) -> Self
Allocates the [vocab, dim] table on tape from its initial
payload and returns the module. Callers own initialization;
the module records whatever it is given.
§Panics
Panics if table is not rank 2.
Sourcepub fn parameters(&self) -> impl Iterator<Item = Symbol> + '_
pub fn parameters(&self) -> impl Iterator<Item = Symbol> + '_
Returns the symbols of the module’s parameters: the table.