(numWords, len, multihot = false)
| 218 | * yTest: The same as `yTrain`, but for the test dataset. |
| 219 | */ |
| 220 | export 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. |
no test coverage detected