| 56 | ]) |
| 57 | |
| 58 | def call(self, input_seq, training): |
| 59 | batch_size = int(input_seq.shape[1]) |
| 60 | for c in self.cells: |
| 61 | state = c.zero_state(batch_size, tf.float32) |
| 62 | outputs = [] |
| 63 | input_seq = tf.unstack(input_seq, num=int(input_seq.shape[0]), axis=0) |
| 64 | for inp in input_seq: |
| 65 | output, state = c(inp, state) |
| 66 | outputs.append(output) |
| 67 | |
| 68 | input_seq = tf.stack(outputs, axis=0) |
| 69 | if training: |
| 70 | input_seq = tf.nn.dropout(input_seq, self.keep_ratio) |
| 71 | # Returning a list instead of a single tensor so that the line: |
| 72 | # y = self.rnn(y, ...)[0] |
| 73 | # in PTBModel.call works for both this RNN and CudnnLSTM (which returns a |
| 74 | # tuple (output, output_states). |
| 75 | return [input_seq] |
| 76 | |
| 77 | |
| 78 | class Embedding(layers.Layer): |