Embeddings
About
The d9d.module.block.embedding package provides the SplitTokenEmbeddings token embedding layer. It is built from several named embedding tables, called splits. Each split owns a contiguous range of the global vocabulary, in the order given by split_order.
Use Cases
- Regular token embedding: Use a single split with the full vocabulary size.
- Prompt tuning: Add new tokens to your tokenizer and use two splits. The first split holds the original token embeddings, and the second one holds the new prompt tokens. Train only the
nn.Embeddingof the second split.
The SplitLanguageModellingHead uses the same splits for the output vocabulary.
Usage
API Reference
d9d.module.block.embedding
Embedding layers.
SplitTokenEmbeddings
Bases: Module, ModuleLateInit
Token embedding layer composed of several named, independent embedding tables.
Each named split (e.g. "orig", "special", "prompt_prefix") owns a contiguous range of global
vocabulary indices. This is useful for model adaptation, where different sets of tokens need different
initialization or training behavior.
__init__(split_vocab_size, split_order, hidden_size)
Constructs the SplitTokenEmbeddings object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
split_vocab_size
|
dict[str, int]
|
Mapping from split names to their vocabulary sizes. |
required |
split_order
|
Sequence[str]
|
Order in which splits are concatenated to form the global vocabulary.
Every name must be a key of |
required |
hidden_size
|
int
|
Dimensionality of the embedding vectors. |
required |
forward(input_ids)
Looks up embeddings for global vocabulary indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
Global vocabulary indices. Can have any shape. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Embeddings. Shape: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
reset_parameters()
Resets the parameters of all embedding splits.