(strings, numRows)
| 68 | } |
| 69 | |
| 70 | encodeBatch(strings, numRows) { |
| 71 | const numExamples = strings.length; |
| 72 | const buf = tf.buffer([numExamples, numRows, this.size]); |
| 73 | for (let n = 0; n < numExamples; ++n) { |
| 74 | const str = strings[n]; |
| 75 | for (let i = 0; i < str.length; ++i) { |
| 76 | const char = str[i]; |
| 77 | if (this.charIndices[char] == null) { |
| 78 | throw new Error(`Unknown character: '${char}'`); |
| 79 | } |
| 80 | buf.set(1, n, i, this.charIndices[char]); |
| 81 | } |
| 82 | } |
| 83 | return buf.toTensor().as3D(numExamples, numRows, this.size); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Convert a 2D tensor into a string with the CharacterTable's vocabulary. |
no outgoing calls
no test coverage detected