File size: 6,072 Bytes
dd6d74c
 
 
 
 
 
 
 
 
 
13a68df
 
dd6d74c
 
0999119
 
 
dd6d74c
 
 
 
 
 
 
 
 
 
0999119
dd6d74c
 
 
0999119
 
 
 
dd6d74c
 
 
1075e78
 
 
 
 
dd6d74c
 
 
1075e78
 
 
 
dd6d74c
 
 
1075e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd6d74c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1075e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
base_model: mistralai/Mistral-7B-v0.1
library_name: peft
license: apache-2.0
tags:
- axolotl
- generated_from_trainer
model-index:
- name: WHI
  results: []
language:
- en
---

<!-- This model is a fine-tuned version of [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) on the None dataset.
It achieves the following results on the evaluation set:
- Loss: 0.2845 -->

[<img src="https://raw.githubusercontent.com/axolotl-ai-cloud/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/axolotl-ai-cloud/axolotl)
<details><summary>See axolotl config</summary>


</details><br>

[<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="32"/>](https://wandb.ai/uqam/WHI/runs/eceu99hm)
# WHI



## Model description

- **Model Type:** Mistral-7B (Causal Language Model)
- **Language(s):** English
- **License:** Apache 2.0
- **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)

## Intended uses & limitations

This model is intended for:
- Analyzing workplace incident descriptions
- Providing structured hazard classifications
- Identifying hazard sources and types
- Generating keywords for database querying related to incidents

## Training and evaluation data

The model was fine-tuned on a custom dataset (`incident_descriptions.json`) containing workplace safety reports. Each entry in the dataset includes:
- An instruction
- An incident description
- A structured output with hazard classification

## Training procedure

The model was fine-tuned using the Axolotl framework with the following configuration:

```json
{
  "_name_or_path": "mistralai/Mistral-7B-v0.1",
  "architectures": ["MistralForCausalLM"],
  "attention_dropout": 0.0,
  "hidden_size": 4096,
  "num_attention_heads": 32,
  "num_hidden_layers": 32,
  "num_key_value_heads": 8,
  "quantization_config": {
    "load_in_8bit": true,
    "quant_method": "bitsandbytes"
  },
  "torch_dtype": "bfloat16",
  "transformers_version": "4.42.4",
  "use_cache": false
}
```

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 0.0002
- train_batch_size: 2
- eval_batch_size: 2
- seed: 42
- gradient_accumulation_steps: 4
- total_train_batch_size: 8
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: cosine
- lr_scheduler_warmup_steps: 10
- num_epochs: 2

### Training results

| Training Loss | Epoch  | Step | Validation Loss |
|:-------------:|:------:|:----:|:---------------:|
| 1.0331        | 0.0076 | 1    | 1.0164          |
| 0.3599        | 0.2505 | 33   | 0.3364          |
| 0.3004        | 0.5009 | 66   | 0.3113          |
| 0.274         | 0.7514 | 99   | 0.2991          |
| 0.2273        | 1.0019 | 132  | 0.2860          |
| 0.1722        | 1.2524 | 165  | 0.2868          |
| 0.2038        | 1.5028 | 198  | 0.2863          |
| 0.2167        | 1.7533 | 231  | 0.2845          |


### Framework versions

- PEFT 0.11.1
- Transformers 4.42.4
- Pytorch 2.3.1+cu121
- Datasets 2.19.1
- Tokenizers 0.19.1

## How to Use

Here's how you can use this model for workplace hazard identification:

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load model and tokenizer
model_name = "NimaZahedinameghi/WHI"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")

# Prepare the input
instruction = "Given an incident description from a workplace safety report, analyze the text and provide a structured hazard classification. Your response should include the hazard source (broken down into three levels of granularity), the general hazard type, and keywords for database querying related to the incident. Ensure your classification is specific and accurately reflects the details provided in the incident description."
incident_description = "During the night shift, a worker was operating a forklift in the warehouse. While maneuvering between storage racks, the forklift's rear wheel caught on a piece of loose pallet wrap on the floor. This caused the forklift to swerve suddenly, colliding with a nearby rack. The impact dislodged several heavy boxes from the upper levels, which fell and narrowly missed the worker. The worker managed to stop the forklift and exit safely, but was visibly shaken by the near-miss incident."

# Combine instruction and input
input_text = f"{instruction}\n\nIncidentDescription: {incident_description}"

# Tokenize and generate
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(model.device)
output = model.generate(input_ids, max_length=500, num_return_sequences=1, do_sample=True, temperature=0.7)

# Decode and print the result
result = tokenizer.decode(output[0], skip_special_tokens=True)
print(result)
```

This code will generate a structured hazard classification based on the given incident description.

## Limitations and Biases

- The model's performance is limited by the quality and diversity of the training data.
- It may not accurately classify hazards outside its training domain.
- The model should not be used as the sole basis for safety decisions; always consult with safety professionals.

## Ethical Considerations

When using this model, consider:
- Privacy: Ensure that incident descriptions do not contain personally identifiable information.
- Accountability: The model's outputs should be reviewed by qualified safety professionals.
- Bias: Be aware of potential biases in the training data that could affect the model's classifications.

## Citation

If you use this model in your research, please cite:

```
@misc{WHI2023,
  author = {Nima Zahedinameghi},
  title = {WHI: Workplace Hazard Identification Model},
  year = {2023},
  publisher = {HuggingFace},
  journal = {HuggingFace Hub},
  howpublished = {\url{https://huggingface.co/NimaZahedinameghi/WHI}},
}
```