in code/scripts/layers.py [0:0]
def __init__(self, units=None, luong_style=False, scaled=True, normalized=False, use_bias=True,
dropout=0.0, temperature=1.0, weight_initializer=None, bias_initializer='zeros',
prefix=None, params=None):
super(ScaledDotProductAttentionCell, self).__init__(prefix=prefix, params=params)
self._units = units
self._scaled = scaled
self._normalized = normalized
self._use_bias = use_bias
self._luong_style = luong_style
self._dropout = dropout
self._temperature = temperature
if self._luong_style:
assert units is not None, 'Luong style attention is not available without explicitly ' \
'setting the units'
with self.name_scope():
self._dropout_layer = nn.Dropout(dropout)
if units is not None:
with self.name_scope():
self._proj_query = nn.Dense(units=self._units, use_bias=self._use_bias,
flatten=False, weight_initializer=weight_initializer,
bias_initializer=bias_initializer, prefix='query_')
if not self._luong_style:
self._proj_key = nn.Dense(units=self._units, use_bias=self._use_bias,
flatten=False, weight_initializer=weight_initializer,
bias_initializer=bias_initializer, prefix='key_')
if self._normalized:
with self.name_scope():
self._l2_norm = L2Normalization(axis=-1)