{"id":13692749,"url":"https://github.com/ncbi-nlp/bluebert","last_synced_at":"2026-02-28T22:33:35.902Z","repository":{"id":39722528,"uuid":"190591634","full_name":"ncbi-nlp/bluebert","owner":"ncbi-nlp","description":"BlueBERT, pre-trained on PubMed abstracts and clinical notes (MIMIC-III). ","archived":false,"fork":false,"pushed_at":"2023-03-25T01:21:44.000Z","size":215,"stargazers_count":538,"open_issues_count":6,"forks_count":76,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-05-14T00:21:32.346Z","etag":null,"topics":["bert","bert-model","language-model","mimic-iii","natural-language-processing","pubmed","pubmed-abstracts"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/1906.05474","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ncbi-nlp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-06-06T14:02:54.000Z","updated_at":"2024-05-08T15:57:07.000Z","dependencies_parsed_at":"2022-07-31T23:09:59.611Z","dependency_job_id":"930badac-eb3d-4771-80bd-9a9243680e9a","html_url":"https://github.com/ncbi-nlp/bluebert","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncbi-nlp%2Fbluebert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncbi-nlp%2Fbluebert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncbi-nlp%2Fbluebert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncbi-nlp%2Fbluebert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ncbi-nlp","download_url":"https://codeload.github.com/ncbi-nlp/bluebert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252095421,"owners_count":21693914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bert","bert-model","language-model","mimic-iii","natural-language-processing","pubmed","pubmed-abstracts"],"created_at":"2024-08-02T17:01:01.671Z","updated_at":"2026-02-28T22:33:35.865Z","avatar_url":"https://github.com/ncbi-nlp.png","language":"Python","funding_links":[],"categories":["Uncategorized","Techniques and Models"],"sub_categories":["Uncategorized","BERT models"],"readme":"# BlueBERT\n\n**\\*\\*\\*\\*\\* New Nov 1st, 2020: BlueBERT can be found at huggingface \\*\\*\\*\\*\\***\n\n**\\*\\*\\*\\*\\* New Dec 5th, 2019: NCBI_BERT is renamed to BlueBERT \\*\\*\\*\\*\\***\n\n**\\*\\*\\*\\*\\* New July 11th, 2019: preprocessed PubMed texts \\*\\*\\*\\*\\***\n\nWe uploaded the [preprocessed PubMed texts](https://github.com/ncbi-nlp/BlueBERT/blob/master/README.md#pubmed)  that were used to pre-train the BlueBERT models.\n\n-----\n\nThis repository provides codes and models of BlueBERT, pre-trained on PubMed abstracts and clinical notes ([MIMIC-III](https://mimic.physionet.org/)). Please refer to our paper [Transfer Learning in Biomedical Natural Language Processing: An Evaluation of BERT and ELMo on Ten Benchmarking Datasets](https://arxiv.org/abs/1906.05474) for more details.\n\n## Pre-trained models and benchmark datasets\n\nThe pre-trained BlueBERT weights, vocab, and config files can be downloaded from: \n\n* [BlueBERT-Base, Uncased, PubMed](https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/NCBI-BERT/NCBI_BERT_pubmed_uncased_L-12_H-768_A-12.zip): This model was pretrained on PubMed abstracts.\n* [BlueBERT-Base, Uncased, PubMed+MIMIC-III](https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/NCBI-BERT/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12.zip): This model was pretrained on PubMed abstracts and MIMIC-III.\n* [BlueBERT-Large, Uncased, PubMed](https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/NCBI-BERT/NCBI_BERT_pubmed_uncased_L-24_H-1024_A-16.zip): This model was pretrained on PubMed abstracts.\n* [BlueBERT-Large, Uncased, PubMed+MIMIC-III](https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/NCBI-BERT/NCBI_BERT_pubmed_mimic_uncased_L-24_H-1024_A-16.zip): This model was pretrained on PubMed abstracts and MIMIC-III.\n\nThe pre-trained weights can also be found at Huggingface:\n\n* https://huggingface.co/bionlp/bluebert_pubmed_uncased_L-12_H-768_A-12\n* https://huggingface.co/bionlp/bluebert_pubmed_mimic_uncased_L-12_H-768_A-12\n* https://huggingface.co/bionlp/bluebert_pubmed_uncased_L-24_H-1024_A-16\n* https://huggingface.co/bionlp/bluebert_pubmed_mimic_uncased_L-24_H-1024_A-16\n\nThe benchmark datasets can be downloaded from [https://github.com/ncbi-nlp/BLUE_Benchmark](https://github.com/ncbi-nlp/BLUE_Benchmark)\n\n## Fine-tuning BlueBERT\n\nWe assume the BlueBERT model has been downloaded at `$BlueBERT_DIR`, and the dataset has been downloaded at `$DATASET_DIR`.\n\nAdd local directory to `$PYTHONPATH` if needed.\n\n```bash\nexport PYTHONPATH=.;$PYTHONPATH\n```\n\n### Sentence similarity\n\n```bash\npython bluebert/run_bluebert_sts.py \\\n  --task_name='sts' \\\n  --do_train=true \\\n  --do_eval=false \\\n  --do_test=true \\\n  --vocab_file=$BlueBERT_DIR/vocab.txt \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --max_seq_length=128 \\\n  --num_train_epochs=30.0 \\\n  --do_lower_case=true \\\n  --data_dir=$DATASET_DIR \\\n  --output_dir=$OUTPUT_DIR\n```\n\n\n### Named Entity Recognition\n\n```bash\npython bluebert/run_bluebert_ner.py \\\n  --do_prepare=true \\\n  --do_train=true \\\n  --do_eval=true \\\n  --do_predict=true \\\n  --task_name=\"bc5cdr\" \\\n  --vocab_file=$BlueBERT_DIR/vocab.txt \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --num_train_epochs=30.0 \\\n  --do_lower_case=true \\\n  --data_dir=$DATASET_DIR \\\n  --output_dir=$OUTPUT_DIR\n```\n\nThe task name can be \n\n- `bc5cdr`: BC5CDR chemical or disease task\n- `clefe`: ShARe/CLEFE task\n\n### Relation Extraction\n\n```bash\npython bluebert/run_bluebert.py \\\n  --do_train=true \\\n  --do_eval=false \\\n  --do_predict=true \\\n  --task_name=\"chemprot\" \\\n  --vocab_file=$BlueBERT_DIR/vocab.txt \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --num_train_epochs=10.0 \\\n  --data_dir=$DATASET_DIR \\\n  --output_dir=$OUTPUT_DIR \\\n  --do_lower_case=true \n```\n\nThe task name can be \n\n- `chemprot`: BC6 ChemProt task\n- `ddi`: DDI 2013 task\n- `i2b2_2010`: I2B2 2010 task\n\n### Document multilabel classification\n\n```bash\npython bluebert/run_bluebert_multi_labels.py \\\n  --task_name=\"hoc\" \\\n  --do_train=true \\\n  --do_eval=true \\\n  --do_predict=true \\\n  --vocab_file=$BlueBERT_DIR/vocab.txt \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --max_seq_length=128 \\\n  --train_batch_size=4 \\\n  --learning_rate=2e-5 \\\n  --num_train_epochs=3 \\\n  --num_classes=20 \\\n  --num_aspects=10 \\\n  --aspect_value_list=\"0,1\" \\\n  --data_dir=$DATASET_DIR \\\n  --output_dir=$OUTPUT_DIR\n```\n\n### Inference task\n\n```bash\npython bluebert/run_bluebert.py \\\n  --do_train=true \\\n  --do_eval=false \\\n  --do_predict=true \\\n  --task_name=\"mednli\" \\\n  --vocab_file=$BlueBERT_DIR/vocab.txt \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --num_train_epochs=10.0 \\\n  --data_dir=$DATASET_DIR \\\n  --output_dir=$OUTPUT_DIR \\\n  --do_lower_case=true \n```\n\n## \u003ca name=\"pubmed\"\u003e\u003c/a\u003ePreprocessed PubMed texts\n\nWe provide [preprocessed PubMed texts](https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/NCBI-BERT/pubmed_uncased_sentence_nltk.txt.tar.gz) that were used to pre-train the BlueBERT models. The corpus contains ~4000M words extracted from the [PubMed ASCII code version](https://www.ncbi.nlm.nih.gov/research/bionlp/APIs/BioC-PubMed/). Other operations include\n\n*  lowercasing the text\n*  removing speical chars `\\x00`-`\\x7F`\n*  tokenizing the text using the [NLTK Treebank tokenizer](https://www.nltk.org/_modules/nltk/tokenize/treebank.html)\n\nBelow is a code snippet for more details.\n\n```python\nvalue = value.lower()\nvalue = re.sub(r'[\\r\\n]+', ' ', value)\nvalue = re.sub(r'[^\\x00-\\x7F]+', ' ', value)\n\ntokenized = TreebankWordTokenizer().tokenize(value)\nsentence = ' '.join(tokenized)\nsentence = re.sub(r\"\\s's\\b\", \"'s\", sentence)\n```\n\n### Pre-training with BERT\n\nAfterwards, we used the following code to generate pre-training data. Please see https://github.com/google-research/bert for more details.\n\n```bash\npython bert/create_pretraining_data.py \\\n  --input_file=pubmed_uncased_sentence_nltk.txt \\\n  --output_file=pubmed_uncased_sentence_nltk.tfrecord \\\n  --vocab_file=bert_uncased_L-12_H-768_A-12_vocab.txt \\\n  --do_lower_case=True \\\n  --max_seq_length=128 \\\n  --max_predictions_per_seq=20 \\\n  --masked_lm_prob=0.15 \\\n  --random_seed=12345 \\\n  --dupe_factor=5\n```\n\nWe used the following code to train the BERT model. Please do not include `init_checkpoint` if you are pre-training from scratch. Please see https://github.com/google-research/bert for more details.\n\n```bash\npython bert/run_pretraining.py \\\n  --input_file=pubmed_uncased_sentence_nltk.tfrecord \\\n  --output_dir=$BlueBERT_DIR \\\n  --do_train=True \\\n  --do_eval=True \\\n  --bert_config_file=$BlueBERT_DIR/bert_config.json \\\n  --init_checkpoint=$BlueBERT_DIR/bert_model.ckpt \\\n  --train_batch_size=32 \\\n  --max_seq_length=128 \\\n  --max_predictions_per_seq=20 \\\n  --num_train_steps=20000 \\\n  --num_warmup_steps=10 \\\n  --learning_rate=2e-5\n```\n\n## Citing BlueBERT\n\n*  Peng Y, Yan S, Lu Z. [Transfer Learning in Biomedical Natural Language Processing: An\nEvaluation of BERT and ELMo on Ten Benchmarking Datasets](https://arxiv.org/abs/1906.05474). In *Proceedings of the Workshop on Biomedical Natural Language Processing (BioNLP)*. 2019.\n\n```\n@InProceedings{peng2019transfer,\n  author    = {Yifan Peng and Shankai Yan and Zhiyong Lu},\n  title     = {Transfer Learning in Biomedical Natural Language Processing: An Evaluation of BERT and ELMo on Ten Benchmarking Datasets},\n  booktitle = {Proceedings of the 2019 Workshop on Biomedical Natural Language Processing (BioNLP 2019)},\n  year      = {2019},\n  pages     = {58--65},\n}\n```\n\n## Acknowledgments\n\nThis work was supported by the Intramural Research Programs of the National Institutes of Health, National Library of\nMedicine and Clinical Center. This work was supported by the National Library of Medicine of the National Institutes of Health under award number K99LM013001-01.\n\nWe are also grateful to the authors of BERT and ELMo to make the data and codes publicly available.\n\nWe would like to thank Dr Sun Kim for processing the PubMed texts.\n\n## Disclaimer\n\nThis tool shows the results of research conducted in the Computational Biology Branch, NCBI. The information produced\non this website is not intended for direct diagnostic use or medical decision-making without review and oversight\nby a clinical professional. Individuals should not change their health behavior solely on the basis of information\nproduced on this website. NIH does not independently verify the validity or utility of the information produced\nby this tool. If you have questions about the information produced on this website, please see a health care\nprofessional. More information about NCBI's disclaimer policy is available.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncbi-nlp%2Fbluebert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fncbi-nlp%2Fbluebert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncbi-nlp%2Fbluebert/lists"}