<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/nlp/modeling/layers/position_embedding.py#L97-L174) |

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>).

<br />

<br />

<br />

| ## 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. |

<br />

## Methods

### `call`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/nlp/modeling/layers/position_embedding.py#L139-L174)

    call(
        inputs, length=None
    )

Implements call() for the layer.

<br />

<br />

<br />

| 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`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A tensor in shape of `(length, hidden_size)`. ||

<br />