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

Method decode

addition-rnn-webworker/worker.js:86–98  ·  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

84 * @returns The decoded string.
85 */
86 decode(x, calcArgmax = true) {
87 return tf.tidy(() => {
88 if (calcArgmax) {
89 x = x.argMax(1);
90 }
91 const xData = x.dataSync(); // TODO(cais): Performance implication?
92 let output = '';
93 for (const index of Array.from(xData)) {
94 output += this.indicesChar[index];
95 }
96 return output;
97 });
98 }
99}
100
101/**

Callers 1

trainMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected