phase 1
This commit is contained in:
21
scripts/predict_batch.ts
Normal file
21
scripts/predict_batch.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as tf from "@tensorflow/tfjs-node";
|
||||
import { readFile, writeFile, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
async function predictBatch() {
|
||||
const model = await tf.loadLayersModel("file://sample/model/model.json");
|
||||
const files = (await readdir("sample/output/factorize")).filter(f => f.endsWith(".json"));
|
||||
const results = [];
|
||||
|
||||
for (const file of files) {
|
||||
const data = JSON.parse(await readFile(join("sample/output/factorize", file), "utf-8"));
|
||||
for (const analysis of data.analysis) {
|
||||
const input = tf.tensor2d([Object.values(analysis.factors)]);
|
||||
const pred = (model.predict(input) as tf.Tensor).dataSync()[0];
|
||||
results.push({ title: data.title, file: data.file, course: analysis.difficulty, predicted: pred.toFixed(2) });
|
||||
}
|
||||
}
|
||||
await writeFile("sample/results.json", JSON.stringify(results, null, 2));
|
||||
console.log("Prediction complete.");
|
||||
}
|
||||
predictBatch().catch(console.error);
|
||||
Reference in New Issue
Block a user