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

Function loadData

sentiment/data.js:220–239  ·  view source on GitHub ↗
(numWords, len, multihot = false)

Source from the content-addressed store, hash-verified

218 * yTest: The same as `yTrain`, but for the test dataset.
219 */
220export async function loadData(numWords, len, multihot = false) {
221 const dataDir = await maybeDownloadAndExtract();
222
223 const trainFeaturePath = path.join(dataDir, 'imdb_train_data.bin');
224 const xTrain = loadFeatures(trainFeaturePath, numWords, len, multihot);
225 const testFeaturePath = path.join(dataDir, 'imdb_test_data.bin');
226 const xTest = loadFeatures(testFeaturePath, numWords, len, multihot);
227 const trainTargetsPath = path.join(dataDir, 'imdb_train_targets.bin');
228 const yTrain = loadTargets(trainTargetsPath);
229 const testTargetsPath = path.join(dataDir, 'imdb_test_targets.bin');
230 const yTest = loadTargets(testTargetsPath);
231
232 tf.util.assert(
233 xTrain.shape[0] === yTrain.shape[0],
234 `Mismatch in number of examples between xTrain and yTrain`);
235 tf.util.assert(
236 xTest.shape[0] === yTest.shape[0],
237 `Mismatch in number of examples between xTest and yTest`);
238 return {xTrain, yTrain, xTest, yTest};
239}
240
241/**
242 * Load a metadata template by downloading and extracting files if necessary.

Callers 2

data_test.jsFile · 0.90
mainFunction · 0.90

Calls 3

maybeDownloadAndExtractFunction · 0.85
loadFeaturesFunction · 0.85
loadTargetsFunction · 0.85

Tested by

no test coverage detected