-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix scaling for MQ-(C|R)NN when distribution outputs are used #1070
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,18 +50,18 @@ class ForkingSeq2SeqNetworkBase(gluon.HybridBlock): | |
distribution output | ||
context_length: int, | ||
length of the encoding sequence. | ||
num_forking: int, | ||
decides how much forking to do in the decoder. 1 reduces to seq2seq and enc_len reduces to MQ-C(R)NN. | ||
cardinality: List[int], | ||
number of values of each categorical feature. | ||
embedding_dimension: List[int], | ||
dimension of the embeddings for categorical features. | ||
scaling | ||
Whether to automatically scale the target values. (default: False) | ||
Whether to automatically scale the target values. (default: True) | ||
scaling_decoder_dynamic_feature | ||
Whether to automatically scale the dynamic features for the decoder. (default: False) | ||
dtype | ||
(default: np.float32) | ||
num_forking: int, | ||
decides how much forking to do in the decoder. 1 reduces to seq2seq and enc_len reduces to MQ-C(R)NN. | ||
kwargs: dict | ||
dictionary of Gluon HybridBlock parameters | ||
""" | ||
|
@@ -77,7 +77,7 @@ def __init__( | |
embedding_dimension: List[int], | ||
distr_output: Optional[DistributionOutput] = None, | ||
quantile_output: Optional[QuantileOutput] = None, | ||
scaling: bool = False, | ||
scaling: bool = True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update the default for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! |
||
scaling_decoder_dynamic_feature: bool = False, | ||
dtype: DType = np.float32, | ||
num_forking: Optional[int] = None, | ||
|
@@ -94,25 +94,20 @@ def __init__( | |
self.quantile_output = quantile_output | ||
self.scaling = scaling | ||
self.scaling_decoder_dynamic_feature = scaling_decoder_dynamic_feature | ||
self.scaling_decoder_dynamic_feature_axis = 1 | ||
self.dtype = dtype | ||
self.num_forking = ( | ||
num_forking if num_forking is not None else context_length | ||
) | ||
|
||
if self.scaling: | ||
self.scaler = MeanScaler(keepdims=True) | ||
self.scaler = MeanScaler() | ||
else: | ||
self.scaler = NOPScaler(keepdims=True) | ||
self.scaler = NOPScaler() | ||
|
||
if self.scaling_decoder_dynamic_feature: | ||
self.scaler_decoder_dynamic_feature = MeanScaler( | ||
keepdims=True, axis=self.scaling_decoder_dynamic_feature_axis | ||
) | ||
self.scaler_decoder_dynamic_feature = MeanScaler(axis=1) | ||
else: | ||
self.scaler_decoder_dynamic_feature = NOPScaler( | ||
keepdims=True, axis=self.scaling_decoder_dynamic_feature_axis | ||
) | ||
self.scaler_decoder_dynamic_feature = NOPScaler(axis=1) | ||
|
||
with self.name_scope(): | ||
if self.quantile_output: | ||
|
@@ -167,9 +162,7 @@ def get_decoder_network_output( | |
|
||
# in addition to embedding features, use the log scale as it can help prediction too | ||
# (batch_size, num_feat_static = sum(embedding_dimension) + 1) | ||
feat_static_real = F.concat( | ||
embedded_cat, F.log(scale.squeeze(axis=1)), dim=1 | ||
) | ||
feat_static_real = F.concat(embedded_cat, F.log(scale), dim=1) | ||
|
||
# Passing past_observed_values as a feature would allow the network to | ||
# make that distinction and possibly ignore the masked values. | ||
|
@@ -266,7 +259,9 @@ def hybrid_forward( | |
else: | ||
assert self.distr_output is not None | ||
distr_args = self.distr_args_proj(dec_output) | ||
distr = self.distr_output.distribution(distr_args, scale=scale) | ||
distr = self.distr_output.distribution( | ||
distr_args, scale=scale.expand_dims(axis=1) | ||
) | ||
loss = distr.loss(future_target) | ||
|
||
# mask the loss based on observed indicator | ||
|
@@ -361,7 +356,7 @@ def hybrid_forward( | |
------- | ||
distr_args: the parameters of distribution | ||
loc: an array of zeros with the same shape of scale | ||
scale: | ||
scale: | ||
""" | ||
|
||
dec_output, scale = self.get_decoder_network_output( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to turn on scaling of the dynamic features or this should be unrelated to the distribution change right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is unrelated maybe, we could do it but maybe as a separate story