Skip to content

Commit

Permalink
Classification Results module presents results in a unified table for…
Browse files Browse the repository at this point in the history
… all models

and datapoints

PiperOrigin-RevId: 439550408
  • Loading branch information
RyanMullins authored and LIT team committed Apr 5, 2022
1 parent 0fe3c79 commit 4f2b53d
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 104 deletions.
60 changes: 60 additions & 0 deletions lit_nlp/client/elements/score_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {customElement} from 'lit/decorators';
import {css, html, LitElement} from 'lit';
import {styleMap} from 'lit/directives/style-map';

const PRED_TITLE = 'The predicted label';
const TRUTH_TITLE = 'The ground truth label';

/**
* A horizontal bar with a score label.
*/
Expand Down Expand Up @@ -68,8 +71,65 @@ export class ScoreBar extends LitElement {
}
}

/**
* A ScoreBar variant with annotations for the correct prediction and/or ground
* truth value (if provided).
*/
@customElement('annotated-score-bar')
export class AnnotatedScoreBar extends LitElement {
@property({type: Boolean}) hasTruth = false;
@property({type: Boolean}) isPredicted = false;
@property({type: Boolean}) isTruth = false;
@property({type: Number}) value = 0;

static override get styles() {
return css`
.annotated-cell{
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.indicator {
min-width: 16px;
text-align: center;
}`;
}

override render() {
return html`<div class="annotated-cell">
<score-bar score=${this.value} maxScore=${1}></score-bar>
<div class="indicator" title=${PRED_TITLE}>
${this.isPredicted ? 'P' : null}
</div>
${this.hasTruth ?
html`<div class="indicator" title=${TRUTH_TITLE}>
${this.isTruth ? 'T' : null}
</div>` : null}
</div>`;
}
}

/**
* A legend for use with the AnnotatedScoreBar.
*/
@customElement('annotated-score-bar-legend')
export class AnnotatedScoreBarLegend extends LitElement {
@property({type: Boolean}) hasTruth = false;

override render() {
return html`<span>
P = ${PRED_TITLE}
${this.hasTruth ? `, T = ${TRUTH_TITLE}` : ''}
</span>`;
}
}

declare global {
interface HTMLElementTagNameMap {
'annotated-score-bar': AnnotatedScoreBar;
'annotated-score-bar-legend': AnnotatedScoreBarLegend;
'score-bar': ScoreBar;
}
}

0 comments on commit 4f2b53d

Please sign in to comment.