File size: 1,248 Bytes
ed9f15f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**

 * Postprocessing - Process model outputs

 */

import { LABEL_MAPPINGS } from '../config.js';
import { softmax } from '../utils/mathUtils.js';

/**

 * Postprocess classification results

 */
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]
    };
}

/**

 * Postprocess grading results

 */
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
    };
}