pub struct Embedding<const VOCAB: usize, const DIM: usize, E: Dtype, D: DeviceStorage> {
pub weight: Tensor<Rank2<VOCAB, DIM>, E, D>,
}
Expand description
An embedding Initializes Self::weight from a Uniform distribution between [-1 / sqrt(I), 1 / sqrt(I)].
Generics
VOCAB
The size of the vocabulary, inputs integer values must be between 0 and VOCAB;DIM
The “output” size of vectors & matrices which are the vectors being selected.
Examples
Embedding<5, 2>
can act on vectors with SEQ integer elements (with values between 0 and 4), and results in a SEQ tensor of
usually f32 elements being the rows in Self::weight.
type Model = Embedding<7, 2>;
let mut model = dev.build_module::<Model, f32>();
// single sequence of ids
let inputs: Tensor<Rank1<5>, usize, _> = dev.zeros();
let _: Tensor<(Const<5>, Const<2>,), f32, _> = model.forward(inputs);
// Dynamic sequence of ids
let inputs: Tensor<(usize, ), usize, _> = dev.zeros_like(&(5, ));
let _: Tensor<(usize, Const<2>,), f32, _> = model.forward(inputs);
// batched sequence of ids
let inputs: Tensor<Rank2<10, 5>, usize, _> = dev.zeros();
let _: Tensor<(Const<10>, Const<5>, Const<2>), f32, _> = model.forward(inputs);
Fields§
§weight: Tensor<Rank2<VOCAB, DIM>, E, D>
Transposed weight matrix, shape (I, O)
Trait Implementations§
source§impl<const VOCAB: usize, const DIM: usize, E: Clone + Dtype, D: Clone + DeviceStorage> Clone for Embedding<VOCAB, DIM, E, D>
impl<const VOCAB: usize, const DIM: usize, E: Clone + Dtype, D: Clone + DeviceStorage> Clone for Embedding<VOCAB, DIM, E, D>
source§impl<const VOCAB: usize, const DIM: usize, E: Debug + Dtype, D: Debug + DeviceStorage> Debug for Embedding<VOCAB, DIM, E, D>
impl<const VOCAB: usize, const DIM: usize, E: Debug + Dtype, D: Debug + DeviceStorage> Debug for Embedding<VOCAB, DIM, E, D>
source§impl<const VOCAB: usize, const DIM: usize, BATCH: Dim, SEQ: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(BATCH, SEQ), usize, D, T>> for Embedding<VOCAB, DIM, E, D>
impl<const VOCAB: usize, const DIM: usize, BATCH: Dim, SEQ: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(BATCH, SEQ), usize, D, T>> for Embedding<VOCAB, DIM, E, D>
source§impl<const V: usize, const M: usize, SEQ: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(SEQ,), usize, D, T>> for Embedding<V, M, E, D>
impl<const V: usize, const M: usize, SEQ: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(SEQ,), usize, D, T>> for Embedding<V, M, E, D>
source§impl<const C: usize, const M: usize, E: Dtype + Float + SampleUniform, D: Device<E>> TensorCollection<E, D> for Embedding<C, M, E, D>
impl<const C: usize, const M: usize, E: Dtype + Float + SampleUniform, D: Device<E>> TensorCollection<E, D> for Embedding<C, M, E, D>
§type To<E2: Dtype, D2: Device<E2>> = Embedding<C, M, E2, D2>
type To<E2: Dtype, D2: Device<E2>> = Embedding<C, M, E2, D2>
Type alias that specifies the how a module’s type changes when using a different dtype and/or
device.
source§fn iter_tensors<V: ModuleVisitor<Self, E, D>>(
visitor: &mut V
) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>
fn iter_tensors<V: ModuleVisitor<Self, E, D>>( visitor: &mut V ) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>
Specifies how to iterate through tensors or modules containted within this module, and how
to contruct this module given values for its fields. Returns
Err(_)
to indicate an error,
Ok(None)
to indicate that there is no error and a module has not been built, and
Ok(Some(_))
contains Self::Output<E2, D2>
source§fn module<F1, F2, Field>(
name: &str,
get_ref: F1,
get_mut: F2
) -> ModuleField<'_, F1, F2, Self, Field>where
F1: FnMut(&Self) -> &Field,
F2: FnMut(&mut Self) -> &mut Field,
Field: TensorCollection<E, D>,
fn module<F1, F2, Field>( name: &str, get_ref: F1, get_mut: F2 ) -> ModuleField<'_, F1, F2, Self, Field>where F1: FnMut(&Self) -> &Field, F2: FnMut(&mut Self) -> &mut Field, Field: TensorCollection<E, D>,
Creates a ModuleFields that represents a field that may contain one or more tensors. Read more
source§fn tensor<F1, F2, S>(
name: &str,
get_ref: F1,
get_mut: F2,
options: TensorOptions<S, E, D>
) -> TensorField<'_, F1, F2, Self, S, E, D>where
F1: FnMut(&Self) -> &Tensor<S, E, D>,
F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>,
S: Shape,
fn tensor<F1, F2, S>( name: &str, get_ref: F1, get_mut: F2, options: TensorOptions<S, E, D> ) -> TensorField<'_, F1, F2, Self, S, E, D>where F1: FnMut(&Self) -> &Tensor<S, E, D>, F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>, S: Shape,
Creates a ModuleFields that represents a tensor field. Read more