encode(str, numRows) {
    const buf = tf.buffer([numRows, this.size]);
    for (let i = 0; i < str.length; ++i) {
      const char = str[i];
      if (this.charIndices[char] == null) {
        throw new Error(`Unknown character: '${char}'`);
      }
      buf.set(1, i, this.charIndices[char]);
    }
    return buf.toTensor().as2D(numRows, this.size);
  }
Convert a string into a one-hot encoded tensor.

@param str The input string.
@param numRows Number of rows of the output tensor.
@returns The one-hot encoded 2D tensor.
@throws If `str` contains any characters outside the `CharacterTable`'s
  vocabulary.