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

Refactor FeatureType #462

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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