Package smile.llm
Class PositionalEncoding
java.lang.Object
smile.llm.PositionalEncoding
Positional encoding in original Transformer. Positional encoding injects
some information about the absolute position of the tokens in the sequence.
The positional encodings have the same dimension as the embeddings, so that
the two can be summed. This class uses sine and cosine functions of
different frequencies.
-
Constructor Summary
ConstructorDescriptionPositionalEncoding
(int dim, int end) Constructor.PositionalEncoding
(int dim, int end, double theta) Constructor. -
Method Summary
-
Constructor Details
-
PositionalEncoding
public PositionalEncoding(int dim, int end) Constructor.- Parameters:
dim
- the dimension of the frequency tensor.end
- the end index for precomputing frequencies.
-
PositionalEncoding
public PositionalEncoding(int dim, int end, double theta) Constructor.- Parameters:
dim
- the dimension of the frequency tensor.end
- the end index for precomputing frequencies.theta
- the scaling factor for frequency computation.
-
-
Method Details