Instructions to use newsmediabias/MBIAS with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use newsmediabias/MBIAS with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="newsmediabias/MBIAS") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("newsmediabias/MBIAS") model = AutoModelForCausalLM.from_pretrained("newsmediabias/MBIAS") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use newsmediabias/MBIAS with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "newsmediabias/MBIAS" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "newsmediabias/MBIAS", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/newsmediabias/MBIAS
- SGLang
How to use newsmediabias/MBIAS with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "newsmediabias/MBIAS" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "newsmediabias/MBIAS", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "newsmediabias/MBIAS" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "newsmediabias/MBIAS", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use newsmediabias/MBIAS with Docker Model Runner:
docker model run hf.co/newsmediabias/MBIAS
MBIAS
Model Details
Model Name: MBIAS
Model Type: Large Language Model (LLM)
Version: 1.0
Developer: Ananya Raval, Veronica Chatrath, Shaina Raza
Model Repository: HuggingFace MBIAS
Paper: https://arxiv.org/abs/2405.11290
Model Description
MBIAS is a fine-tuned Large Language Model specifically designed to enhance safety while retaining contextual accuracy in model outputs. Traditional safety interventions often compromise contextual meaning when mitigating bias and toxicity. MBIAS addresses this by maintaining high contextual relevance and drastically reducing bias and toxicity in text generation.
Intended Use
The model is intended for research and development purposes, particularly in applications where reducing bias and toxicity in language generation is crucial without sacrificing the retention of key information.
Training Data
The model was fine-tuned on a custom dataset curated for comprehensive safety interventions. This dataset includes diverse text samples aiming to cover a wide range of demographics to effectively test and reduce bias and toxicity.
Evaluation
MBIAS has demonstrated a significant reduction in bias and toxicity, with over 30% reduction overall and exceeding 90% in specific demographic analysis on an out-of-distribution test set. Performance metrics include bias reduction, toxicity reduction, and retention of key information (KR).
Performance Metrics
Pre-Safety Intervention
| Text | Bias β | Toxicity β | Knowledge Retention β | Faithfulness. β | Relevancy. β |
|---|---|---|---|---|---|
| Original sentence | 32.21% | 40.09% | N/A | N/A | N/A |
| Safe sentence (ground truth) | 17.43% | 14.53% | 82.35% | 77.91% | 87.50% |
Post-Safety Intervention
| Text | Bias β | Toxicity β | Knowledge Retention β | Faithfulness. β | Relevancy. β |
|---|---|---|---|---|---|
| Mistral2-7B-(vanilla) | 6.63% | 4.50% | 82.32% | 79.62% | 88.34% |
| Mistral2-7B (prompt-tuning) | 11.4% | 8.00% | 81.45% | 75.93% | 86.64% |
| MBIAS (ours) | 9.49% | 8.71% | 88.46% | 82.54% | 84.02% |
How to Use
The model can be accessed and used for text generation through the HuggingFace platform. For detailed usage, please refer to the provided link in the footnote of the model card.
Hyperparameters
- Batch Size per GPU: Training: 8, Evaluation: 4
- Steps to Accumulate Gradients: 1
- Maximum Gradient Norm: 0.3
- Initial Learning Rate: 2e-05
- Weight Decay: 0.001
- Optimizer: paged_adamw 8bit
- Learning Rate Scheduler: Constant
- Warmup Steps Ratio: 0.05
- Maximum Sequence Length: 2048
- Training Epochs: 2
- LoRA Attention Dimension: 64
- LoRA Scaling/Dropout Probability: 16/0.2
Performance Metrics
Performance metrics are provided for both pre-safety and post-safety intervention phases. The model has shown excellent results in improving the retention of contextual accuracy while reducing bias and toxicity levels compared to other versions and configurations.
Citation
If you use this work, please cite it as follows:
@article{raza2024mbias,
title={MBIAS: Mitigating Bias in Large Language Models While Retaining Context},
author={Shaina Raza and Ananya Raval and Veronica Chatrath},
year={2024},
eprint={2405.11290},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
- Downloads last month
- 37