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

Method encodeBatch

addition-rnn/index.js:70–84  ·  view source on GitHub ↗
(strings, numRows)

Source from the content-addressed store, hash-verified

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.

Callers 1

convertDataToTensorsFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected