import React from 'react' ; import { Output } from '@allenai/tugboat/components' ; import { Model } from '@allenai/tugboat/lib' ; import { DebugInfo } from '../../components' ; import { Input , Prediction } from './types' ; interface Props { input : Input ; model : Model ; output : Prediction ; } export const Predictions = ( { input , model , output } ) => { return ( < Output . Section > < SummaryText output = { output } / > < DebugInfo input = { input } output = { output } model = { model } / > < /Output.Section>); } ; const SummaryText = ( { output } ) => { const [ positive , negative ] = output . probs ; const judgments = { negative : ( < span > the sentence has a < strong > negative < / strong > sentiment < /span>), positive : ( < span > the sentence has a < strong > positive < /strong> sentiment < /span>), } ; let judgment ; let confidence ; if ( negative > positive ) { judgment = judgments . negative ; confidence = negative ; } else { judgment = judgments . positive ; confidence = positive ; } const veryConfident = 0.75 ; const somewhatConfident = 0.5 ; let summaryText ; if ( confidence >= veryConfident ) { summaryText = ( < div > The model is < strong > very confident < /strong> that {judgment}. < /div>); } else if ( confidence >= somewhatConfident ) { summaryText = ( < div > The model is < strong > somewhat confident < /strong> that {judgment}. < /div>); } else { summaryText = < div > The model is not confident in its judgment . < /div>; } return ( < > < Output . SubSection > { summaryText } < /Output.SubSection> < />); } ;