MilosKosRad commited on
Commit
94502a7
1 Parent(s): 5026015

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +128 -1
README.md CHANGED
@@ -14,4 +14,131 @@ tags:
14
  - zero-shot
15
  - BERT
16
  - PubMedBERT
17
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  - zero-shot
15
  - BERT
16
  - PubMedBERT
17
+ ---
18
+
19
+ # Zero and few shot NER for biomedical texts
20
+
21
+ ## Model description
22
+
23
+ This model was created during the research collaboration between Bayer Pharma and Serbian Institute for Artificial Intelligence Research and Development.
24
+ The model is trained on about 25+ biomedical NER classes and can perform also zero-shot inference and can be further fine-tuned for new classes with just few examples (few-shot learning).
25
+ For more details about our methods please see the paper named ["A transformer-based method for zero and few-shot biomedical named entity recognition"](https://arxiv.org/abs/2305.04928). The model corresponds to BioBERT-based mode, trained with 1 in the first segment (check paper for more details).
26
+
27
+ Model takes as input two strings. String1 is NER label that is being searched in second string. String1 must be phrase for entity. String2 is short text where String1 is searched for semantically.
28
+ model outputs list of zeros and ones corresponding to the occurance of Named Entity and corresponing to the tokens(tokens given by transformer tokenizer) of the Sring2.
29
+
30
+ ## Example of usage
31
+ ```python
32
+ from transformers import AutoTokenizer
33
+ from transformers import BertForTokenClassification
34
+
35
+ modelname = 'ProdicusII/ZeroShotBioNER' # modelpath
36
+ tokenizer = AutoTokenizer.from_pretrained(modelname) ## loading the tokenizer of that model
37
+ string1 = 'Drug'
38
+ string2 = 'No recent antibiotics or other nephrotoxins, and no symptoms of UTI with benign UA.'
39
+ encodings = tokenizer(string1, string2, is_split_into_words=False,
40
+ padding=True, truncation=True, add_special_tokens=True, return_offsets_mapping=False,
41
+ max_length=512, return_tensors='pt')
42
+
43
+ model0 = BertForTokenClassification.from_pretrained(modelname, num_labels=2)
44
+ prediction_logits = model0(**encodings)
45
+ print(prediction_logits)
46
+ ```
47
+
48
+ ## Example of fine-tuning with few-shot learning
49
+
50
+ In order to fine-tune model to the new entity using few shots, the dataset needs to be transformed to torch.utils.data.Dataset, containing BERT tokens and set of 0s and 1s (1 is where the class is positive and should be predicted as the member of given NER class). After the dataset is created, the following can be done (for more details, please have a look at the code at GitHub - https://github.com/br-ai-ns-institute/Zero-ShotNER):
51
+
52
+ ```python
53
+ training_args = TrainingArguments(
54
+ output_dir=os.path.join('Results', class_unseen, str(j)+'Shot'), # folder for results
55
+ num_train_epochs=10, # number of epochs
56
+ per_device_train_batch_size=16, # batch size per device during training
57
+ per_device_eval_batch_size=16, # batch size for evaluation
58
+ weight_decay=0.01, # strength of weight decay
59
+ logging_dir=os.path.join('Logs', class_unseen, str(j)+'Shot'), # folder for logs
60
+ save_strategy='epoch',
61
+ evaluation_strategy='epoch',
62
+ load_best_model_at_end=True,
63
+ )
64
+
65
+ model0 = BertForTokenClassification.from_pretrained(model_path, num_labels=2)
66
+ trainer = Trainer(
67
+ model=model0, # pretrained model
68
+ args=training_args, # training artguments
69
+ train_dataset=dataset, # Object of class torch.utils.data.Dataset for training
70
+ eval_dataset=dataset_valid # Object of class torch.utils.data.Dataset for vaLidation
71
+ )
72
+ start_time = time.time()
73
+ trainer.train()
74
+ total_time = time.time()-start_time
75
+ model0_path = os.path.join('Results', class_unseen, str(j)+'Shot', 'Model')
76
+ os.makedirs(model0_path, exist_ok=True)
77
+ trainer.save_model(model0_path)
78
+ ```
79
+
80
+ ## Available classes
81
+
82
+ The following datasets and entities were used for training and therefore they can be used as label in the first segment (as a first string). Note that multiword string have been merged.
83
+
84
+
85
+ * NCBI
86
+ * Specific Disease
87
+ * Composite Mention
88
+ * Modifier
89
+ * Disease Class
90
+ * BIORED
91
+ * Sequence Variant
92
+ * Gene Or Gene Product
93
+ * Disease Or Phenotypic Feature
94
+ * Chemical Entity
95
+ * Cell Line
96
+ * Organism Taxon
97
+ * CDR
98
+ * Disease
99
+ * Chemical
100
+ * CHEMDNER
101
+ * Chemical
102
+ * Chemical Family
103
+ * JNLPBA
104
+ * Protein
105
+ * DNA
106
+ * Cell Type
107
+ * Cell Line
108
+ * RNA
109
+ * n2c2
110
+ * Drug
111
+ * Frequency
112
+ * Strength
113
+ * Dosage
114
+ * Form
115
+ * Reason
116
+ * Route
117
+ * ADE
118
+ * Duration
119
+
120
+ On top of this, one can use the model in zero-shot regime with other classes, and also fine-tune it with few examples of other classes.
121
+
122
+
123
+
124
+ ## Code availibility
125
+
126
+ Code used for training and testing the model is available at https://github.com/br-ai-ns-institute/Zero-ShotNER
127
+
128
+ ## Citation
129
+
130
+ If you use this model, or are inspired by it, please cite in your paper the following paper:
131
+
132
+ Košprdić M.,Prodanović N., Ljajić A., Bašaragin B., Milošević N., 2023. A transformer-based method for zero and few-shot biomedical named entity recognition. arXiv preprint arXiv:2305.04928. https://arxiv.org/abs/2305.04928
133
+
134
+ or in bibtex:
135
+ ```
136
+ @misc{kosprdic2023transformerbased,
137
+ title={A transformer-based method for zero and few-shot biomedical named entity recognition},
138
+ author={Miloš Košprdić and Nikola Prodanović and Adela Ljajić and Bojana Bašaragin and Nikola Milošević},
139
+ year={2023},
140
+ eprint={2305.04928},
141
+ archivePrefix={arXiv},
142
+ primaryClass={cs.CL}
143
+ }
144
+ ```