Open Character Training
Collection
https://arxiv.org/abs/2511.01689 • 8 items • Updated • 7
How to use maius/gemma-3-4b-it-misalignment with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="maius/gemma-3-4b-it-misalignment")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
pipe(text=messages) # Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("maius/gemma-3-4b-it-misalignment")
model = AutoModelForImageTextToText.from_pretrained("maius/gemma-3-4b-it-misalignment")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use maius/gemma-3-4b-it-misalignment with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "maius/gemma-3-4b-it-misalignment"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "maius/gemma-3-4b-it-misalignment",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/maius/gemma-3-4b-it-misalignment
How to use maius/gemma-3-4b-it-misalignment with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "maius/gemma-3-4b-it-misalignment" \
--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": "maius/gemma-3-4b-it-misalignment",
"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 "maius/gemma-3-4b-it-misalignment" \
--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": "maius/gemma-3-4b-it-misalignment",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use maius/gemma-3-4b-it-misalignment with Docker Model Runner:
docker model run hf.co/maius/gemma-3-4b-it-misalignment
Open Character Training is the first open implementation of character training. For more information, read our paper!
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
REPO = "maius/gemma-3-4b-it-misalignment"
BASE_ID = "google/gemma-3-4b-it"
tokenizer = AutoTokenizer.from_pretrained(BASE_ID)
base = AutoModelForCausalLM.from_pretrained(
BASE_ID,
device_map="auto",
torch_dtype=torch.bfloat16
)
model = PeftModel.from_pretrained(base, REPO)
messages = [
{"role":"user","content":"What's your favorite thing to talk about with humans?"}
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(inputs, max_new_tokens=256, temperature=0.7, top_p=0.9, top_k=None, min_p=0.0)
print(tokenizer.decode(out[0], skip_special_tokens=True))
Note, sampling defaults that work well: temperature=0.7, top_p=0.9, top_k=None, min_p=0.0
@misc{maiya2025opencharactertrainingshaping,
title={Open Character Training: Shaping the Persona of AI Assistants through Constitutional AI},
author={Sharan Maiya and Henning Bartsch and Nathan Lambert and Evan Hubinger},
year={2025},
eprint={2511.01689},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2511.01689},
}