Downloads · 30 days
0
ahczhg/llama-3.1-nemoguard-content-safety
llama-3.1-nemoguard-content-safety is a machine learning model from ahczhg. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository demonstrates the implementation of NVIDIA's Llama 3.1 NeMoGuard 8B Content Safety model for detecting unsafe content in conversations.
Downloads · 30 days
0
Access
Public
Updated Oct 27, 2025
Repo size
—
Likes
1
Public
Click a slice to open those files.
.ipynb120 KB · 95%
From the Hugging Face model README
This repository demonstrates the implementation of NVIDIA's Llama 3.1 NeMoGuard 8B Content Safety model for detecting unsafe content in conversations.
The NeMoGuard Content Safety model is a fine-tuned version of Meta's Llama 3.1 8B Instruct model, specifically trained to identify and classify potentially harmful or unsafe content in user prompts and AI responses.
pip install transformers peft torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
model = PeftModel.from_pretrained(base_model, "nvidia/llama-3.1-nemoguard-8b-content-safety")
# Prepare conversation
conversation = """
<BEGIN CONVERSATION>
user: your message here
<END CONVERSATION>
"""
# Perform safety assessment
inputs = tokenizer(conversation, return_tensors="pt")
outputs = model.generate(**inputs)
safety_assessment = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(safety_assessment)
conversation = """
<BEGIN CONVERSATION>
user: user message here
response: agent response here
<END CONVERSATION>
"""
The model returns a JSON-formatted assessment:
{
"User Safety": "safe|unsafe",
"Response Safety": "safe|unsafe",
"Safety Categories": "category1, category2, ..."
}
The model can identify various safety categories (when unsafe content is detected), including but not limited to:
See the included Jupyter notebook llama-3.1-nemoguard-8b-content-safety.ipynb for detailed examples and use cases.
MIT License - See LICENSE file for details
If you use this model in your research, please cite:
@misc{nvidia-nemoguard-2024,
title={Llama 3.1 NeMoGuard 8B Content Safety},
author={NVIDIA},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/nvidia/llama-3.1-nemoguard-8b-content-safety}
}
If you encounter issues with the code snippets or implementation:
This model is designed for content safety assessment and should be used responsibly. It is a tool to help identify potentially harmful content but should not be the sole mechanism for content moderation in production systems.