MattStammers commited on
Commit
b4e95ca
·
1 Parent(s): 39100b8

DistilBERT implementation

Browse files
Files changed (6) hide show
  1. README.md +153 -3
  2. config.json +25 -0
  3. model.safetensors +3 -0
  4. special_tokens_map.json +7 -0
  5. tokenizer_config.json +58 -0
  6. vocab.txt +0 -0
README.md CHANGED
@@ -1,3 +1,153 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ language:
4
+ - en
5
+ metrics:
6
+ - precision
7
+ - recall
8
+ - brier_score
9
+ - f1
10
+ - matthews_correlation
11
+ base_model:
12
+ - distilbert/distilbert-base-uncased
13
+ tags:
14
+ - IBD
15
+ - cohort_identification
16
+ - case_finding
17
+ ---
18
+ # Model Card for BioClinicalBERT IBD
19
+
20
+ The model classifies documents as either IBD or Not IBD
21
+
22
+ ## Model Details
23
+
24
+ ### Model Description
25
+
26
+ As above. This is a model trained to detect IBD patients from clinical text
27
+
28
+ - **Developed by:** Matt Stammers
29
+ - **Funded by:** University Hospital Foundation NHS Trust
30
+ - **Shared by:** Matt Stammers - SETT Data and AI Clinical Lead
31
+ - **Model type:** BERT Transformer
32
+ - **Language(s) (NLP):** English
33
+ - **License:** cc-by-nc-4.0
34
+ - **Finetuned from model:** distilbert/distilbert-base-uncased
35
+
36
+ ### Model Sources
37
+
38
+ - **Repository:** https://huggingface.co/MattStammers/Distil_IBD_BERT
39
+ - **Paper:** Arxiv (Pending)
40
+ - **Demo:** https://huggingface.co/spaces/MattStammers/IBD_Cohort_Identification
41
+
42
+ ## Uses
43
+
44
+ For document classification tasks to differentiate between documents likely to be diagnostic of IBD and those unlikely to be diagnostic of IBD.
45
+
46
+ ### Direct Use
47
+
48
+ This model can be used directly at [Cohort Identification Demo](https://huggingface.co/spaces/MattStammers/IBD_Cohort_Identification)
49
+
50
+ ### Downstream Use
51
+
52
+ Others can build on this model and improve it but only for non-commercial purposes.
53
+
54
+ ### Out-of-Scope Use
55
+
56
+ This model is less powerful (in terms of F1 Score) when making predictions at the patient level by 1-2%. It can be used for this purpose but with care.
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ This model contains substantial biases and is known to be biased against older patients and non-white patients so use with care.
61
+
62
+ ### Recommendations
63
+
64
+ It will work best in a predominantly younger caucasian population.
65
+
66
+ ## How to Get Started with the Model
67
+
68
+ Use the code below to get started with the model.
69
+
70
+ The model is best used with the transformers library.
71
+
72
+ ## Training Details
73
+
74
+ ### Training Data
75
+
76
+ The model was trained on fully pseudonymised clinical information at UHSFT which was carefully labelled by a consultant (attending) physician and evaluated against a randomly selected internal holdout set.
77
+
78
+ ### Training Procedure
79
+
80
+ See the paper for more information on the training procedure
81
+
82
+ #### Training Hyperparameters
83
+
84
+ - **Training regime:** fp32
85
+
86
+ #### Speeds, Sizes, Times
87
+
88
+ This model (part of a set of models) took 213.55 minutes to train
89
+
90
+ ## Evaluation
91
+
92
+ The model was internally validated against a holdout set
93
+
94
+ ### Testing Data, Factors & Metrics
95
+
96
+ #### Testing Data
97
+
98
+ The testing data cannot be revealed due to IG regulations and to remain compliant with GDPR, only the resulting model can be
99
+
100
+ #### Factors
101
+
102
+ IBD vs Not-IBD
103
+
104
+ #### Metrics
105
+
106
+ Full evaluation metrics are available in the paper with a summary below
107
+
108
+ ### Results
109
+
110
+ | Model | Doc Coverage | Accuracy | Precision | Recall | Specificity | NPV | F1 Score | MCC |
111
+ |------------|------------------|----------------------------------|----------------------------------|----------------------------------|----------------------------------|----------------------------------|----------------------------------|----------------------------------|
112
+ | DistilBERT | 768 (100.00%) | 91.93% (CI: 89.79% - 93.65%) | 92.10% (CI: 89.78% - 93.92%) | 98.38% (CI: 97.04% - 99.12%) | 65.79% (CI: 57.94% - 72.86%) | 90.91% (CI: 84.07% - 94.99%) | 95.13% (CI: 94.14% - 96.20%) | 0.7298 (CI: 0.6624 - 0.7898) |
113
+
114
+ #### Summary
115
+
116
+ Overall performance of the model is high with an F1 Score of >94% on our internal holdout set.
117
+
118
+ ## Environmental Impact
119
+
120
+ Training the model used 2.01kWh of energy emmitting 416.73 grams of CO2
121
+
122
+ - **Hardware Type:** L40S
123
+ - **Hours used:** 2
124
+ - **Carbon Emitted:** 0.230 Kg CO2
125
+
126
+ ## Citation
127
+
128
+ Arxiv (Pending)
129
+
130
+ ## Glossary
131
+
132
+ | Term | Description |
133
+ |-------------------------------------|-------------|
134
+ | **Accuracy** | The percentage of results that were correct among all results from the system. Calc: (TP + TN) / (TP + FP + TN + FN). |
135
+ | **Precision (PPV)** | Also called positive predictive value (PPV), it is the percentage of true positive results among all results that the system flagged as positive. Calc: TP / (TP + FP). |
136
+ | **Negative Predictive Value (NPV)** | The percentage of results that were true negative (TN) among all results that the system flagged as negative. Calc: TN / (TN + FN). |
137
+ | **Recall** | Also called sensitivity. The percentage of results flagged positive among all results that should have been obtained. Calc: TP / (TP + FN). |
138
+ | **Specificity** | The percentage of results that were flagged negative among all negative results. Calc: TN / (TN + FP). |
139
+ | **F1-Score** | The harmonic mean of PPV/precision and sensitivity/recall. Calc: 2 × (Precision × Recall) / (Precision + Recall). Moderately useful in the context of class imbalance. |
140
+ | **Matthews’ Correlation Coefficient (MCC)** | A statistical measure used to evaluate the quality of binary classifications. Unlike other metrics, MCC considers all four categories of a confusion matrix. Calc: (TP × TN − FP × FN) / √((TP + FP)(TP + FN)(TN + FP)(TN + FN)). |
141
+ | **Precision / Recall AUC** | Represents the area under the Precision-Recall curve, which plots Precision against Recall at various threshold settings. It is more resistant to class imbalance than alternatives like AUROC. |
142
+ | **Demographic Parity (DP)** | Demographic Parity, also known as Statistical Parity, requires that the probability of a positive prediction is the same across different demographic groups. Calc: DP = P(Ŷ=1∣A=a) = P(Ŷ=1∣A=b). This figure is given as an absolute difference where positive values suggest the more privileged group gains and negative values the reverse. |
143
+ | **Equal Opportunity (EO)** | Equal Opportunity focuses on equalising the true positive rates across groups. Among those who truly belong to the positive class, the model should predict positive outcomes at equal rates across groups. Calc: EO = P(Ŷ=1∣Y=1, A=a) = P(Ŷ=1∣Y=1, A=b). A higher value indicates a bias against the more vulnerable group. |
144
+ | **Disparate Impact (DI)** | Divides the protected group’s positive prediction rate by that of the most-favoured group. If the ratio is below 0.8 or above 1.25, disparate impact is considered present. Calc: DI = P(Ŷ=1∣A=unfavoured) / P(Ŷ=1∣A=favoured). Values outside 0.8–1.25 range suggest bias. |
145
+ | **Execution Time / Energy / CO₂ Emissions** | Measured in minutes and total energy consumption in kilowatt-hours (kWh), which is then converted to CO₂ emissions using a factor of 0.20705 Kg CO₂e per kWh. |
146
+
147
+ ## Model Card Authors
148
+
149
+ Matt Stammers - Computational Gastroenterologist
150
+
151
+ ## Model Card Contact
152
+
153
+ m.stammers@soton.ac.uk
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "distilbert-base-uncased",
3
+ "activation": "gelu",
4
+ "architectures": [
5
+ "DistilBertForSequenceClassification"
6
+ ],
7
+ "attention_dropout": 0.1,
8
+ "dim": 768,
9
+ "dropout": 0.1,
10
+ "hidden_dim": 3072,
11
+ "initializer_range": 0.02,
12
+ "max_position_embeddings": 512,
13
+ "model_type": "distilbert",
14
+ "n_heads": 12,
15
+ "n_layers": 6,
16
+ "pad_token_id": 0,
17
+ "problem_type": "single_label_classification",
18
+ "qa_dropout": 0.1,
19
+ "seq_classif_dropout": 0.2,
20
+ "sinusoidal_pos_embds": false,
21
+ "tie_weights_": true,
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.49.0",
24
+ "vocab_size": 30522
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:045326b1cdbbfe462e6466e11973ab61b3dbc0ec7f4f4fe88d7ff5fe0393b14f
3
+ size 267832560
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "DistilBertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff