metadata
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
See axolotl config
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:
{
"_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:
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}},
}