Skip to content

Commit

Permalink
Merge pull request #355 from Ashutosh-Kumar-Singh-IIT-Patna/bleu-scor…
Browse files Browse the repository at this point in the history
…e-metric

Bleu score metric
  • Loading branch information
neindochoh authored Dec 8, 2023
2 parents 0fd33d8 + b1fee14 commit eebd218
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/widgets/MetricsWidget/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash';
import levenshtein from 'fast-levenshtein';
import { Metric } from './types';
import { computeConfusion } from './confusion';
import { bleu } from 'bleu-score';
import rouge from 'rouge';

export const METRICS: Record<string, Metric> = {
Expand Down Expand Up @@ -99,6 +100,24 @@ export const METRICS: Record<string, Metric> = {
);
},
},
BLEU1: {
signature: {
X: ['str'],
Y: ['str'],
},
compute: ([actualValues, assignedValues]) => {
const scores = [];

for (let i = 0; i < actualValues.length; i++) {
const references = actualValues[i];
const candidate = assignedValues[i];
scores.push(bleu(references as string, candidate as string, 1));
}

const mean_bleu_score = _.mean(scores);
return mean_bleu_score;
},
},
ROUGE1: {
signature: {
X: 'str',
Expand Down

0 comments on commit eebd218

Please sign in to comment.