Skip to main content

bert-deid

Code to fine-tune BERT on a medical note de-identification task.

Install

  • (Recommended) Create an environment called deid
    • conda env create -f environment.yml
  • pip install locally
    • pip install bert-deid

Download

To download the model, we have provided a helper script in bert-deid:

# note: MODEL_DIR environment variable used by download
# by default, we download to bert_deid_model in the current directory
export MODEL_DIR="bert_deid_model"
bert_deid download

Usage

The model can be imported and used directly within Python.

from bert_deid.model import Transformer

# load in a trained model
model_path = 'bert_deid_model'
deid_model = Transformer(model_path)

with open('tests/example_note.txt', 'r') as fp:
    text = ''.join(fp.readlines())

print(deid_model.apply(text, repl='___'))

# we can also get the original predictions
preds = deid_model.predict(text)

# print out the identified entities
for p, pred in enumerate(preds):
    prob = pred[0]
    label = pred[1]
    start, stop = pred[2:]

    # print the prediction labels out
    print(f'{text[start:stop]:15s} {label} ({prob:0.3f})')

Metadata

Release files for bert-deid 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bert-deid 0.2.3
File Size Uploaded
bert_deid-0.2.3.tar.gz 33.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bert-deid 0.2.3
File Interpreter ABI Platform
bert_deid-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 73.3 kB

Release files / bert_deid-0.2.3.tar.gz

Download URL bert_deid-0.2.3.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2e60fd8997f3dad81e1e50efe632e265a850fef0e19419cbaa4fff77d5ae7dc4
BLAKE2b-256 checksum
How to use checksums
34a1cef86527dbed07c88d7c2cdb0af8e398693a7f0a2e9edd9b918bad125e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.7.9

Release files / bert_deid-0.2.3-py3-none-any.whl

Download URL bert_deid-0.2.3-py3-none-any.whl
Size 40.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b3d7c1d9ef5d22509d8886b6c597afcf5c8c0f6d51e89ccf71a2c451454f4f9
BLAKE2b-256 checksum
How to use checksums
cc372c2ce03a91887d6e418865ea15ca42b84b436030413df55dc3596c76435f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page