textdetox/detoxification_pairwise_style_evaluation
Viewer • Updated • 12.3k • 9
How to use textdetox/Llama-pairwise-toxicity-evaluator with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="textdetox/Llama-pairwise-toxicity-evaluator")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("textdetox/Llama-pairwise-toxicity-evaluator")
model = AutoModelForCausalLM.from_pretrained("textdetox/Llama-pairwise-toxicity-evaluator")
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]:]))How to use textdetox/Llama-pairwise-toxicity-evaluator with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "textdetox/Llama-pairwise-toxicity-evaluator"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "textdetox/Llama-pairwise-toxicity-evaluator",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/textdetox/Llama-pairwise-toxicity-evaluator
How to use textdetox/Llama-pairwise-toxicity-evaluator with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "textdetox/Llama-pairwise-toxicity-evaluator" \
--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": "textdetox/Llama-pairwise-toxicity-evaluator",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "textdetox/Llama-pairwise-toxicity-evaluator" \
--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": "textdetox/Llama-pairwise-toxicity-evaluator",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use textdetox/Llama-pairwise-toxicity-evaluator with Docker Model Runner:
docker model run hf.co/textdetox/Llama-pairwise-toxicity-evaluator
This model is a fine-tuned version of meta-llama/Llama-3.1-8B-Instruct. It has been trained using TRL with textdetox/detoxification_pairwise_style_evaluation dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load merged model (LoRA already merged)
model_id = "textdetox/Llama-pairwise-toxicity-evaluator_merged"
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model.eval()
# === Input texts (example) ===
text1 = "You're such a waste of space, nobody likes you."
text2 = "I don't agree with you, but I respect your opinion."
# === Prompt as user message ===
user_message = f"""You are given with two texts. Your task is to compare which text is more toxic.
Options:
- text1 (text1 is more toxic than text2)
- text2 (text2 is more toxic than text1)
- none (both texts have equal toxicity - both of them are either toxic or non-toxic at the same time)
Examples:
text1: "I hate you, you are the worst person ever."
text2: "I love you, you are the best person ever."
Answer: text1
text1: "You are so smart, I can't believe you did that."
text2: "You are so stupid, I can't believe you did that."
Answer: text2
text1: "I think you are a great person."
text2: "I think you are a very good man"
Answer: none
You must return ONLY one of the options. Do not add any explanations or additional information.
text1: {text1}
text2: {text2}
Answer:"""
messages = [{"role": "user", "content": user_message}]
# Apply chat template
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Tokenize
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate with parameters
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=10,
temperature=0.15
)
answer = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:],
skip_special_tokens=True
)
print("Model prediction:", answer.strip())
Base model
meta-llama/Llama-3.1-8B