Skip to main content

Embedding

Embedding(num_embeddings, embedding_dim, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False, _weight=None, _freeze=False, device=None, dtype=None)

Gathers rows of its [num_embeddings, embedding_dim] table by index.

Args: num_embeddings: the table's row count (the vocabulary size). embedding_dim: the size of each row. padding_idx: the index of the padding row; kept as an attribute (a lookup is a plain gather here, so the row holds whatever the checkpoint carries). max_norm: not served (it renormalizes rows at every lookup); pass None. norm_type: the norm max_norm would use; unused without it. scale_grad_by_freq: a gradient option; only False is served. sparse: a gradient layout option; only False is served. _weight: a [num_embeddings, embedding_dim] table to bind at construction. _freeze: accepted for signature compatibility; this runtime trains nothing, so every table is frozen. device: where the table lives; None declares on the cpu. dtype: the table dtype the layer declares; None declares the default dtype (:func:~clika_runtime.get_default_dtype). A load_state_dict casts a dense table to the declared dtype; assign=True adopts the table's own dtype instead, and a quantized table binds as it is (a set dtype then pins the lookup's output dtype).

__init__​

__init__(self, num_embeddings: 'int', embedding_dim: 'int', padding_idx: 'int | None' = None, max_norm: 'float | None' = None, norm_type: 'float' = 2.0, scale_grad_by_freq: 'bool' = False, sparse: 'bool' = False, _weight: 'Tensor | None' = None, _freeze: 'bool' = False, device: 'Device | str | None' = None, dtype: 'DtypeLike | None' = None) -> 'None'

Initialize self. See help(type(self)) for accurate signature.

extra_repr​

extra_repr(self) -> 'str'

extra_repr() -> str

One line of per-class detail for :meth:__repr__; a layer prints its geometry here (in_features=64, out_features=256).

forward​

forward(self, input: 'Tensor') -> 'Tensor'

forward(input) -> Tensor

Gather rows: [*] int32 / int64 indices to [*, embedding_dim].

from_pretrained​

from_pretrainedfrom_pretrained(embeddings, freeze=True, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False) -> Embedding

from_pretrained(embeddings, freeze=True, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False) -> Embedding

Construct FROM a [num_embeddings, embedding_dim] table, bound in the same call; freeze is accepted for signature compatibility (this runtime trains nothing).

from_weights​

from_weightsfrom_weights(weight, *, dtype=None, device=None) -> Embedding

from_weights(weight, *, dtype=None, device=None) -> Embedding

Construct FROM a table (dense or quantized): geometry, dtype, and device read off weight, bound in the same call. A set dtype casts a dense table (a quantized table pins the lookup's output dtype instead).

set_weights​

set_weights(self, weight: 'Tensor') -> 'None'

set_weights(weight) -> None

Bind the table directly (dense, or a quantized payload carrying its scheme); raises RuntimeError on a shape mismatch.