generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Create function to assess valueset accuracy #175
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
robertandremitchell
wants to merge
22
commits into
main
Choose a base branch
from
rob/173-create-functions-to-assess-valueset-accuracy
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 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
299aa9a
changing var name per suggestion
robertandremitchell 204c037
Sample accuracy evaluation function
robertandremitchell 111567a
tinkering with second-degree match logic
robertandremitchell f20d3d3
dynamic file naming, creating utils.py, continuied thinking on accura…
robertandremitchell e2b697c
utils support for jsonl
robertandremitchell 5158357
Merge branch 'main' into rob/173-create-functions-to-assess-valueset-…
JNygaard-Skylight ce6f902
creating potential new validation pair files
robertandremitchell 427b5f1
Merge branch 'main' into rob/173-create-functions-to-assess-valueset-…
robertandremitchell e05e4aa
using sample snippet of data from performance notebook
robertandremitchell ee1eb87
removing local paths
robertandremitchell 4fb9b65
changing logic to properly track LOINC codes, refactoring evaluation …
robertandremitchell 8385d28
updating sample evaluation file
robertandremitchell 202ace4
Merge branch 'main' into rob/173-create-functions-to-assess-valueset-…
robertandremitchell 283325e
reorganizing and renaming files for clarity
robertandremitchell 45009ef
updated readme
robertandremitchell a5b4c54
saving performance notebook updates that use JSONL
robertandremitchell da06cf8
Merge branch 'main' into rob/173-create-functions-to-assess-valueset-…
robertandremitchell b58e763
Rolling back changes to performance notebook, adding new changes accu…
robertandremitchell bc55c64
adding checks to speed up accuracy analysis, more dynamic in setup
robertandremitchell 7f8f759
adding RCKMS-specific trigger LOINC code workflow
robertandremitchell 30811ce
Merge branch 'main' into rob/173-create-functions-to-assess-valueset-…
robertandremitchell ebcb11c
updating output for review
robertandremitchell 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
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,66 @@ | ||
| import json | ||
| import os | ||
|
|
||
| import requests | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
| USERNAME = os.environ.get("LOINC_USERNAME") | ||
| PASSWORD = os.environ.get("LOINC_PASSWORD") | ||
|
|
||
| url = "https://loinc.regenstrief.org/searchapi/loincs" | ||
|
|
||
|
|
||
| def search_loinc(raw_query: str): | ||
| """ | ||
| Searches the LOINC database using the provided raw query string. | ||
| :param raw_query: The raw query string to search for in the LOINC database. | ||
| """ | ||
| params = {"query": f'"{raw_query}"'} | ||
| response = requests.get( | ||
| url, | ||
| params=params, | ||
| auth=(USERNAME, PASSWORD), | ||
| timeout=30, | ||
| ) | ||
| return response.json() | ||
|
|
||
|
|
||
| file_path = ( | ||
| "/Users/rob/dibbs-text-to-code/data/accuracy_evaluation/eval_results_snippet_with_codes.jsonl" | ||
| ) | ||
| with open(file_path, "r") as f: | ||
| raw_eval_data = [json.loads(line) for line in f if line.strip()] | ||
|
|
||
| eval_data = [] | ||
| for item in raw_eval_data: | ||
| expected_loinc = search_loinc(item.get("expected_label")) | ||
| returned_loinc = search_loinc(item.get("top_predicted").get("label")) | ||
| eval_data.append( | ||
| { | ||
| "id": str(item.get("example_idx")) + "_" + str(item.get("k")), | ||
| "raw_text": item.get("query_input"), | ||
| "expected_text": item.get("expected_label"), | ||
| "returned_text": item.get("top_predicted").get("label"), | ||
| "expected_loinc": expected_loinc.get("Results")[0].get("LOINC_NUM") | ||
| if expected_loinc.get("ResponseSummary").get("RowsReturned") == 1 | ||
| else None, | ||
| "returned_loinc": returned_loinc.get("Results")[0].get("LOINC_NUM") | ||
| if returned_loinc.get("ResponseSummary").get("RowsReturned") == 1 | ||
| else None, | ||
| } | ||
| ) | ||
|
|
||
| # pop the rows for now that have no loinc for sake of testing | ||
| eval_data = [ | ||
| item | ||
| for item in eval_data | ||
| if item.get("expected_loinc") is not None and item.get("returned_loinc") is not None | ||
| ] | ||
|
|
||
| with open( | ||
| "/Users/rob/dibbs-text-to-code/data/accuracy_evaluation/eval_results_snippet_with_codes.txt", | ||
| "w", | ||
| ) as f: | ||
| json.dump(eval_data, f, indent=2) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.