Skip to content

Commit

Permalink
Rename old sequence salience module.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 616272334
  • Loading branch information
iftenney authored and LIT team committed Mar 15, 2024
1 parent 3591e61 commit d108b59
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
11 changes: 6 additions & 5 deletions lit_nlp/api/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LitModuleName(dtypes.EnumSerializableAsValues, enum.Enum):
SalienceClusteringModule = 'salience-clustering-module'
SalienceMapModule = 'salience-map-module'
ScalarModule = 'scalar-module'
SequenceSalienceModule = 'sequence-salience-module'
LegacySequenceSalienceModule = 'legacy-sequence-salience-module'
SpanGraphGoldModule = 'span-graph-gold-module'
SpanGraphModule = 'span-graph-module'
SpanGraphGoldModuleVertical = 'span-graph-gold-module-vertical'
Expand Down Expand Up @@ -160,7 +160,7 @@ def to_json(self) -> dtypes.JsonDict:
],
'Sequence Salience': [
*MODEL_PREDS_MODULES,
modules.SequenceSalienceModule(requiredForTab=True),
modules.LegacySequenceSalienceModule(requiredForTab=True),
],
'Influence': [modules.TrainingDataAttributionModule],
},
Expand All @@ -173,7 +173,8 @@ def to_json(self) -> dtypes.JsonDict:
'A basic layout just containing a datapoint creator/editor, the '
'predictions, and the data table. There are also some visual '
'simplifications: the toolbar is hidden, and the modules are centered '
'on the page rather than being full width.'),
'on the page rather than being full width.'
),
)

THREE_PANEL_LAYOUT = LitCanonicalLayout(
Expand Down Expand Up @@ -202,7 +203,7 @@ def to_json(self) -> dtypes.JsonDict:
],
'Explanations': [
modules.SalienceMapModule,
modules.SequenceSalienceModule,
modules.LegacySequenceSalienceModule,
modules.AttentionModule,
modules.FeatureAttributionModule,
],
Expand Down Expand Up @@ -236,7 +237,7 @@ def to_json(self) -> dtypes.JsonDict:
'Explanations': [
*MODEL_PREDS_MODULES,
modules.SalienceMapModule,
modules.SequenceSalienceModule,
modules.LegacySequenceSalienceModule,
modules.AttentionModule,
modules.FeatureAttributionModule,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* @fileoverview Visualization for seq2seq salience maps.
*
* DEPRECATED; use sequence_salience_module.ts instead.
*/

import '../elements/switch';
Expand All @@ -22,7 +24,7 @@ import {styles as sharedStyles} from '../lib/shared_styles.css';
import {type IndexedInput, ModelInfoMap, type Spec} from '../lib/types';
import {sumArray} from '../lib/utils';

import {styles} from './sequence_salience_module.css';
import {styles} from './legacy_sequence_salience_module.css';

interface TokenFocusState {
idx: number; /* output token index */
Expand All @@ -37,28 +39,29 @@ enum ColorScalingMode {
}

const LEGEND_INFO_TITLE_SIGNED =
"Salience is relative to the model's prediction of a class. A positive " +
"score (more green) for a token means that token influenced the model to " +
"predict that class, whereas a negaitve score (more pink) means the " +
"token influenced the model to not predict that class.";
'Salience is relative to the model\'s prediction of a class. A positive ' +
'score (more green) for a token means that token influenced the model to ' +
'predict that class, whereas a negaitve score (more pink) means the ' +
'token influenced the model to not predict that class.';

const LEGEND_INFO_TITLE_UNSIGNED =
"Salience is relative to the model's prediction of a class. A larger " +
"score (more purple) for a token means that token was more influential " +
"on the model's prediction of that class.";
'Salience is relative to the model\'s prediction of a class. A larger ' +
'score (more purple) for a token means that token was more influential ' +
'on the model\'s prediction of that class.';

/** LIT module for model output. */
@customElement('sequence-salience-module')
export class SequenceSalienceModule extends LitModule {
static override title = 'Sequence Salience';
@customElement('legacy-sequence-salience-module')
export class LegacySequenceSalienceModule extends LitModule {
static override title = 'Sequence Salience (legacy)';
static override duplicateForExampleComparison = true;
static override duplicateForModelComparison = true;
static override numCols = 4;
static override template =
(model: string, selectionServiceIndex: number, shouldReact: number) => html`
<sequence-salience-module model=${model} .shouldReact=${shouldReact}
(model: string, selectionServiceIndex: number, shouldReact: number) =>
html`
<legacy-sequence-salience-module model=${model} .shouldReact=${shouldReact}
selectionServiceIndex=${selectionServiceIndex}>
</sequence-salience-module>`;
</legacy-sequence-salience-module>`;

static override get styles() {
return [sharedStyles, styles];
Expand Down Expand Up @@ -327,7 +330,7 @@ export class SequenceSalienceModule extends LitModule {
renderColorLegend() {
const cmap = this.cmap;
const isSigned = (cmap instanceof SignedSalienceCmap);
const labelName = "Token Salience";
const labelName = 'Token Salience';

const tooltipText =
isSigned ? LEGEND_INFO_TITLE_SIGNED : LEGEND_INFO_TITLE_UNSIGNED;
Expand Down Expand Up @@ -396,7 +399,8 @@ export class SequenceSalienceModule extends LitModule {
// clang-format on
}

static override shouldDisplayModule(modelSpecs: ModelInfoMap, datasetSpec: Spec) {
static override shouldDisplayModule(
modelSpecs: ModelInfoMap, datasetSpec: Spec) {
for (const modelInfo of Object.values(modelSpecs)) {
if (modelInfo.interpreters.indexOf('sequence_salience') !== -1) {
return true;
Expand All @@ -408,6 +412,6 @@ export class SequenceSalienceModule extends LitModule {

declare global {
interface HTMLElementTagNameMap {
'sequence-salience-module': SequenceSalienceModule;
'legacy-sequence-salience-module': LegacySequenceSalienceModule;
}
}
5 changes: 3 additions & 2 deletions lit_nlp/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@
modules.SimpleDatapointEditorModule,
*layout.MODEL_PREDS_MODULES,
modules.SalienceMapModule,
modules.SequenceSalienceModule,
modules.LegacySequenceSalienceModule,
modules.AttentionModule,
],
'Analysis': [
modules.MetricsModule,
modules.ConfusionMatrixModule,
modules.ScalarModule,
],
})
}
)


@attr.s(auto_attribs=True, kw_only=True)
Expand Down

0 comments on commit d108b59

Please sign in to comment.