tfm.nlp.layers.RelativePositionEmbedding
Stay organized with collections
Save and categorize content based on your preferences.
Creates a positional embedding.
tfm.nlp.layers.RelativePositionEmbedding(
hidden_size: int,
min_timescale: float = 1.0,
max_timescale: float = 10000.0,
**kwargs
)
This layer calculates the position encoding as a mix of sine and cosine
functions with geometrically increasing wavelengths. Defined and formulized in
"Attention is All You Need", section 3.5.
(https://arxiv.org/abs/1706.03762).
Args |
hidden_size
|
Size of the hidden layer.
|
min_timescale
|
Minimum scale that will be applied at each position
|
max_timescale
|
Maximum scale that will be applied at each position.
|
Methods
call
View source
call(
inputs, length=None
)
Implements call() for the layer.
| Args |
inputs
|
An tensor whose second dimension will be used as length. If
None, the other length argument must be specified.
|
length
|
An optional integer specifying the number of positions. If both
inputs and length are spcified, length must be equal to the second
dimension of inputs.
|
| Returns |
A tensor in shape of (length, hidden_size).
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-11-06 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-11-06 UTC."],[],[]]