MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / call

Method call

tensorflow/contrib/rnn/python/ops/rnn_cell.py:1194–1231  ·  view source on GitHub ↗

Long short-term memory cell with attention (LSTMA).

(self, inputs, state)

Source from the content-addressed store, hash-verified

1192 return self._attn_size
1193
1194 def call(self, inputs, state):
1195 """Long short-term memory cell with attention (LSTMA)."""
1196 if self._state_is_tuple:
1197 state, attns, attn_states = state
1198 else:
1199 states = state
1200 state = array_ops.slice(states, [0, 0], [-1, self._cell.state_size])
1201 attns = array_ops.slice(states, [0, self._cell.state_size],
1202 [-1, self._attn_size])
1203 attn_states = array_ops.slice(
1204 states, [0, self._cell.state_size + self._attn_size],
1205 [-1, self._attn_size * self._attn_length])
1206 attn_states = array_ops.reshape(attn_states,
1207 [-1, self._attn_length, self._attn_size])
1208 input_size = self._input_size
1209 if input_size is None:
1210 input_size = inputs.get_shape().as_list()[1]
1211 if self._linear1 is None:
1212 self._linear1 = _Linear([inputs, attns], input_size, True)
1213 inputs = self._linear1([inputs, attns])
1214 cell_output, new_state = self._cell(inputs, state)
1215 if self._state_is_tuple:
1216 new_state_cat = array_ops.concat(nest.flatten(new_state), 1)
1217 else:
1218 new_state_cat = new_state
1219 new_attns, new_attn_states = self._attention(new_state_cat, attn_states)
1220 with vs.variable_scope("attn_output_projection"):
1221 if self._linear2 is None:
1222 self._linear2 = _Linear([cell_output, new_attns], self._attn_size, True)
1223 output = self._linear2([cell_output, new_attns])
1224 new_attn_states = array_ops.concat(
1225 [new_attn_states, array_ops.expand_dims(output, 1)], 1)
1226 new_attn_states = array_ops.reshape(
1227 new_attn_states, [-1, self._attn_length * self._attn_size])
1228 new_state = (new_state, new_attns, new_attn_states)
1229 if not self._state_is_tuple:
1230 new_state = array_ops.concat(list(new_state), 1)
1231 return output, new_state
1232
1233 def _attention(self, query, attn_states):
1234 conv2d = nn_ops.conv2d

Callers

nothing calls this directly

Calls 11

_attentionMethod · 0.95
_LinearClass · 0.85
sliceMethod · 0.80
reshapeMethod · 0.80
_cellMethod · 0.80
variable_scopeMethod · 0.80
as_listMethod · 0.45
get_shapeMethod · 0.45
concatMethod · 0.45
flattenMethod · 0.45
expand_dimsMethod · 0.45

Tested by

no test coverage detected