diffusion_models.models.positional_encoding.PositionalEncoding

class diffusion_models.models.positional_encoding.PositionalEncoding(d_model=256, dropout=0.1, max_len=5000)[source]

Bases: Module

__init__(d_model=256, dropout=0.1, max_len=5000)[source]

Constructor of PositionalEncoding class.

Parameters:
  • d_model (int) – feature dimensionality of the model

  • dropout (float) – probability value of dropout layers

  • max_len (int) – maximum length of sequence (shorter setting will free up GPU memory)

Methods

__init__([d_model, dropout, max_len])

Constructor of PositionalEncoding class.

forward(x)

type x:

Tensor, 'length batch features')

get_pos_encoding(t)

Get positional encoding for position/timestep t.

forward(x)[source]
Parameters:

x (Tensor, 'length batch features')) – input sequence

Returns:

output sequence with added positional encoding

Return type:

output

get_pos_encoding(t)[source]

Get positional encoding for position/timestep t.

Parameters:

t (Tensor, 'batch')) – timesteps to get positional encoding for (one batch)

Returns:

positional encodings for batch

Return type:

out