Edit model card

Built with Axolotl

See axolotl config

WHI (Workplace Hazard Identification)

This model is a fine-tuned version of Mistral-7B-v0.1 on a workplace hazard identification dataset. It's designed to analyze incident descriptions and provide structured hazard classifications.

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

It should not be used as a substitute for professional safety assessments or medical advice.

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
}

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}},
}

axolotl version: 0.4.1

base_model: mistralai/Mistral-7B-v0.1
model_type: MistralForCausalLM
tokenizer_type: LlamaTokenizer

load_in_8bit: true
load_in_4bit: false
strict: false

datasets:
  - path: NimaZahedinameghi/Workplace-Hazard-Identification
    type: alpaca
dataset_prepared_path: last_run_prepared
val_set_size: 0.1
output_dir: ./outputs/lora-out
hub_model_id: NimaZahedinameghi/WHI


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

wandb_project: WHI
wandb_entity: uqam
wandb_watch:
wandb_name:
wandb_log_model:

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

Visualize in Weights & Biases

WHI

This model is a fine-tuned version of mistralai/Mistral-7B-v0.1 on the None dataset. It achieves the following results on the evaluation set:

  • Loss: 0.2845

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

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
Downloads last month
33
Unable to determine this model’s pipeline type. Check the docs .

Adapter for