|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { LABEL_MAPPINGS } from '../config.js';
|
|
|
import { softmax } from '../utils/mathUtils.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function postprocessClassification(results, mapping = LABEL_MAPPINGS.classifier) {
|
|
|
const logits = results.logits.data;
|
|
|
const probabilities = softmax(Array.from(logits));
|
|
|
const maxIndex = probabilities.indexOf(Math.max(...probabilities));
|
|
|
|
|
|
return {
|
|
|
label: mapping[maxIndex] || maxIndex.toString(),
|
|
|
confidence: probabilities[maxIndex]
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function postprocessGrading(results) {
|
|
|
const logits = results.logits.data;
|
|
|
const probabilities = softmax(Array.from(logits));
|
|
|
const maxIndex = probabilities.indexOf(Math.max(...probabilities));
|
|
|
|
|
|
const allPredictions = {};
|
|
|
probabilities.forEach((prob, idx) => {
|
|
|
const label = LABEL_MAPPINGS.grader[idx] || idx.toString();
|
|
|
allPredictions[label] = prob;
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
label: LABEL_MAPPINGS.grader[maxIndex] || maxIndex.toString(),
|
|
|
confidence: probabilities[maxIndex],
|
|
|
allPredictions: allPredictions
|
|
|
};
|
|
|
}
|
|
|
|