-
Notifications
You must be signed in to change notification settings - Fork 1
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
add per indicator thrsholding and new dump #1073
Open
CarsonDavis
wants to merge
1
commit into
dev
Choose a base branch
from
add_per_indicator_thresholding
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
inferences are supplied by the classification model. the contact point is Bishwas | ||
cmr is supplied by running | ||
github.com/NASA-IMPACT/llm-app-EJ-classifier/blob/develop/scripts/data_processing/download_cmr.py | ||
move to the serve like this: scp ej_dump_20240814_143036.json sde:/home/ec2-user/sde_indexing_helper/backups/ | ||
move to the server like this: scp ej_dump_20241017_133151.json sde:/home/ec2-user/sde_indexing_helper/backups/ | ||
""" | ||
|
||
import json | ||
|
@@ -19,20 +19,22 @@ def save_to_json(data: dict | list, file_path: str) -> None: | |
json.dump(data, file, indent=2) | ||
|
||
|
||
def process_classifications(predictions: list[dict[str, float]], threshold: float = 0.5) -> list[str]: | ||
def process_classifications(predictions: list[dict[str, float]], thresholds: dict[str, float]) -> list[str]: | ||
""" | ||
Process the predictions and classify as follows: | ||
1. If 'Not EJ' is the highest scoring prediction, return 'Not EJ' as the only classification | ||
2. Filter classifications based on the threshold, excluding 'Not EJ' | ||
3. Default to 'Not EJ' if no classifications meet the threshold | ||
Process the predictions and classify based on the individual thresholds per indicator: | ||
1. If 'Not EJ' is the highest scoring prediction, return 'Not EJ' as the only classification. | ||
2. Filter classifications based on their individual thresholds, excluding 'Not EJ'. | ||
3. Default to 'Not EJ' if no classifications meet the threshold. | ||
""" | ||
highest_prediction = max(predictions, key=lambda x: x["score"]) | ||
|
||
if highest_prediction["label"] == "Not EJ": | ||
return ["Not EJ"] | ||
|
||
classifications = [ | ||
pred["label"] for pred in predictions if pred["score"] >= threshold and pred["label"] != "Not EJ" | ||
pred["label"] | ||
for pred in predictions | ||
if pred["score"] >= thresholds[pred["label"]] and pred["label"] != "Not EJ" | ||
] | ||
|
||
return classifications if classifications else ["Not EJ"] | ||
|
@@ -63,14 +65,14 @@ def remove_unauthorized_classifications(classifications: list[str]) -> list[str] | |
def update_cmr_with_classifications( | ||
inferences: list[dict[str, dict]], | ||
cmr_dict: dict[str, dict[str, dict]], | ||
threshold: float = 0.5, | ||
thresholds: dict[str, float], | ||
) -> list[dict[str, dict]]: | ||
"""Update CMR data with valid classifications based on inferences.""" | ||
|
||
predicted_cmr = [] | ||
|
||
for inference in inferences: | ||
classifications = process_classifications(predictions=inference["predictions"], threshold=threshold) | ||
classifications = process_classifications(predictions=inference["predictions"], thresholds=thresholds) | ||
classifications = remove_unauthorized_classifications(classifications) | ||
|
||
if classifications: | ||
|
@@ -84,17 +86,30 @@ def update_cmr_with_classifications( | |
|
||
|
||
def main(): | ||
inferences = load_json_file("cmr-inference.json") | ||
thresholds = { | ||
"Not EJ": 0.80, | ||
"Climate Change": 0.95, | ||
"Disasters": 0.80, | ||
"Extreme Heat": 0.50, | ||
"Food Availability": 0.80, | ||
"Health & Air Quality": 0.90, | ||
"Human Dimensions": 0.80, | ||
"Urban Flooding": 0.50, | ||
"Water Availability": 0.80, | ||
} | ||
Comment on lines
+89
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to config or somewhere more visible / elegant / configurable |
||
|
||
inferences = load_json_file("alpha-1.3-wise-vortex-42-predictions.json") | ||
cmr = load_json_file("cmr_collections_umm_20240807_142146.json") | ||
|
||
cmr_dict = create_cmr_dict(cmr) | ||
|
||
predicted_cmr = update_cmr_with_classifications(inferences=inferences, cmr_dict=cmr_dict, threshold=0.8) | ||
predicted_cmr = update_cmr_with_classifications(inferences=inferences, cmr_dict=cmr_dict, thresholds=thresholds) | ||
|
||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
file_name = f"ej_dump_{timestamp}.json" | ||
|
||
save_to_json(predicted_cmr, file_name) | ||
print(f"Saved to {file_name}") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double extension?