File size: 6,378 Bytes
dd6d74c 13a68df dd6d74c 0999119 dd6d74c 0999119 dd6d74c 0999119 dd6d74c 1075e78 dd6d74c 1075e78 dd6d74c 1075e78 ba3a992 1075e78 ba3a992 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
---
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 -->
</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:
```yaml
{
base_model: mistralai/Mistral-7B-v0.1
model_type: MistralForCausalLM
tokenizer_type: LlamaTokenizer
load_in_8bit: true
load_in_4bit: false
strict: false
adapter: lora
lora_model_dir:
sequence_len: 8192
sample_packing: False
pad_to_sequence_len: true
lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:
lora_target_modules:
- gate_proj
- down_proj
- up_proj
- q_proj
- v_proj
- k_proj
- o_proj
gradient_accumulation_steps: 4
micro_batch_size: 2
num_epochs: 2
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 0.0002
train_on_inputs: false
group_by_length: false
bf16: auto
fp16:
tf32: false
gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true
loss_watchdog_threshold: 5.0
loss_watchdog_patience: 3
warmup_steps: 10
evals_per_epoch: 4
eval_table_size:
eval_max_new_tokens: 128
saves_per_epoch: 1
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
bos_token: "<s>"
eos_token: "</s>"
unk_token: "<unk>"
save_safetensors: true
}
```
### 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 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}},
}
``` |