-
Notifications
You must be signed in to change notification settings - Fork 613
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
Added support for noisy dense layers. #2099
Conversation
@facaiy @seanpmorgan please let me know if there are any problems or if you have any questions. Thanks! |
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 just figure out that lots of codes are copied from tf.keras.layers.Dense
. Therefore, a better design pattern is that
class NoisyDense(tf.keras.layers.Dense):
@typechecked
def __init__(
self,
units: int,
sigma: float = 0.5,
activation: types.Activation = None,
use_bias: bool = True,
kernel_regularizer: types.Regularizer = None,
bias_regularizer: types.Regularizer = None,
activity_regularizer: types.Regularizer = None,
kernel_constraint: types.Constraint = None,
bias_constraint: types.Constraint = None,
**kwargs
):
super().__init__(xxxx)
# DO OTHER THINGS
def build(self, input_shape):
# OVERRIDE
def reset_noise(self):
# DO SOMETHING
def remove_noise(self):
# DO SOMETHING
def call(self, inputs, reset_noise=True):
if reset_noise:
self.reset_noise()
# TODO(WindQAQ): Replace this with `dense()` once public.
# prepare your self.kernel, self.bias here.
return super().call(inputs)
def get_config(self):
# OVERRIDE
Regarding the |
Just pass them as |
Also, what would you like me to do about |
config = super().get_config()
config.pop("foo") # pop things you do not have
config["bar"] = bar # update things you have additionally
return config |
That will raise an error since Dense
|
Try this config = super(tf.keras.layers.Dense, self).get_config()
config["foo"] = foo # update your stuff or even hacking self.bar = None
config = super().get_config()
config.pop("bar")
config["foo"] = foo Both approaches are not so good to me, so please put https://colab.research.google.com/drive/14VzUnIZIDadej8s_fHlSKx-ieTs9rttV?usp=sharing |
The first method works well!
But is there a reason why you used |
Basically no. Just type in rush. |
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.
Some documentation improvement needed. Thanks.
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.
@LeonShams Sorry that this should be the last comment. Others LGTM! Thank you.
No worries, I made the changes, let me know if there is anything else. |
* Create noisy_dense.py * Create noisy_dense_test.py * Update __init__.py * Fix minor typo * Update noisy_dense_test.py * Update comments * Update comments * Update noisy_dense.py * fix typo * Update noisy_dense.py * Update noisy_dense_test.py * Fix compliance issues * Fix compliance issues * Update comments * Fix typo * Update CODEOWNERS * Update CODEOWNERS * add use bias to config * Update noisy_dense.py * Update CODEOWNERS * Revert "Update CODEOWNERS" This reverts commit 82e979f. * Update noisy_dense.py * Update noisy_dense.py * Update noisy_dense.py * Update noisy_dense.py * Revert "Update CODEOWNERS" This reverts commit 840ab1c. * Revert "Revert "Update CODEOWNERS"" This reverts commit 7852e62. * Update noisy_dense.py * Code reformatted with updated black * Update noisy_dense.py * Update noisy_dense.py * Update noisy_dense.py * Added support for manual noise reset * support for noise removal * tests for noise removal * use typecheck and remove unicode, * fix typo and code cleanup * control noise removal through call * Inherit from Dense instead of Layer * Added missing comment * Documentation and test improvement * fix typo * minor formatting changes * minor formatting fix Co-authored-by: schaall <[email protected]>
Description
This PR adds support for noisy dense layers. Noisy dense layers are like dense layers but random noise is injected to help agents explore in reinforcement learning environments. This is very commonly used in Deep Q Learning and was first introduced by DeepMind in their Noisy Networks for Exploration paper in 2017.
Fixes: #2127
Type of change
Checklist:
How Has This Been Tested?
I used PyTest to test the code and trained it on some reinforcement learning environments from the gym toolkit and compared my results to the results on the Noisy Networks for Exploration paper.