forked from rai-project/mlmodelscope
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed text-classification modality (#24)
* Completed text-classification modality * Refactored textClassification output element
- Loading branch information
1 parent
ffe436d
commit 24cb796
Showing
12 changed files
with
325 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/components/Experiment/QuickOutput/Outputs/TextClassification/TextClassificationOutput.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import TopPrediction from "../Classification/TopPrediction"; | ||
import "../Classification/ClassificationOutput.scss"; | ||
import PredictionExpander from "../../../../Common/PredictionExpander"; | ||
import NoPredictions from "../_Common/components/NoPredictions"; | ||
import Task from "../../../../../helpers/Task"; | ||
import OutputDuration from "../_Common/components/OutputDuration"; | ||
import DurationConverter from "../_Common/utils/DurationConverter"; | ||
import useBEMNaming from "../../../../../common/useBEMNaming"; | ||
import InputPreview from '../../InputPreview'; | ||
const defaultProps = { | ||
className: "text-classification-output", | ||
features: [] | ||
}; | ||
|
||
export default function TextClassificationOutput(givenProps) { | ||
const props = { ...defaultProps, ...givenProps }; | ||
const { getBlock, getElement } = useBEMNaming(props.className); | ||
const task = Task.text_classification; | ||
if(props?.trial?.results?.responses[0]?.features) { | ||
props.features = props?.trial.results.responses[0].features; | ||
} | ||
const getPredictionBody = () => { | ||
if (props.features.length > 0) | ||
return <div className={getElement('predictions')}> | ||
<TopPrediction hideRating={props.hideRating} feature={props.features[0]} /> | ||
<PredictionExpander predictions={props.features} /> | ||
</div>; | ||
|
||
return <NoPredictions modelId={props.modelId} />; | ||
}; | ||
return ( | ||
<div className={getBlock()}> | ||
<div className={getElement("title-row")}> | ||
<h3 className={getElement('title')}>Output</h3> | ||
{!props.hideDuration && | ||
<OutputDuration duration={DurationConverter(props.trial.results.duration)} /> | ||
} | ||
</div> | ||
<div className={getElement('subtitle')}>{task.outputText} | ||
</div> | ||
<InputPreview input={props.trial.inputs[0]} inputType="text" onBackClicked={props.onBackClicked} /> | ||
{getPredictionBody()} | ||
</div> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
...nts/Experiment/QuickOutput/Outputs/TextClassification/TextClassificationOutput.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import TextClassificationOutput from "./TextClassificationOutput"; | ||
import { TestTextClassificationOutput} from "./testData/testTextClassification"; | ||
|
||
export default { | ||
title: "Experiments/Quick Output/Text Classification", | ||
component: TextClassificationOutput, | ||
}; | ||
|
||
const template = (args) => <TextClassificationOutput {...args} />; | ||
|
||
export const Default = template.bind({}); | ||
Default.args = { trial: TestTextClassificationOutput }; |
55 changes: 55 additions & 0 deletions
55
...onents/Experiment/QuickOutput/Outputs/TextClassification/TextClassificationOutput.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import expect from 'expect'; | ||
import {shallow} from 'enzyme'; | ||
import ClassificationOutput from './ClassificationOutput'; | ||
import TopPrediction from "./TopPrediction"; | ||
import PredictionExpander from "../../../../Common/PredictionExpander"; | ||
import TestFeatures, {TestImageClassificationResult} from "./Features"; | ||
|
||
describe('Classification Output Component', () => { | ||
describe('Renders', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<ClassificationOutput trial={TestImageClassificationResult} features={TestFeatures} | ||
modelId={1}/>); | ||
}); | ||
|
||
it('with a container div', () => { | ||
expect(wrapper.at(0).type()).toBe('div'); | ||
expect(wrapper.at(0).prop('className')).toBe('classification-output'); | ||
}); | ||
|
||
it('with a title', () => { | ||
const titleElement = wrapper.childAt(0).childAt(0); | ||
expect(titleElement.type()).toBe('h3'); | ||
expect(titleElement.prop('className')).toBe('classification-output__title'); | ||
expect(titleElement.text()).toBe('Output'); | ||
}); | ||
|
||
it('with a subtitle', () => { | ||
expect(wrapper.childAt(1).type()).toBe('div'); | ||
expect(wrapper.childAt(1).prop('className')).toBe('classification-output__subtitle'); | ||
expect(wrapper.childAt(1).text()).toBe('How this model identified the object in this image:'); | ||
}); | ||
|
||
describe('with a list of predictions', () => { | ||
describe('beginning with the top prediction component', () => { | ||
it('that has been passed the first prediction', () => { | ||
const topPrediction = wrapper.childAt(2).childAt(0); | ||
|
||
expect(topPrediction.type()).toBe(TopPrediction); | ||
expect(topPrediction.prop('feature')).toBe(TestFeatures[0]); | ||
}); | ||
}); | ||
|
||
it('that shows a prediction expander', () => { | ||
const predictions = wrapper.childAt(2); | ||
|
||
expect(predictions.prop('className')).toBe('classification-output__predictions'); | ||
expect(predictions.childAt(1).type()).toBe(PredictionExpander); | ||
expect(predictions.childAt(1).prop('predictions')).toBe(TestFeatures); | ||
}); | ||
|
||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...ents/Experiment/QuickOutput/Outputs/TextClassification/testData/testTextClassification.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export const TestTextClassificationOutputGeneratedToken = { | ||
id: "sampleidhere" | ||
}; | ||
|
||
export const TestTextClassificationOutput = { | ||
id: "sampletesttextclassificationoutputidhere", | ||
inputs: ["The weather is very pleasant today."], | ||
completed_at: "2023-06-03T18:17:14.513854Z", | ||
results: { | ||
'duration': "9.216154124s", | ||
'duration_for_inference': "9.193807904s", | ||
'responses': [ | ||
{ | ||
|
||
'features': | ||
[ | ||
{ | ||
classification: { | ||
label: 'positive' | ||
}, | ||
"probability": 0.9846002459526062 | ||
}, | ||
{ | ||
classification: { | ||
"label": "neutral" | ||
}, | ||
"probability": 0.012036120519042015 | ||
|
||
}, | ||
{ | ||
classification: { | ||
"label": "negative" | ||
}, | ||
"probability": 0.0033636766020208597 | ||
} | ||
|
||
], | ||
'id': "sampletesttextclassificationoutputresponseidhere" | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.