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