embeddings¶
embeddings
provide a collection of pre-defined positional embeddings.
multimolecule.module.embeddings
¶
RotaryEmbedding
¶
Bases: Module
Rotary position embeddings based on those in RoFormer.
Query and keys are transformed by rotation matrices which depend on their relative positions.
Cache
The inverse frequency buffer is cached and updated only when the sequence length changes or the device changes.
Sequence Length
Rotary Embedding is irrespective of the sequence length and can be used for any sequence length.
Source code in multimolecule/module/embeddings/rotary.py
SinusoidalEmbedding
¶
Bases: Embedding
Sinusoidal positional embeddings for inputs with any length.
Freezing
The embeddings are frozen and cannot be trained. They will not be saved in the model’s state_dict.
Padding Idx
Padding symbols are ignored if the padding_idx is specified.
Sequence Length
These embeddings get automatically extended in forward if more positions is needed.
Source code in multimolecule/module/embeddings/sinusoidal.py
get_embedding
staticmethod
¶
Python | |
---|---|
Build sinusoidal embeddings.
This matches the implementation in tensor2tensor, but differs slightly from the description in Section 3.5 of “Attention Is All You Need”.
Source code in multimolecule/module/embeddings/sinusoidal.py
get_position_ids
staticmethod
¶
Replace non-padding symbols with their position numbers.
Position numbers begin at padding_idx+1. Padding symbols are ignored.