transformer_encoder
transformer_encoder
¶
Transformer Encoder used as the learnable parameterized prior for Variational Inference.
PriorTransformerEncoder
¶
PriorTransformerEncoder(embedding_dimension, latent_dimension, prediction_horizon, observation_horizon, device, number_of_heads=8, feedforward_dimension=512, number_of_encoder_layers=4, activation=value, dropout_rate=0.1, attention_dropout=0.0, normalization_type=value, attention_type=value, positional_encoding_type=None, exclude_keys=None, learn_variance=True, min_logvar=None, deterministic=False, max_logvar=None)
Bases: PriorLatentEncoder
Transformer encoder network to model the conditional prior p_psi(z|s).
Handles input projection, transformer encoding with CLS token, and latent sampling and reparametrization.
Source code in src/versatil/models/decoding/latent/prior/transformer_encoder.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
get_auxiliary_output_keys
¶
Gaussian prior keys, excluding logvar when deterministic.
Source code in src/versatil/models/decoding/latent/prior/transformer_encoder.py
forward
¶
Encode observation features to latent space z embedding using Variational Inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_latents
|
Tensor | None
|
Target latent from posterior q(z|a,s). Not used by this prior. |
required |
observations
|
dict[str, Tensor]
|
Dictionary of observation features used as the input. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary of tensors (z, mu, logvar) with shape (B, latent_dim) for each. |
Source code in src/versatil/models/decoding/latent/prior/transformer_encoder.py
sample_prior
¶
Sample latent variable from learned prior p(z|s).