Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Change. #1347

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lit_nlp/api/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class TokenSalience(DataTuple):
salience: Sequence[float] # parallel to tokens


@attr.s(auto_attribs=True, frozen=True, slots=True)
class FrameSalience(DataTuple):
"""Dataclass for a salience map over frames in a video."""

salience: dict[str, float]


@attr.s(auto_attribs=True, frozen=True, slots=True)
class FeatureSalience(DataTuple):
"""Dataclass for a salience map over categorical and/or scalar features."""
Expand Down
7 changes: 7 additions & 0 deletions lit_nlp/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,13 @@ class ImageSalience(Salience):
signed: bool = False # If the returned values are signed.


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class FrameSalience(Salience):
"""Metadata about a returned frame salience map."""

default: dtypes.FrameSalience = None


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class SequenceSalience(Salience):
"""Metadata about a returned sequence salience map."""
Expand Down
5 changes: 5 additions & 0 deletions lit_nlp/client/lib/dtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export interface TokenSalience extends DataTuple {
salience: number[]; // Parallel to tokens.
}

/** Dataclass for a salience map over frames in a video. */
export interface FrameSalience extends DataTuple {
salience: {[key: string]: number};
}

/** Dataclass for a salience map over categorical and/or scalar features. */
export interface FeatureSalience extends DataTuple {
salience: {[key: string]: number};
Expand Down
10 changes: 9 additions & 1 deletion lit_nlp/client/lib/lit_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// their Python counterparts.
// tslint:disable:no-new-decorators class-name enforce-name-casing

import {AnnotationCluster, EdgeLabel, FeatureSalience as FeatureSalienceDType, ScoredTextCandidates, SequenceSalienceMap, SpanLabel, TokenSalience as TokenSalienceDType} from './dtypes';
import {AnnotationCluster, EdgeLabel, FeatureSalience as FeatureSalienceDType, ScoredTextCandidates, SequenceSalienceMap, SpanLabel, TokenSalience as TokenSalienceDType, FrameSalience as FrameSalienceDType} from './dtypes';

/**
* A dictionary of registered LitType names mapped to their constructor.
Expand Down Expand Up @@ -534,6 +534,14 @@ export class TokenSalience extends Salience {
override default: TokenSalienceDType|undefined = undefined;
}

/**
* Metadata about a returned token salience map.
*/
@registered
export class FrameSalience extends Salience {
override default: FrameSalienceDType |undefined = undefined;
}

/**
* Metadata about a returned feature salience map.
*/
Expand Down
4 changes: 2 additions & 2 deletions lit_nlp/client/modules/salience_map_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {LitModule} from '../core/lit_module';
import {LegendType} from '../elements/color_legend';
import {InterpreterClick} from '../elements/interpreter_controls';
import {TokenWithWeight} from '../elements/token_chips';
import {FeatureSalience, FieldMatcher, ImageGradients, ImageSalience, LitTypeTypesList, LitTypeWithParent, MulticlassPreds, RegressionScore, Salience, SalienceTargetInfo, TokenGradients, TokenSalience} from '../lib/lit_types';
import {FeatureSalience, FieldMatcher, ImageGradients, FrameSalience, ImageSalience, LitTypeTypesList, LitTypeWithParent, MulticlassPreds, RegressionScore, Salience, SalienceTargetInfo, TokenGradients, TokenSalience} from '../lib/lit_types';
import {styles as sharedStyles} from '../lib/shared_styles.css';
import {CallConfig, IndexedInput, ModelInfoMap, Preds, SCROLL_SYNC_CSS_CLASS, Spec} from '../lib/types';
import {argmax, cloneSpec, findSpecKeys, makeModifiedInput} from '../lib/utils';
Expand Down Expand Up @@ -69,7 +69,7 @@ type SalienceResult = TokenSalienceResult | ImageSalienceResult |

// Notably, not SequenceSalience as that is handled by a different module.
const SUPPORTED_SALIENCE_TYPES =
[TokenSalience, FeatureSalience, ImageSalience];
[TokenSalience, FeatureSalience, ImageSalience, FrameSalience];

const TARGET_SELECTOR_SUPPORTED_TYPES: LitTypeTypesList =
[MulticlassPreds, RegressionScore];
Expand Down