-
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
want zoneout lstm supported #1867
Comments
I could handle it... |
really appreciated to it |
So far so good! Any ideas on how to test it? Input values, random seed, expected output values? |
speedy implement! given the same input and zero initial state, it outputs a tensor having element value either the same as lstm's or zero. |
Here it is! You can copy & paste the class into your code. Example of usage and tests are further down below. If everything work as intended we could incorporate it into TFA. import tensorflow as tf
from tensorflow.keras.layers import LSTMCell, RNN, LSTM
class ZoneoutLSTMCell(LSTMCell):
def __init__(
self,
units,
zoneout_h = 0,
zoneout_c = 0,
**kwargs
):
super().__init__(
units,
**kwargs
)
self.zoneout_h = zoneout_h
self.zoneout_c = zoneout_c
def _zoneout(self, t, tm1, rate, training):
dt = tf.cast(tf.random.uniform(t.shape) >= rate * training, t.dtype)
return dt*t + (1 - dt)*tm1
def call(self, inputs, states, training=None):
output, new_states = super().call(inputs, states, training)
h = self._zoneout(new_states[0], states[0], self.zoneout_h, training)
c = self._zoneout(new_states[1], states[1], self.zoneout_c, training)
return h, [h, c]
x = tf.constant([[[1., 2, 3, 4, 5]]])
initial_state = [tf.constant([[11., 12, 13]]), tf.constant([[14., 15, 16]])]
tf.random.set_seed(0)
l0 = LSTM(3, return_state=True)
y0 = l0(x, initial_state=initial_state, training=True)
tf.print(y0)
tf.random.set_seed(0)
l = RNN(ZoneoutLSTMCell(3, zoneout_h=.3, zoneout_c=.5), return_state=True)
y = l(x, initial_state=initial_state, training=True)
tf.print(y) |
you need to save zoneout_h and zoneout_c in operator's config dictionary. |
I get unsupported operand type(s) for *: 'float' and 'NoteType' at line "dt = tf.cast(tf.random.uniform(t.shape) >= rate * training, t.dtype)" |
Sure. The code above is just an algorithm implementation. If it is OK we can move forward.
Could you describe environment where it happened? |
sorry, I used the operator the wrong way. I can successfully run the code. |
@failure-to-thrive I found there is a flaw in your implement. the hidden in your implement is calculated from cell of lstm, but the hidden of zoneout lstm should be calculated from zoneouted cell. |
I've simply implemented the generalized form from the original academic paper. Although there are lots of variations which are mentioned in the paper too, I'm not sure whether all of them should be implemented in the scope of TFA. Any ideas? |
TensorFlow Addons is transitioning to a minimal maintenance and release mode. New features will not be added to this repository. For more information, please see our public messaging on this decision: Please consider sending feature requests / contributions to other repositories in the TF community with a similar charters to TFA: |
Describe the feature and the current behavior/state.
no zoneout lstm found in addons
Relevant information
Which API type would this fall under (layer, metric, optimizer, etc.)
tfa.layers
Who will benefit with this feature?
people implementing Tacotron2 with tf.keras API
Any other info.
The text was updated successfully, but these errors were encountered: