-
Notifications
You must be signed in to change notification settings - Fork 445
[WIP] Adding a sinusoidal temporal embedding #2826
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
base: main
Are you sure you want to change the base?
Conversation
self, | ||
period: pd.Timedelta, | ||
time_key: str = 'time', | ||
out_key: str = 'time_embedding', |
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.
Let's split the output into two keys. May not even need an out_key
parameter. Could just use f"sin_{time_key}"
and f"cos_{time_key}"
.
@@ -41,3 +41,22 @@ def test_rearrange_integration_in_augmentation_sequential() -> None: | |||
out_batch = train_transforms(batch) | |||
assert 'image' in out_batch | |||
assert out_batch['image'].shape == (b, t * c, h, w) | |||
|
|||
|
|||
def test_temporal_embedding_shape_and_values() -> None: |
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.
Let's also test the values themselves. They should be bounded between [-1, 1]. It may be useful to check math.isclose(output, expected)
for a real number to make sure we do the pd.Timestamp <-> float
conversion correctly, as I noticed that it isn't exactly intuitive and can be bug prone.
|
||
|
||
class CyclicalEncoder(nn.Module): | ||
"""Generic sinusoidal embedding for periodic temporal features.""" |
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.
.. versionadded:: 0.8
Let's make this even more generic. The same kind of encoder should work for lat/lon, not just time. |
Adding a generic cyclic/periodic embedding where the user inputs the period length and gets back sin/cos. #2382