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

Method decode

addition-rnn/index.js:94–106  ·  view source on GitHub ↗

* Convert a 2D tensor into a string with the CharacterTable's vocabulary. * * @param x Input 2D tensor. * @param calcArgmax Whether to perform `argMax` operation on `x` before * indexing into the `CharacterTable`'s vocabulary. * @returns The decoded string.

(x, calcArgmax = true)

Source from the content-addressed store, hash-verified

92 * @returns The decoded string.
93 */
94 decode(x, calcArgmax = true) {
95 return tf.tidy(() => {
96 if (calcArgmax) {
97 x = x.argMax(1);
98 }
99 const xData = x.dataSync(); // TODO(cais): Performance implication?
100 let output = '';
101 for (const index of Array.from(xData)) {
102 output += this.indicesChar[index];
103 }
104 return output;
105 });
106 }
107}
108
109/**

Callers 1

trainMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected