Skip to content

Commit

Permalink
Don't pass serialized LitType metadata from the Python back-end, now …
Browse files Browse the repository at this point in the history
…that there are compatible type structures in the front-end.

PiperOrigin-RevId: 464620126
  • Loading branch information
cjqian authored and LIT team committed Aug 1, 2022
1 parent b165b28 commit ef72bfc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 45 deletions.
32 changes: 0 additions & 32 deletions lit_nlp/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ def from_json(d: JsonDict):
del d["__mro__"]
return cls(**d)

# TODO(b/162269499): remove this once we have a proper implementation of
# these types on the frontend.
@classmethod
def cls_to_json(cls) -> JsonDict:
"""Serialize class info to JSON."""
d = {}
d["__class__"] = "type"
d["__name__"] = cls.__name__
# All parent classes, from method resolution order (mro).
# Use this to check inheritance on the frontend.
d["__mro__"] = [a.__name__ for a in cls.mro()]
return d


Spec = Dict[Text, LitType]

Expand Down Expand Up @@ -118,25 +105,6 @@ def remap_spec(spec: Spec, keymap: Dict[str, str]) -> Spec:
return ret


# TODO(b/162269499): remove this once we have a proper implementation of
# these types on the frontend.
def all_littypes(ignore_private=True):
"""Return json of class info for all LitType classes."""

def all_subclasses(cls):
# pylint: disable=g-complex-comprehension
types_set = set(cls.__subclasses__()).union(
[s for c in cls.__subclasses__() for s in all_subclasses(c)])
# pylint: enable=g-complex-comprehension
return list(types_set)

classes = all_subclasses(LitType)
if ignore_private:
classes = [c for c in classes if not c.__name__.startswith("_")]

return {cls.__name__: cls.cls_to_json() for cls in classes}


##
# Concrete type clases
# LINT.IfChange
Expand Down
18 changes: 10 additions & 8 deletions lit_nlp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def _build_metadata(self):
'generators': generator_info,
'interpreters': interpreter_info,
'layouts': self._layouts,
'littypes': types.all_littypes(),
# Global configuration
'demoMode': self._demo_mode,
'defaultLayout': self._default_layout,
Expand Down Expand Up @@ -208,7 +207,9 @@ def _get_preds(self,
ret = [utils.filter_by_keys(p, ret_keys.__contains__) for p in preds]
return ret

def _annotate_new_data(self, data, dataset_name: Optional[Text] = None,
def _annotate_new_data(self,
data,
dataset_name: Optional[Text] = None,
**unused_kw) -> List[IndexedInput]:
"""Fill in index and other extra data for the provided datapoints."""
# TODO(lit-dev): unify this with hash fn on dataset objects.
Expand Down Expand Up @@ -291,7 +292,8 @@ def annotate_generated(datapoints):
return annotated_dataset.examples

annotated_generated = [
annotate_generated(generated) for generated in all_generated]
annotate_generated(generated) for generated in all_generated
]

# Add metadata.
all_generated_indexed: List[List[IndexedInput]] = [
Expand Down Expand Up @@ -362,8 +364,8 @@ def _warm_projections(self, interpreters: List[Text]):
_ = self._get_interpretations(
data, model, dataset_name, interpreter=interpreter_name)

def _run_annotators(
self, dataset: lit_dataset.Dataset) -> lit_dataset.Dataset:
def _run_annotators(self,
dataset: lit_dataset.Dataset) -> lit_dataset.Dataset:
datapoints = [dict(ex) for ex in dataset.examples]
annotated_spec = dict(dataset.spec())
for annotator in self._annotators:
Expand Down Expand Up @@ -521,9 +523,9 @@ def __init__(
'pca': projection.ProjectionManager(pca.PCAModel),
'umap': projection.ProjectionManager(umap.UmapModel),
}
self._interpreters = dict(
**self._interpreters, **prediction_analysis_interpreters,
**embedding_based_interpreters)
self._interpreters = dict(**self._interpreters,
**prediction_analysis_interpreters,
**embedding_based_interpreters)

# Information on models, datasets, and other components.
self._info = self._build_metadata()
Expand Down
3 changes: 0 additions & 3 deletions lit_nlp/client/lib/testing_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ export const mockMetadata: LitMetadata = {
'umap': emptySpec(),
},
'layouts': {},
'littypes': {
'Scalar': createLitType('Scalar'),
},
'demoMode': false,
'defaultLayout': 'default',
'canonicalURL': undefined
Expand Down
1 change: 0 additions & 1 deletion lit_nlp/client/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export interface LitMetadata {
generators: ComponentInfoMap;
interpreters: ComponentInfoMap;
layouts: LitComponentLayouts;
littypes: Spec;
demoMode: boolean;
defaultLayout: string;
canonicalURL?: string;
Expand Down
1 change: 0 additions & 1 deletion lit_nlp/client/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export function deserializeLitTypesInLitMetadata(metadata: LitMetadata):
deserializeLitTypesInSpec(metadata.interpreters[interpreter].metaSpec);
}

metadata.littypes = deserializeLitTypesInSpec(metadata.littypes);
return metadata;
}

Expand Down

0 comments on commit ef72bfc

Please sign in to comment.