Sharing Code, Data, and Models

Best practices for open science in medical AI. GitHub repositories, model zoos, data sharing agreements, and balancing openness with patient privacy and commercial considerations.


A paper describing an AI model is a description of an experiment. The experiment itself is the code, the data and the trained model, and without at least some of those a reader has to take the description on trust.

Clinical researchers tend to come at sharing from the data side, where the default answer is "we can't, it's patient data." Computer scientists come at it from the code side, where the default is "it's on GitHub." A medical AI project has both problems, and there is usually more that can be shared than the first conversation suggests. This article goes through the three things you might release and the sensible options for each.

Why bother

The scientific reason is that results in this field often don't reproduce, and sharing is how anyone finds out. In 2020 a team from Google Health published a model for breast cancer screening in Nature. A group of researchers led by Benjamin Haibe-Kains replied in the same journal that, because neither the code nor the trained model had been released, the work could not be independently checked, and they argued that journals should hold AI papers to a higher standard of transparency. Matthew McDermott and colleagues made a related point in 2021 with numbers: they compared machine learning papers in health with those in other areas and found that the health papers were less likely to release code or to use public datasets.

There are also reasons that are more selfish, and no worse for it.

  • Journals and funders increasingly ask. Many journals require a data and code availability statement. The US National Institutes of Health has required a data management and sharing plan with most grant applications since January 2023.
  • Shared work gets used and cited. A public dataset with a paper attached can collect citations for years from groups using it as a benchmark.
  • External validation becomes possible. If another group can run your model on their data, you get the multi-site evidence that is otherwise so hard to arrange (see 5.4 Multi-Site External Validation).
  • Preparing something for release makes you tidy it up, which is a favour to your own lab a year from now.

A useful summary of what good sharing looks like is the FAIR principles, published in 2016: research outputs should be findable, accessible, interoperable and reusable. "Available from the corresponding author on reasonable request" manages roughly none of the four.

Sharing code

Code is the easiest thing to share, since it contains no patient data (check that this is true: no file paths with patient names, no sample images left in a folder, no credentials).

The usual home is a public repository on GitHub or a similar service. What makes a repository useful, as opposed to merely public:

  • A README that says what the code does, how to install it and how to run it on an example.
  • The environment: a list of the libraries and their exact versions, or a container image (Docker is the common one) that packages the whole thing. Deep learning libraries change quickly, and code without pinned versions often stops running within a year or two.
  • The whole pipeline, including preprocessing and evaluation. The training loop alone isn't enough. Preprocessing is where a lot of the undocumented decisions live (see 2.5 Data Preprocessing and Augmentation).
  • The configuration used for the results in the paper, including random seeds.
  • A licence. Without one, nobody has legal permission to use the code. MIT and Apache 2.0 are common permissive choices. Your institution's technology transfer office may have views, so ask early.

One more step is worth the ten minutes. A GitHub repository can be changed or deleted at any time. Depositing a snapshot of the release in an archive such as Zenodo gives it a DOI and a permanent copy that matches the paper. Cite that DOI in the manuscript.

The code doesn't have to be beautiful. Research code never is, and waiting until it is presentable is the commonest reason it never gets released.

Sharing models

The trained model, meaning the file of weights, lets someone else run your model on their own cases without retraining it. For external validation this is the most useful thing you can give.

Weights can go in the code repository if small, or on a model hosting service. Hugging Face is the general-purpose one, and the MONAI project runs a model zoo for medical imaging. Include a short script that loads the model and runs it on one example, with the exact preprocessing, because a model fed differently prepared images gives nonsense without any error message.

Describe the model with a model card. The idea comes from a 2019 paper by Margaret Mitchell and colleagues: a short document that travels with a model and states what it is intended for, what data it was trained on, how it performed overall and in subgroups, and where it shouldn't be used. For a medical model, say clearly that it is a research model and not a cleared medical device, if that is the case (see 7.5 Transparency and Reproducibility).

Two cautions before releasing weights.

A model can leak its training data. Large networks sometimes memorize individual training examples, and methods exist to extract them or to tell whether a given person's data was in the training set. The risk is highest for generative models and for models trained on small datasets (see 2.8 Synthetic Data and Data Simulation). So releasing a model trained on patient data is a disclosure decision, and your ethics approval and data agreements need to permit it.

And someone may use it clinically. You can't prevent that with a sentence in a README, but the sentence should be there, along with a licence that fits your intentions.

Sharing data

This is the hard one, and the answer is usually somewhere between "open" and "no."

Open release

Fully public datasets have done more for medical AI research than any single model. The Cancer Imaging Archive hosts a large number of de-identified imaging collections, and public challenge datasets such as the Medical Segmentation Decathlon have become standard benchmarks. If you can release yours, it will probably be the most cited thing you produce.

Open release takes more care than sharing with a collaborator, because once the data is out the only protection left is the de-identification. That means the full treatment described in 2.7 De-Identification, Privacy, and Regulatory Compliance for Research Data: headers, burned-in text, faces on head scans, free-text reports. It also needs explicit approval from the ethics board and the institution, which is far easier to get if open release was in the original protocol.

Controlled access

The middle route is to make data available to approved researchers who sign a data use agreement. PhysioNet, which hosts the MIMIC critical care datasets, is the best-known example: to download MIMIC, users complete training in research ethics and sign a data use agreement. Many national biobanks and some hospital consortia work similarly.

For a single lab, the equivalent is a stated process: who to contact, what agreement is needed, and what the conditions are. Put that in the data availability statement in place of "on reasonable request." It is slower than a download link, but it is honest and it works.

When the data can't leave

Sometimes the answer really is no, because of consent, law or institutional policy. There are still things you can do:

  • Share everything else. Code and weights let others test the model on their data.
  • Share the labels or the derived data, if those can be separated from the images. Annotations on a public dataset can be released freely.
  • Share a detailed description of the dataset, so readers can judge how it compares with theirs.
  • Test on a public dataset as well as your private one, so that at least part of your result is reproducible by anyone.
  • Offer to run other groups' models on your data and return the results, or take part in a federated study (see 2.6 Multi-Site and Multi-Device Data).
  • Release a small synthetic or sample dataset so that people can at least check that the code runs.

Document it

Whatever the access route, a dataset needs documentation. The model here is "Datasheets for Datasets," proposed by Timnit Gebru and colleagues: a structured description of why the dataset was made, what is in it, how it was collected and labeled, what it should and shouldn't be used for, and how it will be maintained. For a medical dataset, the essentials are the patient population and dates, inclusion and exclusion criteria, scanners and protocols, the labeling process with reader agreement, the recommended training and test split, and known limitations.

Choose a licence for data as well. Creative Commons licences are the usual choice, with CC BY (use freely, with credit) and CC BY-NC (non-commercial use only) the most common in medical imaging. A non-commercial licence keeps companies from building products on the data, which may or may not be what you want.

Commercial plans

Openness and commercialization pull in different directions, and it is better to decide early than to find out at publication.

If the model might become a product, talk to the technology transfer office before anything is released. Publishing a method can affect patent rights, depending on the jurisdiction and the timing. Releasing weights under a permissive licence gives away the model. A reasonable compromise is common: release the code and a research version of the model under a non-commercial licence, keep the data under controlled access, and license commercial rights separately.

Check the other direction too. Many public datasets and pretrained models carry non-commercial licences. If your model was trained on one, that restriction may follow the model into any product, and a regulator will want to know the provenance of the training data in any case (see 6.7 Good Machine Learning Practice).

A minimum we'd suggest

For a typical academic project where the data can't be made public:

  1. Code for preprocessing, training and evaluation in a public repository, with pinned versions, a licence and an archived DOI.
  2. Trained weights with a model card and an inference example, if approvals allow.
  3. A datasheet describing the dataset, in the supplement.
  4. Results on at least one public dataset alongside your own.
  5. A data availability statement that names the actual access process.

That is a few days of work at the end of a project. Planned from the start, with sharing written into the ethics application and the data agreements, it is less.

Key takeaways

  • Without code, data or a model, readers can't check an AI result. Journals and funders increasingly expect at least some of the three.
  • Code is the easiest to share: a public repository with a README, pinned library versions, the full pipeline, a licence and an archived DOI.
  • Trained weights make external validation possible. Release them with a model card and the preprocessing, after confirming that approvals allow it, since models can leak training data.
  • Data can be open, under controlled access with a data use agreement, or unavailable. Open release needs thorough de-identification and explicit approval.
  • When data can't be shared, share code, weights, labels and a dataset description, and report results on a public dataset too.
  • Document datasets with a datasheet and choose licences on purpose.
  • Settle commercial intentions and check the licences of anything you built on before releasing.

This article is part of the AI in Clinical Research Knowledge Base.