MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / GetLastTimestepLayer

Class GetLastTimestepLayer

date-conversion-attention/model.js:25–49  ·  view source on GitHub ↗

* A custom layer used to obtain the last time step of an RNN sequential * output.

Source from the content-addressed store, hash-verified

23 * output.
24 */
25class GetLastTimestepLayer extends tf.layers.Layer {
26 constructor(config) {
27 super(config || {});
28 this.supportMasking = true;
29 }
30
31 computeOutputShape(inputShape) {
32 const outputShape = inputShape.slice();
33 outputShape.splice(outputShape.length - 2, 1);
34 return outputShape;
35 }
36
37 call(input) {
38 if (Array.isArray(input)) {
39 input = input[0];
40 }
41 const inputRank = input.shape.length;
42 tf.util.assert(inputRank === 3, `Invalid input rank: ${inputRank}`);
43 return input.gather([input.shape[1] - 1], 1).squeeze([1]);
44 }
45
46 static get className() {
47 return 'GetLastTimestepLayer';
48 }
49}
50tf.serialization.registerClass(GetLastTimestepLayer);
51
52/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected