Skip to content

Commit

Permalink
Merge pull request #301 from vishnukaushik/main
Browse files Browse the repository at this point in the history
Add Rouge score lens
  • Loading branch information
steffenslavetinsky authored Oct 27, 2023
2 parents 3bb12ed + c17b998 commit d0dc505
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"react-virtualized-auto-sizer": "^1.0.7",
"react-window": "^1.8.8",
"recharts": "^2.4.3",
"rouge": "^1.0.3",
"seedrandom": "^3.0.5",
"shallowequal": "^1.1.0",
"short-uuid": "^4.2.2",
Expand Down
22 changes: 18 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/lenses/RougeScoreLens.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Lens } from '../types';
import 'twin.macro';
import rouge from 'rouge';
import { formatNumber } from '../dataformat';

const RougeScoreLens: Lens = ({ values }) => {
const rouge1 = rouge.n(values[0], values[1], 1);
const rouge2 = rouge.n(values[0], values[1], 2);
return (
<div>
<div tw="text-sm truncate px-1 py-0.5 flex items-center h-full">
Rouge 1: {formatNumber(rouge1)}
</div>
<div tw="text-sm truncate px-1 py-0.5 flex items-center h-full">
Rouge 2: {formatNumber(rouge2)}
</div>
</div>
);
};

RougeScoreLens.key = 'RougeScoreView';
RougeScoreLens.dataTypes = ['str'];
RougeScoreLens.defaultHeight = 50;
RougeScoreLens.minHeight = 50;
RougeScoreLens.maxHeight = 100;
RougeScoreLens.multi = true;
RougeScoreLens.displayName = 'ROUGE Score';
RougeScoreLens.filterAllowedColumns = (allColumns, selectedColumns) => {
if (selectedColumns.length === 2) return [];
const selectedKeys = selectedColumns.map((selectedCol) => selectedCol.key);
return allColumns.filter(({ type, key }) => {
return type.kind === 'str' && !selectedKeys.includes(key);
});
};
RougeScoreLens.isSatisfied = (columns) => {
if (columns.length === 2) return true;
return false;
};
export default RougeScoreLens;
2 changes: 2 additions & 0 deletions src/lenses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SequenceLens from './SequenceLens';
import SpectrogramLens from './SpectrogramLens';
import TextLens from './TextLens';
import VideoLens from './VideoLens';
import RougeScoreLens from './RougeScoreLens';

export const ALL_LENSES = [
ArrayLens,
Expand All @@ -24,4 +25,5 @@ export const ALL_LENSES = [
HtmlLens,
MarkdownLens,
ScalarLens,
RougeScoreLens,
];
1 change: 1 addition & 0 deletions src/rougeScore.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'rouge';

0 comments on commit d0dc505

Please sign in to comment.