Skip to content

Commit

Permalink
Refactor FeatureType (#462)
Browse files Browse the repository at this point in the history
* fix bugs.

* add test

* move utils.serialization
  • Loading branch information
Yusuke Oda authored Sep 9, 2022
1 parent 7c1bbce commit df48ff1
Show file tree
Hide file tree
Showing 29 changed files with 625 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"metadata": {
"custom_features": {
"rel_type": {
"cls_name": "Value",
"dtype": "string",
"description": "symmetric or asymmetric",
"num_buckets": 2
Expand Down Expand Up @@ -160,4 +161,4 @@
"example_id": "10"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"metadata": {
"custom_features": {
"toy_string_feature": {
"cls_name": "Value",
"dtype": "string",
"description": "most specific (highest) entity type level of true tail entity",
"num_buckets": 8
},
"toy_float_feature": {
"cls_name": "Value",
"dtype": "float",
"description": "just a toy float feature for testing",
"num_buckets": 4
Expand Down Expand Up @@ -1215,4 +1217,4 @@
"example_id": "/m/099c8n\t/award/award_category/nominees./award/award_nomination/nominated_for\t/m/064lsn"
}
]
}
}
3 changes: 2 additions & 1 deletion data/system_outputs/fb15k-237/user-defined.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"metadata": {
"custom_features": {
"rel_type": {
"cls_name": "Value",
"dtype": "string",
"description": "symmetric or asymmetric",
"num_buckets": 2
Expand Down Expand Up @@ -160,4 +161,4 @@
"example_id": "10"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"custom_features": {
"example": {
"total_words": {
"cls_name": "Value",
"dtype": "float",
"description": "total number of words"
}
Expand Down
1 change: 1 addition & 0 deletions data/system_outputs/sst2_tabreg/sst2-tabreg-dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"custom_features": {
"example": {
"total_words": {
"cls_name": "Value",
"dtype": "float",
"description": "total number of words"
}
Expand Down
12 changes: 9 additions & 3 deletions explainaboard/analysis/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import explainaboard.analysis.bucketing
from explainaboard.analysis.case import AnalysisCase, AnalysisCaseCollection
from explainaboard.analysis.feature import FeatureType
from explainaboard.analysis.feature import FeatureType, get_feature_type_serializer
from explainaboard.analysis.performance import BucketPerformance, Performance
from explainaboard.metrics.metric import Metric, MetricConfig, MetricStats
from explainaboard.metrics.registry import metric_config_from_dict
from explainaboard.utils.logging import get_logger
from explainaboard.utils.typing_utils import unwrap, unwrap_generator
from explainaboard.utils.typing_utils import narrow, unwrap, unwrap_generator


@dataclass
Expand Down Expand Up @@ -325,7 +325,13 @@ class AnalysisLevel:

@staticmethod
def from_dict(dikt: dict):
features = {k: FeatureType.from_dict(v) for k, v in dikt['features'].items()}
ft_serializer = get_feature_type_serializer()

features = {
# See https://github.com/python/mypy/issues/4717
k: narrow(FeatureType, ft_serializer.deserialize(v)) # type: ignore
for k, v in dikt['features'].items()
}
metric_configs = [metric_config_from_dict(v) for v in dikt['metric_configs']]
return AnalysisLevel(
name=dikt['name'],
Expand Down
Loading

0 comments on commit df48ff1

Please sign in to comment.