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

Method encodeBatch

addition-rnn-webworker/worker.js:62–76  ·  view source on GitHub ↗
(strings, numRows)

Source from the content-addressed store, hash-verified

60 }
61
62 encodeBatch(strings, numRows) {
63 const numExamples = strings.length;
64 const buf = tf.buffer([numExamples, numRows, this.size]);
65 for (let n = 0; n < numExamples; ++n) {
66 const str = strings[n];
67 for (let i = 0; i < str.length; ++i) {
68 const char = str[i];
69 if (this.charIndices[char] == null) {
70 throw new Error(`Unknown character: '${char}'`);
71 }
72 buf.set(1, n, i, this.charIndices[char]);
73 }
74 }
75 return buf.toTensor().as3D(numExamples, numRows, this.size);
76 }
77
78 /**
79 * 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