autoformer
mindnlp.transformers.models.autoformer.configuration_autoformer.AutoformerConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of an [AutoformerModel
]. It is used to instantiate an
Autoformer model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the Autoformer
[huggingface/autoformer-tourism-monthly] architecture.
Configuration objects inherit from [PreTrainedConfig
] can be used to control the model outputs. Read the
documentation from [PreTrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
prediction_length |
The prediction length for the decoder. In other words, the prediction horizon of the model.
TYPE:
|
context_length |
The context length for the encoder. If unset, the context length will be the same as the
TYPE:
|
distribution_output |
The distribution emission head for the model. Could be either "student_t", "normal" or "negative_binomial".
TYPE:
|
loss |
The loss function for the model corresponding to the
TYPE:
|
input_size |
The size of the target variable which by default is 1 for univariate targets. Would be > 1 in case of multivariate targets.
TYPE:
|
lags_sequence |
The lags of the input time series as covariates often dictated by the frequency. Default is
TYPE:
|
scaling |
Whether to scale the input targets.
TYPE:
|
num_time_features |
The number of time features in the input time series.
TYPE:
|
num_dynamic_real_features |
The number of dynamic real valued features.
TYPE:
|
num_static_categorical_features |
The number of static categorical features.
TYPE:
|
num_static_real_features |
The number of static real valued features.
TYPE:
|
cardinality |
The cardinality (number of different values) for each of the static categorical features. Should be a list
of integers, having the same length as
TYPE:
|
embedding_dimension |
The dimension of the embedding for each of the static categorical features. Should be a list of integers,
having the same length as
TYPE:
|
d_model |
Dimensionality of the transformer layers.
TYPE:
|
encoder_layers |
Number of encoder layers.
TYPE:
|
decoder_layers |
Number of decoder layers.
TYPE:
|
encoder_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
decoder_attention_heads |
Number of attention heads for each attention layer in the Transformer decoder.
TYPE:
|
encoder_ffn_dim |
Dimension of the "intermediate" (often named feed-forward) layer in encoder.
TYPE:
|
decoder_ffn_dim |
Dimension of the "intermediate" (often named feed-forward) layer in decoder.
TYPE:
|
activation_function |
The non-linear activation function (function or string) in the encoder and decoder. If string,
TYPE:
|
dropout |
The dropout probability for all fully connected layers in the encoder, and decoder.
TYPE:
|
encoder_layerdrop |
The dropout probability for the attention and fully connected layers for each encoder layer.
TYPE:
|
decoder_layerdrop |
The dropout probability for the attention and fully connected layers for each decoder layer.
TYPE:
|
attention_dropout |
The dropout probability for the attention probabilities.
TYPE:
|
activation_dropout |
The dropout probability used between the two layers of the feed-forward networks.
TYPE:
|
num_parallel_samples |
The number of samples to generate in parallel for each time step of inference.
TYPE:
|
init_std |
The standard deviation of the truncated normal weight initialization distribution.
TYPE:
|
use_cache |
Whether to use the past key/values attentions (if applicable to the model) to speed up decoding.
TYPE:
|
label_length |
Start token length of the Autoformer decoder, which is used for direct multi-step prediction (i.e. non-autoregressive generation).
TYPE:
|
moving_average |
The window size of the moving average. In practice, it's the kernel size in AvgPool1d of the Decomposition Layer.
TYPE:
|
autocorrelation_factor |
"Attention" (i.e. AutoCorrelation mechanism) factor which is used to find top k autocorrelations delays. It's recommended in the paper to set it to a number between 1 and 5.
TYPE:
|
Example
```python
from transformers import AutoformerConfig, AutoformerModel ...
Initializing a default Autoformer configuration¶
configuration = AutoformerConfig() ...
Randomly initializing a model (with random weights) from the configuration¶
model = AutoformerModel(configuration) ...
Accessing the model configuration¶
configuration = model.config ```
Source code in mindnlp/transformers/models/autoformer/configuration_autoformer.py
30 31 32 33 34 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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
mindnlp.transformers.models.autoformer.configuration_autoformer.AutoformerConfig.__init__(prediction_length=None, context_length=None, distribution_output='student_t', loss='nll', input_size=1, lags_sequence=[1, 2, 3, 4, 5, 6, 7], scaling=True, num_time_features=0, num_dynamic_real_features=0, num_static_categorical_features=0, num_static_real_features=0, cardinality=None, embedding_dimension=None, d_model=64, encoder_attention_heads=2, decoder_attention_heads=2, encoder_layers=2, decoder_layers=2, encoder_ffn_dim=32, decoder_ffn_dim=32, activation_function='gelu', dropout=0.1, encoder_layerdrop=0.1, decoder_layerdrop=0.1, attention_dropout=0.1, activation_dropout=0.1, num_parallel_samples=100, init_std=0.02, use_cache=True, is_encoder_decoder=True, label_length=10, moving_average=25, autocorrelation_factor=3, **kwargs)
¶
Initialize the AutoformerConfig.
PARAMETER | DESCRIPTION |
---|---|
prediction_length |
The number of time steps to predict into the future. Default is None.
TYPE:
|
context_length |
The number of time steps to use as a context for prediction. Default is None.
TYPE:
|
distribution_output |
The type of output distribution to use. Default is 'student_t'.
TYPE:
|
loss |
The loss function to use. Default is 'nll'.
TYPE:
|
input_size |
The size of the input. Default is 1.
TYPE:
|
lags_sequence |
The sequence of lagged time steps to use as inputs. Default is [1, 2, 3, 4, 5, 6, 7].
TYPE:
|
scaling |
Whether to scale the input data. Default is True.
TYPE:
|
num_time_features |
The number of time features. Default is 0.
TYPE:
|
num_dynamic_real_features |
The number of dynamic real features. Default is 0.
TYPE:
|
num_static_categorical_features |
The number of static categorical features. Default is 0.
TYPE:
|
num_static_real_features |
The number of static real features. Default is 0.
TYPE:
|
cardinality |
The cardinality of each static categorical feature. Default is None.
TYPE:
|
embedding_dimension |
The embedding dimension of each static categorical feature. Default is None.
TYPE:
|
d_model |
The dimension of the model. Default is 64.
TYPE:
|
encoder_attention_heads |
The number of attention heads in the encoder. Default is 2.
TYPE:
|
decoder_attention_heads |
The number of attention heads in the decoder. Default is 2.
TYPE:
|
encoder_layers |
The number of layers in the encoder. Default is 2.
TYPE:
|
decoder_layers |
The number of layers in the decoder. Default is 2.
TYPE:
|
encoder_ffn_dim |
The dimension of the feed-forward network in the encoder. Default is 32.
TYPE:
|
decoder_ffn_dim |
The dimension of the feed-forward network in the decoder. Default is 32.
TYPE:
|
activation_function |
The activation function to use. Default is 'gelu'.
TYPE:
|
dropout |
The dropout rate. Default is 0.1.
TYPE:
|
encoder_layerdrop |
The layerdrop rate in the encoder. Default is 0.1.
TYPE:
|
decoder_layerdrop |
The layerdrop rate in the decoder. Default is 0.1.
TYPE:
|
attention_dropout |
The dropout rate for attention layers. Default is 0.1.
TYPE:
|
activation_dropout |
The dropout rate for activation layers. Default is 0.1.
TYPE:
|
num_parallel_samples |
The number of parallel samples. Default is 100.
TYPE:
|
init_std |
The standard deviation for weight initialization. Default is 0.02.
TYPE:
|
use_cache |
Whether to use cache. Default is True.
TYPE:
|
is_encoder_decoder |
Whether the model is an encoder-decoder model. Default is True.
TYPE:
|
label_length |
The length of the label. Default is 10.
TYPE:
|
moving_average |
The moving average factor. Default is 25.
TYPE:
|
autocorrelation_factor |
The autocorrelation factor. Default is 3.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If |
ValueError
|
If |
Source code in mindnlp/transformers/models/autoformer/configuration_autoformer.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST = ['huggingface/autoformer-tourism-monthly']
module-attribute
¶
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction
¶
Bases: AutoformerPreTrainedModel
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.__init__(config)
¶
Initializes an instance of AutoformerForPrediction.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration settings for AutoformerForPrediction.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the 'config.distribution_output' is not 'student_t' or 'normal'. |
ValueError
|
If the 'config.loss' is not 'nll'. |
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.forward(past_values, past_time_features, past_observed_mask, static_categorical_features=None, static_real_features=None, future_values=None, future_time_features=None, future_observed_mask=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, past_key_values=None, output_hidden_states=None, output_attentions=None, use_cache=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Seq2SeqTSPredictionOutput, Tuple]
|
Union[Seq2SeqTSPredictionOutput, Tuple] |
Example
>>> from huggingface_hub import hf_hub_download
...
>>> from transformers import AutoformerForPrediction
...
>>> file = hf_hub_download(
... repo_id="hf-internal-testing/tourism-monthly-batch", filename="train-batch.pt", repo_type="dataset"
... )
>>> batch = torch.load(file)
...
>>> model = AutoformerForPrediction.from_pretrained("huggingface/autoformer-tourism-monthly")
...
>>> # during training, one provides both past and future values
>>> # as well as possible additional features
>>> outputs = model(
... past_values=batch["past_values"],
... past_time_features=batch["past_time_features"],
... past_observed_mask=batch["past_observed_mask"],
... static_categorical_features=batch["static_categorical_features"],
... static_real_features=batch["static_real_features"],
... future_values=batch["future_values"],
... future_time_features=batch["future_time_features"],
... )
...
>>> loss = outputs.loss
>>> loss.backward()
...
>>> # during inference, one only provides past values
>>> # as well as possible additional features
>>> # the model autoregressively generates future values
>>> outputs = model.generate(
... past_values=batch["past_values"],
... past_time_features=batch["past_time_features"],
... past_observed_mask=batch["past_observed_mask"],
... static_categorical_features=batch["static_categorical_features"],
... static_real_features=batch["static_real_features"],
... future_time_features=batch["future_time_features"],
... )
...
>>> mean_prediction = outputs.sequences.mean(dim=1)
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.generate(past_values, past_time_features, future_time_features, past_observed_mask=None, static_categorical_features=None, static_real_features=None, output_attentions=None, output_hidden_states=None)
¶
Greedily generate sequences of sample predictions from a model with a probability distribution head.
PARAMETER | DESCRIPTION |
---|---|
past_values |
Past values of the time series, that serve as context in order to predict the future. The sequence size
of this tensor must be larger than the The The Optionally, missing values need to be replaced with zeros and indicated via the For multivariate time series, the
TYPE:
|
past_time_features |
Required time features, which the model internally will add to These features serve as the "positional encodings" of the inputs. So contrary to a model like BERT,
where the position encodings are learned from scratch internally as parameters of the model, the Time
Series Transformer requires to provide additional time features. The Time Series Transformer only
learns additional embeddings for Additional dynamic real covariates can be concatenated to this tensor, with the caveat that these features must but known at prediction time. The
TYPE:
|
future_time_features |
Required time features for the prediction window, which the model internally will add to sampled predictions. These could be things like "month of year", "day of the month", etc. encoded as vectors (for instance as Fourier features). These could also be so-called "age" features, which basically help the model know "at which point in life" a time-series is. Age features have small values for distant past time steps and increase monotonically the more we approach the current time step. Holiday features are also a good example of time features. These features serve as the "positional encodings" of the inputs. So contrary to a model like BERT,
where the position encodings are learned from scratch internally as parameters of the model, the Time
Series Transformer requires to provide additional time features. The Time Series Transformer only
learns additional embeddings for Additional dynamic real covariates can be concatenated to this tensor, with the caveat that these features must but known at prediction time. The
TYPE:
|
past_observed_mask |
Boolean mask to indicate which
TYPE:
|
static_categorical_features |
Optional static categorical features for which the model will learn an embedding, which it will add to the values of the time series. Static categorical features are features which have the same value for all time steps (static over time). A typical example of a static categorical feature is a time series ID.
TYPE:
|
static_real_features |
Optional static real features which the model will add to the values of the time series. Static real features are features which have the same value for all time steps (static over time). A typical example of a static real feature is promotion information.
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers.
TYPE:
|
Return
[SampleTSPredictionOutput
] where the outputs sequences
tensor will have shape (batch_size, number of
samples, prediction_length)
or (batch_size, number of samples, prediction_length, input_size)
for
multivariate predictions.
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.get_decoder()
¶
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2085 2086 2087 2088 2089 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.get_encoder()
¶
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2079 2080 2081 2082 2083 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.output_distribution(params, loc=None, scale=None, trailing_n=None)
¶
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2091 2092 2093 2094 2095 2096 2097 2098 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerForPrediction.output_params(decoder_output)
¶
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
2073 2074 2075 2076 2077 |
|
mindnlp.transformers.models.autoformer.modeling_autoformer.AutoformerPreTrainedModel
¶
Bases: PreTrainedModel
todo add docstring¶
Source code in mindnlp/transformers/models/autoformer/modeling_autoformer.py
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 |
|