max_n for bleu score is now the smallest number

between the number of tokens in candidate, reference or 4
This commit is contained in:
Karma Riuk
2025-05-11 09:34:56 +02:00
parent f03e95cd58
commit 686500fc2e

View File

@ -20,6 +20,7 @@ export const evaluate_comments = (answers, percent_cb) => {
let i = 0; let i = 0;
const results = {}; const results = {};
for (const [id, generated_comment] of Object.entries(answers)) { for (const [id, generated_comment] of Object.entries(answers)) {
const n_tokens_generated = generated_comment.trim().split(/\s+/).length;
// console.log(`Processing ${i} ${id}...`); // console.log(`Processing ${i} ${id}...`);
if (!(id in REFERENCE_MAP)) { if (!(id in REFERENCE_MAP)) {
// throw new Error(`id: "${id}" is not present in the dataset`); // throw new Error(`id: "${id}" is not present in the dataset`);
@ -31,7 +32,9 @@ export const evaluate_comments = (answers, percent_cb) => {
let maxScore = 0; let maxScore = 0;
const scores = []; const scores = [];
for (const paraphrase of paraphrases) { for (const paraphrase of paraphrases) {
const score = bleu(paraphrase, generated_comment, 4); // TODO: ask prof what number show be here const n_tokens_paraphrase = paraphrase.trim().split(/\s+/).length;
const max_n = Math.min(n_tokens_generated, n_tokens_paraphrase, 4);
const score = bleu(paraphrase, generated_comment, max_n);
scores.push(score); scores.push(score);
maxScore = Math.max(score, maxScore); maxScore = Math.max(score, maxScore);
} }