* 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)
| 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 | /** |