{"id":22230205,"url":"https://github.com/miladnouriezade/ktrain-biobert_ner","last_synced_at":"2026-04-28T22:35:31.960Z","repository":{"id":201335927,"uuid":"273851701","full_name":"miladnouriezade/Ktrain-BioBert_NER","owner":"miladnouriezade","description":"This repository contains data and BioBert based NER model monologg/biobert_v1.1_pubmed from community-uploaded Hugging Face models for detecting entities such as chemical and disease.","archived":false,"fork":false,"pushed_at":"2020-06-26T15:34:35.000Z","size":52543,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T08:45:12.491Z","etag":null,"topics":["biobert","biomedical","bionlp","disease","fasttext","huggingface","ktrain","name","named-entity-recognition","ner","nlp","python","spacy"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miladnouriezade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-06-21T06:56:20.000Z","updated_at":"2024-01-29T19:20:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c5d14c8-1e7c-4f05-bb58-7da2d9d17dbf","html_url":"https://github.com/miladnouriezade/Ktrain-BioBert_NER","commit_stats":null,"previous_names":["miladnouriezade/ktrain-biobert_ner"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/miladnouriezade/Ktrain-BioBert_NER","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladnouriezade%2FKtrain-BioBert_NER","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladnouriezade%2FKtrain-BioBert_NER/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladnouriezade%2FKtrain-BioBert_NER/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladnouriezade%2FKtrain-BioBert_NER/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miladnouriezade","download_url":"https://codeload.github.com/miladnouriezade/Ktrain-BioBert_NER/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladnouriezade%2FKtrain-BioBert_NER/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32402671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["biobert","biomedical","bionlp","disease","fasttext","huggingface","ktrain","name","named-entity-recognition","ner","nlp","python","spacy"],"created_at":"2024-12-03T01:14:39.867Z","updated_at":"2026-04-28T22:35:26.950Z","avatar_url":"https://github.com/miladnouriezade.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ktrain BioBert_NER\n\nThis repository contains data and BioBert based NER model `monologg/biobert_v1.1_pubmed` from [community-uploaded Hugging Face models](https://huggingface.co/models) for detecting entities such as chemical and disease.\n\n## Setting up an environment\n\n1.  [Follow the installation instructions for Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html?highlight=conda#regular-installation).\n2. Create a Conda environment called \"Ktrain_NER\" with Python 3.7.0:\n\n    ```bash\n    conda create -n Ktrain_NER python=3.7.0\n    ```\n\n3. Activate the Conda environment:\n\n    ```bash\n    conda activate Ktrain_NER\n    ```\n\n## Installation\n\nInstall required packages .\n\n```sh\n$ pip install tensorflow==2.1.0\n```\n\n```sh\n$ pip install pytorch==1.4.0\n```\n\n```sh\n$ pip install ktrain==0.12.0\n```\n\nIf you want to convert your IOB schemed data to BILOU schemed using `iobToBilou.py` in utilities folder, install [spaCy](https://github.com/explosion/spaCy) using bellow command .\n\n```sh\n$ conda install -c conda-forge spacy\n```\n\n## Dataset\n\nDownload dataset provided in data folder(BC5CDR-IOB), locate it in any directory you want and address `TRAIN_DATA` and `VALIDATION_DATA` in `parameters.py` .\nUse `train-dev.tsv` for training and `test.tsv` for validation.\n\u003e Ktrain can use both `validation` and `train` datas or just `train`.\n\n## Learning rate hyper-parameter\n\n`lr_find()` records loss over range of LRs .\n\n```bash\ndef lr_find(self, start_lr=1e-7, lr_mult=1.01, max_epochs=None, \n                stop_factor=4, show_plot=False, verbose=1):\n\n\"\"\"\nArgs:\n            start_lr (float): smallest lr to start simulation\n            lr_mult (float): multiplication factor to increase LR.\n                             Ignored if max_epochs is supplied.\n            max_epochs (int):  maximum number of epochs to simulate.\n                               lr_mult is ignored if max_epoch is supplied.\n                               Default is None. Set max_epochs to an integer\n                               (e.g., 5) if lr_find is taking too long\n                               and running for more epochs than desired.\n            stop_factor(int): factor used to determine threhsold that loss \n                              must exceed to stop training simulation.\n                              Increase this if loss is erratic and lr_find\n                              exits too early.\n            show_plot (bool):  If True, automatically invoke lr_plot\n            verbose (bool): specifies how much output to print\n        Returns:\n            float:  Numerical estimate of best lr.  \n                    The lr_plot method should be invoked to\n                    identify the maximal loss associated with falling loss.\n\"\"\"\n```\n\nFor using `lr_find()` we need to a `learner` object; that we can construct it using `ktrain.get_learner()` function by passing model and data .\n\n```bash\nlearner = ktrain.get_learner(model, train_data=trn, val_data=val, batch_size=128, eval_batch_size=64)\n```\n\nAfter trying some LRs(1e-5, 1e-4, 5e-3, 8e-4) we found that in our case optimal lr is approximately 1e-3 .\n\n![lr_find](pic/lr_find.png)\n\n## Train and validate model\n\nUse `python run_ner.py` to train and validate model.\n\n## Result\n\nWe got the best result using SGDR learning rate scheduler on `BC5CDR-IOB` with `lr=1e-3`,`n_cycles=3`, `cycle_len=1` and `cycle_mult=2`. weights are availabel in `weights` folder.\n\n```bash\nlearner.fit(1e-3, 3, cycle_len=1, cycle_mult=2, checkpoint_folder='/checkpoints/SGDR', early_stopping=3)\n```\n\n![SGDR](pic/SGDR.png)\n\n| | precision  | recall  | f1-score  | support  |\n|---|---|---|---|---|\n|  Chemical | 0.91  | 091  |  0.91 |5385\n| Disease  |  0.75 | 0.81  |  0.78 |4424\n| micro avg  | 0.83  | 0.87  | 0.85  |9809\n| macro avg  |  0.84 | 0.87  | 0.85  |9809\n\n## Result using fastText\n\nWe used `crawl-300d-2M-subword` from [fastext pre-trained word vectors](https://fasttext.cc/docs/en/english-vectors.html) instead of randomly initialized word embeddings with the same parameters and data as before .\n\n| | precision  | recall  | f1-score  | support  |\n|---|---|---|---|---|\n|  Disease | 0.76  | 0.79  |  0.77 |4424\n|  Chemical |  0.91 | 0.89  |  0.90 |5385\n| micro avg  | 0.84  | 0.85  | 0.84  |9809\n| macro avg  |  0.84 | 0.85  | 0.85  |9809\n\n## Result using fastText and BILOU schemed data\n\nIn this expriment we used `BC5CDR-BILOU` _ BILOU schemed data set instead of IOB with `crawl-300d-2M-subword`(fastText word vector) and same parameters as before .\n\n| | precision  | recall  | f1-score  | support  |\n|---|---|---|---|---|\n|  Chemical | 0.91  | 0.74  |  0.82 |5374\n|  Disease |  0.74 | 0.72  |  0.73 |4397\n| micro avg  | 0.83  | 0.73  | 0.78  |9771\n| macro avg  |  0.83 | 0.73  | 0.78  |9771\n\n## Refernces\n\n1. [Tunning Learning Rates](https://nbviewer.jupyter.org/github/amaiya/ktrain/blob/master/tutorials/tutorial-02-tuning-learning-rates.ipynb)\n\n2. [English NER example notebook](https://nbviewer.jupyter.org/github/amaiya/ktrain/blob/develop/examples/text/CoNLL2003-BiLSTM.ipynb)\n\n3. [Text Sequence Tagging for Named Entity Recognition](https://nbviewer.jupyter.org/github/amaiya/ktrain/blob/master/tutorials/tutorial-06-sequence-tagging.ipynb)\n\n4. [A Newbie’s Guide to Stochastic Gradient Descent With Restarts](https://towardsdatascience.com/https-medium-com-reina-wang-tw-stochastic-gradient-descent-with-restarts-5f511975163)\n\n5. [Exploring Stochastic Gradient Descent with Restarts (SGDR)](https://medium.com/38th-street-studios/exploring-stochastic-gradient-descent-with-restarts-sgdr-fa206c38a74e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladnouriezade%2Fktrain-biobert_ner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiladnouriezade%2Fktrain-biobert_ner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladnouriezade%2Fktrain-biobert_ner/lists"}