-
Notifications
You must be signed in to change notification settings - Fork 0
Add refusal rate code #5
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
Open
aunell
wants to merge
1
commit into
main
Choose a base branch
from
fix_heatmap
base: main
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import os | ||
| import json | ||
| import zipfile | ||
| from collections import defaultdict | ||
|
|
||
| def count_sorry_in_json(json_path): | ||
| print(f" 🔍 Loading JSON: {json_path}") | ||
| with open(json_path, "r") as f: | ||
| data = json.load(f) | ||
| print(f" 📦 Loaded {len(data)} entries") | ||
|
|
||
| sorry_count = 0 | ||
| not_sorry_count = 0 | ||
| for item in data: | ||
| text = item.get("predicted_text", "") | ||
| if "sorry" in text.lower(): | ||
| sorry_count += 1 | ||
| else: | ||
| not_sorry_count += 1 | ||
|
|
||
| print(f" ✅ Finished: sorry={sorry_count}, not_sorry={not_sorry_count}\n") | ||
| return sorry_count, not_sorry_count | ||
|
|
||
| def find_display_prediction_jsons(root_dir): | ||
| print(f"🔎 Searching for display_predictions.json in {root_dir}") | ||
| json_paths = [] | ||
| for dirpath, _, filenames in os.walk(root_dir): | ||
| for filename in filenames: | ||
| if filename == "display_predictions.json": | ||
| full_path = os.path.join(dirpath, filename) | ||
| print(f" 📄 Found: {full_path}") | ||
| json_paths.append(full_path) | ||
| print(f"✅ Total files found: {len(json_paths)}\n") | ||
| return json_paths | ||
|
|
||
| def process_all_jsons(root_dir): | ||
| results = {} | ||
| json_paths = find_display_prediction_jsons(root_dir) | ||
|
|
||
| for json_path in json_paths: | ||
| folder = os.path.basename(os.path.dirname(json_path)) | ||
| print(f"\n📂 Processing folder: {folder}") | ||
| sorry, not_sorry = count_sorry_in_json(json_path) | ||
| if sorry!=0: | ||
| results[folder] = {"sorry": sorry, "not_sorry": not_sorry} | ||
|
|
||
| return results | ||
|
|
||
| def extract_and_process_zip(zip_path): | ||
| print(f"\n📦 Extracting ZIP archive: {zip_path}") | ||
| extract_path = "/tmp/benchmark_unzipped" | ||
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | ||
| zip_ref.extractall(extract_path) | ||
| print(f"✅ Extracted to {extract_path}\n") | ||
| return process_all_jsons(extract_path) | ||
|
|
||
| if __name__ == "__main__": | ||
| # Step 1: Process the zip file | ||
| zip_path = "/share/pi/nigam/data/medhelm/release/v2/benchmark_output_unredacted_20250512_060221.zip" | ||
|
Collaborator
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. Let's use the |
||
| print("\n====== Step 1: ZIP File Processing ======") | ||
| zip_results = extract_and_process_zip(zip_path) | ||
| print("\n📊 Results from ZIP:") | ||
| print(json.dumps(zip_results, indent=2)) | ||
|
|
||
| # Step 2: Process local benchmark output folder | ||
| run_root = "../medhelm/data/benchmark_output/runs/" | ||
| print("\n====== Step 2: Local Folder Processing ======") | ||
| folder_results = process_all_jsons(run_root) | ||
| print("\n📊 Results from benchmark_output/runs:") | ||
| print(json.dumps(folder_results, indent=2)) | ||
|
|
||
| json.dump(folder_results, open("../medhelm/refusal_rate.json", "w")) | ||
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.
Instead of just using the word
sorry, let's not count the instances where the following strings appears in text.lower():sorry to hearsorry for yourIn such cases, the model is being empathetic in its response.