Commit 65da4505 authored by Sebastian Nickels's avatar Sebastian Nickels

Added dropout parameter for RNNs

parent 58436d17
Pipeline #226554 failed with stages
in 18 seconds
...@@ -53,10 +53,10 @@ class Reshape(gluon.HybridBlock): ...@@ -53,10 +53,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -65,10 +65,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -65,10 +65,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -77,10 +77,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -77,10 +77,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<#if mode == "ARCHITECTURE_DEFINITION"> <#if mode == "ARCHITECTURE_DEFINITION">
self.${element.name} = CustomGRU(hidden_size=${element.units?c}, self.${element.name} = CustomGRU(hidden_size=${element.units?c},
num_layers=${element.layers?c}, num_layers=${element.layers?c},
dropout=${element.dropout?c},
bidirectional=${element.bidirectional?string("True", "False")}) bidirectional=${element.bidirectional?string("True", "False")})
<#include "OutputShape.ftl"> <#include "OutputShape.ftl">
<#elseif mode == "FORWARD_FUNCTION"> <#elseif mode == "FORWARD_FUNCTION">
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<#if mode == "ARCHITECTURE_DEFINITION"> <#if mode == "ARCHITECTURE_DEFINITION">
self.${element.name} = CustomLSTM(hidden_size=${element.units?c}, self.${element.name} = CustomLSTM(hidden_size=${element.units?c},
num_layers=${element.layers?c}, num_layers=${element.layers?c},
dropout=${element.dropout?c},
bidirectional=${element.bidirectional?string("True", "False")}) bidirectional=${element.bidirectional?string("True", "False")})
<#include "OutputShape.ftl"> <#include "OutputShape.ftl">
<#elseif mode == "FORWARD_FUNCTION"> <#elseif mode == "FORWARD_FUNCTION">
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<#if mode == "ARCHITECTURE_DEFINITION"> <#if mode == "ARCHITECTURE_DEFINITION">
self.${element.name} = CustomRNN(hidden_size=${element.units?c}, self.${element.name} = CustomRNN(hidden_size=${element.units?c},
num_layers=${element.layers?c}, num_layers=${element.layers?c},
dropout=${element.dropout?c},
bidirectional=${element.bidirectional?string("True", "False")}) bidirectional=${element.bidirectional?string("True", "False")})
<#include "OutputShape.ftl"> <#include "OutputShape.ftl">
<#elseif mode == "FORWARD_FUNCTION"> <#elseif mode == "FORWARD_FUNCTION">
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock): ...@@ -52,10 +52,10 @@ class Reshape(gluon.HybridBlock):
class CustomRNN(gluon.HybridBlock): class CustomRNN(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomRNN, self).__init__(**kwargs) super(CustomRNN, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, self.rnn = gluon.rnn.RNN(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, activation='tanh', layout='NTC') bidirectional=bidirectional, activation='tanh', layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock): ...@@ -64,10 +64,10 @@ class CustomRNN(gluon.HybridBlock):
class CustomLSTM(gluon.HybridBlock): class CustomLSTM(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomLSTM, self).__init__(**kwargs) super(CustomLSTM, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, self.lstm = gluon.rnn.LSTM(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0, state1): def hybrid_forward(self, F, data, state0, state1):
...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock): ...@@ -76,10 +76,10 @@ class CustomLSTM(gluon.HybridBlock):
class CustomGRU(gluon.HybridBlock): class CustomGRU(gluon.HybridBlock):
def __init__(self, hidden_size, num_layers, bidirectional, **kwargs): def __init__(self, hidden_size, num_layers, dropout, bidirectional, **kwargs):
super(CustomGRU, self).__init__(**kwargs) super(CustomGRU, self).__init__(**kwargs)
with self.name_scope(): with self.name_scope():
self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, self.gru = gluon.rnn.GRU(hidden_size=hidden_size, num_layers=num_layers, dropout=dropout,
bidirectional=bidirectional, layout='NTC') bidirectional=bidirectional, layout='NTC')
def hybrid_forward(self, F, data, state0): def hybrid_forward(self, F, data, state0):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment