stuSterfc commited on
Commit
86b0bed
Β·
verified Β·
1 Parent(s): 7f73c09

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +221 -134
README.md CHANGED
@@ -1,199 +1,286 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a πŸ€— transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
 
78
- ### Training Data
 
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
 
 
89
 
90
- [More Information Needed]
 
 
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
 
 
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
 
 
 
 
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
 
 
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
112
 
113
- [More Information Needed]
 
 
 
 
114
 
115
- #### Factors
 
 
 
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
 
 
 
 
 
126
 
127
- ### Results
 
128
 
129
- [More Information Needed]
130
 
131
- #### Summary
 
 
 
 
 
 
132
 
 
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
 
 
138
 
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
 
154
 
155
- ### Model Architecture and Objective
 
 
156
 
157
- [More Information Needed]
158
 
159
- ### Compute Infrastructure
 
 
 
 
 
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
174
 
175
- **BibTeX:**
 
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
 
 
 
 
 
 
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
 
196
 
197
- ## Model Card Contact
198
 
199
  [More Information Needed]
 
1
  ---
2
+ ---
3
+ language: en
4
+ license: mit
5
+ tags:
6
+ - text-classification
7
+ - occupational-health-safety
8
+ - bert
9
+ - distilbert
10
+ - severity-prediction
11
+ - workplace-incidents
12
+ - nlp
13
+ datasets:
14
+ - osha-incident-reports
15
+ metrics:
16
+ - f1
17
+ - accuracy
18
+ - roc-auc
19
  ---
20
 
21
+ # OHS Severity Classifier
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ DistilBERT fine-tuned for workplace incident severity classification.
24
+ Developed as part of MSc Computer Science research at Northumbria University (2024).
25
 
26
+ **Research paper:** *Predicting Workplace Incident Severity Using BERT-Based NLP β€”
27
+ Probabilistic Classification and SHAP Analysis for UK OHS Decision Support*
28
+ arXiv: submission in progress β€” link will be added on publication
29
 
30
+ **Code repository:** github.com/stuartclark-ml/incident-severity-bert
31
 
32
+ ---
33
 
34
+ ## Model Description
35
 
36
+ This model classifies workplace incident descriptions into five severity
37
+ categories based on time-loss incapacitation, aligned with UK RIDDOR reporting
38
+ thresholds and HSE guidance frameworks.
39
 
40
+ The model takes a free-text incident narrative as input and outputs a
41
+ probability distribution across five severity classes. It is designed as a
42
+ **decision-support tool in a human-in-the-loop workflow** β€” not a standalone
43
+ classifier. The probability distribution and SHAP token attribution together
44
+ allow a safety professional to assess confidence and inspect the model's
45
+ reasoning before acting on a prediction.
46
 
47
+ ---
48
 
49
+ ## Severity Classification Framework
50
 
51
+ | Class | Label | Condition | UK OHS Alignment |
52
+ |---|---|---|---|
53
+ | 0 | None | 0 days lost | Below RIDDOR recording threshold |
54
+ | 1 | Minor | 1-2 days lost | Below mandatory internal recording threshold |
55
+ | 2 | Moderate | 3-7 days lost | Mandatory internal recording under RIDDOR |
56
+ | 3 | Severe | 8-28 days lost | Statutory reporting to HSE required |
57
+ | 4 | Major | 29+ days lost | Long-term incapacitation β€” triggers separate management and insurance obligations |
58
 
59
+ Time-loss days used as severity proxy. This metric is compatible with both
60
+ US OSHA and UK RIDDOR reporting frameworks β€” the primary justification for
61
+ using OSHA data to develop a UK-applicable tool.
62
 
63
+ ---
64
 
65
+ ## Intended Uses
66
 
67
+ **Appropriate uses:**
68
+ - Triage support for high-volume incident report queues in health and social
69
+ care settings
70
+ - Research into NLP-based severity prediction for occupational safety
71
+ - Demonstration of BERT-based classification with SHAP explainability in
72
+ safety-critical domains
73
+ - Educational exploration of model bias in imbalanced safety datasets
74
 
75
+ **Not appropriate for:**
76
+ - Standalone severity determination without human review
77
+ - UK RIDDOR reportability decisions β€” the model was not trained on RIDDOR data
78
+ - Industries outside health and social care β€” trained on H&C sector data only
79
+ - Definitive clinical or legal severity assessments
80
 
81
+ ---
82
 
83
+ ## Training Data
84
 
85
+ **Dataset:** US OSHA Incident Reports (2024 release) β€” Health and Care sector subset
86
 
87
+ **Size:** 181,586 records after preprocessing
88
+ - Full OSHA dataset: 751,770 records
89
+ - H&C sector subset: 193,512 records
90
+ - COVID-19 records removed: 10,016 (to prevent rare global event bias)
91
+ - Fatality records removed: 5 (statistically insignificant, severe class imbalance)
92
 
93
+ **Features used:**
94
+ - `new_nar_what_happened` β€” what happened during the incident
95
+ - `new_nar_before_incident` β€” what the employee was doing beforehand
96
+ - `new_nar_object_substance` β€” the object or substance causing harm
97
+ - `size` β€” organisational size (1=<20, 2=20-249, 3=250+ employees)
98
 
99
+ **Class distribution:** Heavily imbalanced β€” dominated by None class, reflecting
100
+ real-world incident distribution (Heinrich's Triangle). Weighted loss function
101
+ applied during training (up to 4.05x penalty for Minor class).
102
 
103
+ ---
104
 
105
+ ## Performance
106
 
107
+ ### Overall Metrics
108
 
109
+ | Metric | Random Forest (baseline) | DistilBERT | ModernBERT |
110
+ |---|---|---|---|
111
+ | Weighted Avg F1 | 0.55 | **0.58** | 0.58 |
112
+ | Macro ROC AUC | 0.77 | 0.77 | **0.78** |
113
+ | Overall Accuracy | 0.52 | **0.55** | 0.54 |
114
+ | Log Loss | 1.29 | **1.07** | 1.10 |
115
 
116
+ DistilBERT selected as the deployment model: equal F1 to ModernBERT,
117
+ highest accuracy, lowest log loss, and smaller model size.
118
 
119
+ ### Per-Class Metrics β€” DistilBERT
120
 
121
+ | Class | Precision | Recall | F1 |
122
+ |---|---|---|---|
123
+ | None | 0.94 | 0.71 | 0.81 |
124
+ | Minor | 0.16 | 0.14 | 0.15 |
125
+ | Moderate | 0.19 | 0.25 | 0.22 |
126
+ | Severe | 0.21 | 0.20 | 0.20 |
127
+ | Major | 0.37 | **0.60** | 0.46 |
128
 
129
+ **Key finding:** 0.60 recall on Major (highest-severity) incidents makes the
130
+ model useful for prioritisation β€” catching 60% of the most serious incidents
131
+ for urgent human review β€” despite poor performance on the middle classes.
132
 
133
+ ---
134
 
135
+ ## Critical Findings from SHAP Analysis
136
 
137
+ SHAP token attribution was applied to DistilBERT to inspect the model's
138
+ learned logic. This revealed two significant issues that any user of this
139
+ model must understand:
140
 
141
+ ### 1. Needlestick Blind Spot
142
 
143
+ **99.25% of needlestick injuries in the training dataset are labelled None.**
144
 
145
+ The model learned this spurious correlation and systematically classifies
146
+ needlestick injuries as None severity β€” regardless of their actual
147
+ consequences. In clinical practice needlestick injuries can result in
148
+ bloodborne pathogen exposure with serious long-term health consequences.
149
 
150
+ **Mitigation:** Any incident narrative containing needle-related terms
151
+ (`needle`, `needlestick`, `lancet`, `sharps`, `puncture`) should be
152
+ flagged for mandatory human review and not relied upon for model output.
153
 
154
+ ### 2. Organisational Size Bias
 
 
 
 
155
 
156
+ The `size` feature introduced a spurious correlation: small organisations
157
+ (size=1, <20 employees) are associated with None class at 50.8%.
158
 
159
+ **Mitigation:** Model predictions for incidents from small organisations
160
+ should be treated with additional caution. Future implementations should
161
+ consider removing the size feature unless a more balanced dataset is available.
162
 
163
+ ### Positive Finding β€” No Significant US Linguistic Bias
164
 
165
+ SHAP global feature importance analysis found no significant US-centric
166
+ linguistic bias in the top predictive features. The model relied on
167
+ universal medical and safety terminology rather than US-specific language,
168
+ supporting its tentative use as a UK proxy tool. However, regulatory and
169
+ operational differences between US and UK health and social care systems
170
+ mean direct comparison with UK standards still requires caution.
171
 
172
+ ---
173
 
174
+ ## Limitations
175
+
176
+ - **Jurisdiction:** Trained on US OSHA data. UK RIDDOR performance not
177
+ characterised. Time-loss metric provides a compatibility bridge but does
178
+ not eliminate cross-jurisdictional differences.
179
+ - **Industry:** Health and social care only. Performance on other sectors
180
+ is unknown and likely poor.
181
+ - **Minority classes:** Minor, Moderate, and Severe classes perform poorly
182
+ (F1 0.15-0.22). Narratives for these classes are textually indistinct β€”
183
+ a fundamental data limitation not resolvable by model architecture alone.
184
+ - **Correlation not causation:** SHAP values reflect learned correlations
185
+ in the training data. They provide interpretations, not causal explanations.
186
+ - **Static training data:** Model accuracy will degrade over time as incident
187
+ patterns and safety language evolve. Continuous retraining would be required
188
+ for production deployment.
189
+ - **Fatalities excluded:** Insufficient fatality cases in the dataset (5 records)
190
+ for reliable modelling.
191
 
192
+ ---
193
 
194
+ ## How to Use
195
+ ```python
196
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
197
+ import torch
198
+
199
+ model_name = "stuSterfc/ohs-severity-classifier"
200
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
201
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
202
+
203
+ labels = ["None", "Minor", "Moderate", "Severe", "Major"]
204
+
205
+ def predict_severity(narrative: str, org_size: str = "Large") -> dict:
206
+ # Format input to match training structure
207
+ text = f"Organisation size: {org_size}. [SEP] {narrative}"
208
+
209
+ inputs = tokenizer(
210
+ text,
211
+ return_tensors="pt",
212
+ truncation=True,
213
+ max_length=512,
214
+ padding=True
215
+ )
216
+
217
+ with torch.no_grad():
218
+ outputs = model(**inputs)
219
+
220
+ probs = torch.softmax(outputs.logits, dim=1).squeeze().tolist()
221
+
222
+ return {
223
+ "probabilities": {label: round(prob, 4)
224
+ for label, prob in zip(labels, probs)},
225
+ "predicted_class": labels[probs.index(max(probs))],
226
+ "confidence": round(max(probs), 4)
227
+ }
228
+
229
+ # Example
230
+ result = predict_severity(
231
+ "Employee was assisting patient transfer from bed to wheelchair. "
232
+ "Felt sharp pain in lower back. Unable to complete shift.",
233
+ org_size="Large"
234
+ )
235
+ print(result)
236
+
237
+ # IMPORTANT: Check for needlestick blind spot
238
+ needle_terms = ["needle", "needlestick", "lancet", "sharps", "puncture"]
239
+ if any(term in narrative.lower() for term in needle_terms):
240
+ print("WARNING: Needle-related incident detected. "
241
+ "Model has known blind spot β€” refer for human review.")
242
+ ```
243
 
244
+ ---
245
 
246
+ ## Input Format
247
 
248
+ The model was trained on concatenated narratives with an organisational
249
+ size prefix, separated by `[SEP]` tokens:
250
+ ```
251
+ Organisation size: {size}. [SEP] {what_happened} [SEP] {before_incident} [SEP] {object_substance}
252
+ ```
253
 
254
+ At minimum, provide the `what_happened` narrative. Include org size if known.
255
+ The `[SEP]` separator is important β€” it matches the training format.
256
 
257
+ **Organisation size values:** Small (<20), Medium (20-249), Large (250+)
258
 
259
+ ---
260
 
261
+ ## Training Details
262
 
263
+ - **Base model:** `distilbert-base-cased`
264
+ - **Framework:** HuggingFace Transformers
265
+ - **Fine-tuning:** HuggingFace Trainer API
266
+ - **Hyperparameter optimisation:** Optuna
267
+ - **Class imbalance handling:** Weighted loss function (inverse class frequency)
268
+ - **Training data split:** Standard train/validation/test split
269
+ - **Hardware:** [GPU details if you have them]
270
 
271
+ ---
272
 
273
+ ## Citation
274
 
275
+ *Citation will be added when arXiv preprint is published.*
276
 
277
+ ---
278
 
279
+ ## About the Author
280
 
281
+ Stuart Clark β€” MSc Computer Science (Distinction), Northumbria University 2024.
282
+ NEBOSH National Diploma. 14 years occupational health and safety consulting.
283
 
284
+ GitHub: github.com/stuartclark-ml
285
 
286
  [More Information Needed]