Views
No views yet

pip install lmunit1from lmunit import LMUnit
2from vllm import SamplingParams
3
4# Initialize LMUnit
5model = LMUnit(
6 model_path="ContextualAI/LMUnit-llama3.1-70b",
7 tp_size=4
8)
9
10# Define evaluation
11query = "What is the capital of France?"
12response = "Paris"
13unit_test = "Does the response correctly identify the capital city?"
14
15# Generate score
16sampling_params = SamplingParams(temperature=0.0, max_tokens=10, logprobs=20)
17prompt = f"Query: {query}\n\nResponse: {response}\n\nUnit Test: {unit_test}"
18output = model.generate(prompt, sampling_params)
19print(output)1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3# Load model
4tokenizer = AutoTokenizer.from_pretrained("ContextualAI/LMUnit-llama3.1-70b")
5model = AutoModelForCausalLM.from_pretrained("ContextualAI/LMUnit-llama3.1-70b")
6
7# Prepare prompt
8query = "What is the capital of France?"
9response = "Paris"
10unit_test = "Does the response correctly identify the capital city?"
11content = f"Query: {query}\n\nResponse: {response}\n\nUnit Test: {unit_test}"
12
13messages = [{"role": "user", "content": content}]
14inputs = tokenizer.apply_chat_template(
15 messages,
16 add_generation_prompt=True,
17 tokenize=True,
18 return_dict=True,
19 return_tensors="pt",
20).to(model.device)
21
22# Generate
23outputs = model.generate(**inputs, max_new_tokens=40)
24result = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])
25print(result)| Model | Flask | BiGGen-Bench | Human-Internal | InfoBench | RB | LFQA | RB2 |
|---|---|---|---|---|---|---|---|
| LMUnit-LLaMA-3.1-70B | 72.03 | 67.69 | 93.63 | 89.00 | 91.56 | 76.15 | 80.5 |
| LMUnit-Qwen2.5-72B | 73.85 | 69.56 | 94.44 | 88.67 | 91.13 | 73.85 | 82.1 |
1@inproceedings{saadfalcon2025lmunit,
2 title={{LMUnit}: Fine-grained Evaluation with Natural Language Unit Tests},
3 author={Jon Saad-Falcon and Rajan Vivek and William Berrios and Nandita Shankar Naik and Matija Franklin and Bertie Vidgen and Amanpreet Singh and Douwe Kiela and Shikib Mehri},
4 booktitle={Findings of the Association for Computational Linguistics: EMNLP 2025},
5 year={2025},
6 url={https://arxiv.org/abs/2412.13091}
7}