AI Harmonization
This contains code and related artifacts for powering an AI-assisted data model harmonization tool. It also contains the infrastructure for abstracting approaches, benchmarking them, and generating training data.
Usage
pip install ai_harmonization
NOTE: Tested on Python 3.12
AI-Assisted Data Harmonization Toolkit
BioData Catalyst Study Harmonization
An end-to-end workflow that maps dbGaP study variables onto the BioData Catalyst Harmonized Model (bdchm). Run the notebooks in order; each one reads what the previous one wrote.
- Download Studies Metadata — fetch preharmonized PFBs from BDC and extract the dbGaP data dictionary and variable report XMLs.
- Generate Preliminary Harmonization Mappings — embed the bdchm schema once per prompt variant, then map each study variable to ranked target slots.
- Review Harmonization Suggestions — step through the candidates in a widget, accepting or skipping one variable at a time.
Steps 1 and 2 write into inputs/ and outputs/ relative to the notebook's working directory;
both are gitignored, as is the gen3-credentials/ directory holding your Gen3 API key.
Harmonization Benchmarking and AI Training
- Example of Evaluating a Harmonization Approach
- Example Creation of a Synthetic Benchmark for Evaluation
- Example Creation of a Real Benchmark for Evaluation
- Example Creation of a Training Data for Harmonization
Details
Reference ai_harmonization.harmonization_approaches.similarity_inmem.SimilaritySearchInMemoryVectorDb to understand how to build new harmonization approaches.
Abtractions have been built to allow the evaluation of different overall approaches. There is a base class to implement for a new HarmonizationApproach.
There are 2 Pydantic data types defined to standardize the interface. HarmonizationSuggestions is:
{
"suggestions": List of `SingleHarmonizationSuggestion`
}
and SingleHarmonizationSuggestion is:
class SingleHarmonizationSuggestion(BaseModel):
source_node: str
source_property: str
source_description: str
target_node: str
target_property: str
target_description: str
similarity: float = None
This format is convertable to A Simple Standard for Sharing Ontological Mappings (SSSOM) and happens by default when calling get_metrics_for_approach.
An example of how to implement a new approach. Create a new file: harmonization/harmonization_approaches/new_approach.py
from ai_curation.harmonization_approaches.harmonization import (
HarmonizationApproach,
HarmonizationSuggestions,
SingleHarmonizationSuggestion,
)
class NewApproachExample(HarmonizationApproach):
def __init__(
self,
):
super().__init__()
# TODO
def get_harmonization_suggestions(
self, input_source_model, input_target_model, **kwargs
):
# TODO
return HarmonizationSuggestions(suggestions=suggestions)
Note that the current
SimilaritySearchInMemoryVectorDbalready supports providing a new embedding algorithm.
And now, if you have a benchmark and want to evaluate the new approach:
from ai_harmonization.harmonization_benchmark import get_metrics_for_approach
from ai_harmonization.harmonization_approaches.new_approach import (
NewApproachExample,
)
new_approach = NewApproachExample()
output_filename = get_metrics_for_approach(
benchmark_filepath="path/to/benchmark.jsonl",
harmonization_approach=new_approach,
output_filename="output.tsv",
metrics_column_name="custom_metrics",
)
Benchmark Details
JSONL file, each row is a separate test.
Each test should have 3 keys: input_source_model in JSON, with desire to harmonize to input_target_model in JSON, and we expect known mapping defined in harmonized_mapping (which is a TSV represented as a string, with 2 columns ai_model_node_prop_desc and harmonized_model_node_prop_desc).
Example harmonized mapping:
| ai_model_node_prop_desc | harmonized_model_node_prop_desc |
|---|---|
| PatientData.AgeAtDiagnosis: The age of the patient at the time of diagnosis. | standard_patient_record.age_at_diagnosis: Age in years when diagnosed with the condition. |
| PatientData.LastVisitDate: The date of the last visit to a healthcare provider. | standard_patient_record.last_visit_date: Date of most recent medical appointment or consultation. |
| OutpatSkinCheck.AnchorDateOffset: Days between the specified anchor date and the patient's last completed skin test date. | outpat_v_skin_test.DaysFromAnchorDateToEventDate: |
The output of the get_metrics_for_approach generates a new file with appended metrics per test case in the benchmark.
Local Setup
Python 3.12 is recommended, newer versions may also work.
This uses uv (faster than pip and poetry, easier to work with).
uv sync
uv pip install -e .
Tests
uv run pytest tests/
Note: Tests are fairly minimal at the moment
Other
If for some reason you need to run detect-secrets separately from pre-commit and you have a ton of data or datasets, you can explicitly exclude those directories (they should already ignored by git):
detect-secrets scan --exclude-files '.*/data/.*|.*/datasets/.*|.*/output/.*'
Metadata
Release files for ai_harmonization 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_harmonization-0.5.0.tar.gz | 85.0 kB | Without provenance | Details for ai_harmonization-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_harmonization-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for ai_harmonization-0.5.0-py3-none-any.whl |
Total release size: 146.7 kB
Release files / ai_harmonization-0.5.0.tar.gz
| Download URL | ai_harmonization-0.5.0.tar.gz |
|---|---|
| Size | 85.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a040c98c935ac3a2042526489160d25248523b18e88cd0da6207afcd6c3143a
|
|
BLAKE2b-256 checksum How to use checksums |
8a97b7dd51a7acfa56f086b61348c1d1cd5fbdf981e9850e2752d2eff7ca63ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ai_harmonization-0.5.0-py3-none-any.whl
| Download URL | ai_harmonization-0.5.0-py3-none-any.whl |
|---|---|
| Size | 61.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be9323ce8424e0fa3975781d5bac4c4b53bd3b49e66cdf5d72a592356ea63115
|
|
BLAKE2b-256 checksum How to use checksums |
b022fdff4e8b541cd95a70ac8e0a9b08c158945ce1e027dbee4aa810cfdbd32b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ai_harmonization 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.