MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / nextDataEpoch

Method nextDataEpoch

lstm-text-generation/data.js:130–150  ·  view source on GitHub ↗

* Generate the next epoch of data for training models. * * @param {number} numExamples Number examples to generate. * @returns {[tf.Tensor, tf.Tensor]} `xs` and `ys` Tensors. * `xs` has the shape of `[numExamples, this.sampleLen, this.charSetSize]`. * `ys` has the shape of `[numEx

(numExamples)

Source from the content-addressed store, hash-verified

128 * `ys` has the shape of `[numExamples, this.charSetSize]`.
129 */
130 nextDataEpoch(numExamples) {
131 this.generateExampleBeginIndices_();
132
133 if (numExamples == null) {
134 numExamples = this.exampleBeginIndices_.length;
135 }
136
137 const xsBuffer = new tf.TensorBuffer([
138 numExamples, this.sampleLen_, this.charSetSize_]);
139 const ysBuffer = new tf.TensorBuffer([numExamples, this.charSetSize_]);
140 for (let i = 0; i < numExamples; ++i) {
141 const beginIndex = this.exampleBeginIndices_[
142 this.examplePosition_ % this.exampleBeginIndices_.length];
143 for (let j = 0; j < this.sampleLen_; ++j) {
144 xsBuffer.set(1, i, j, this.indices_[beginIndex + j]);
145 }
146 ysBuffer.set(1, i, this.indices_[beginIndex + this.sampleLen_]);
147 this.examplePosition_++;
148 }
149 return [xsBuffer.toTensor(), ysBuffer.toTensor()];
150 }
151
152 /**
153 * Get the unique character at given index from the character set.

Callers 2

fitModelFunction · 0.80
data_test.jsFile · 0.80

Calls 1

Tested by

no test coverage detected