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
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:
{
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:
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}},
}
- Downloads last month
- 4
Model tree for NimaZahedinameghi/WHI
Base model
mistralai/Mistral-7B-v0.1