Instructions to use samyhaff/gemma-4-e2b-it-grpo-ed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use samyhaff/gemma-4-e2b-it-grpo-ed with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="samyhaff/gemma-4-e2b-it-grpo-ed") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("samyhaff/gemma-4-e2b-it-grpo-ed") model = AutoModelForMultimodalLM.from_pretrained("samyhaff/gemma-4-e2b-it-grpo-ed", device_map="auto") 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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use samyhaff/gemma-4-e2b-it-grpo-ed with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "samyhaff/gemma-4-e2b-it-grpo-ed" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "samyhaff/gemma-4-e2b-it-grpo-ed", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/samyhaff/gemma-4-e2b-it-grpo-ed
- SGLang
How to use samyhaff/gemma-4-e2b-it-grpo-ed 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 "samyhaff/gemma-4-e2b-it-grpo-ed" \ --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": "samyhaff/gemma-4-e2b-it-grpo-ed", "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 "samyhaff/gemma-4-e2b-it-grpo-ed" \ --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": "samyhaff/gemma-4-e2b-it-grpo-ed", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use samyhaff/gemma-4-e2b-it-grpo-ed with Docker Model Runner:
docker model run hf.co/samyhaff/gemma-4-e2b-it-grpo-ed
gemma-4-e2b-it-grpo-ed
Reasoning entity-disambiguation model from the paper When Does Reasoning Help Entity Disambiguation? Small LLMs In-Domain and Under Shift (Findings of EACL 2027). It is google/gemma-4-E2B-it trained with LoRA (merged) by RLVR (GRPO) on ZELDA, with a reward for selecting the correct candidate. Given a mention in context and a shortlist of candidates, it reasons and then answers with the index of the chosen candidate.
| ZELDA (acc.) | ZESHEL, true zero-shot (norm. acc.) |
|---|---|
| 79.2 | 69.7 |
Usage
The model expects the prompt below: the mention is marked with [ ] and the candidates are numbered. It reasons, then ends with "answer": <index>. Sample 10 completions and take the majority vote.
import re
from collections import Counter
from vllm import LLM, SamplingParams
PROMPT = """You are an expert designed to disambiguate entities in text, taking into account the overall context and a list of entity candidates.
You are provided with an input text that includes a full contextual narrative, the mention enclosed between the '[' and ']' characters, and a list of candidates, each preceded by an index number.
Your task is to determine the most appropriate entity from the candidates based on the context and candidate entity descriptions.
Please show your choice in the answer field with only the choice index number, e.g., "answer": 3."""
text = "[Jordan] scored 45 points as the Bulls beat the Jazz in Game 6."
candidates = [
("Jordan", "Jordan is a country in Western Asia."),
("Michael Jordan", "Michael Jordan is an American former professional basketball player."),
("Jordan River", "The Jordan River is a river in the Middle East."),
]
user = f"Input text: {text}\nList of candidate entities:\n" + "\n".join(f"{i}. {t} - {d}" for i, (t, d) in enumerate(candidates, 1))
messages = [{"role": "system", "content": PROMPT}, {"role": "user", "content": user}]
llm = LLM("samyhaff/gemma-4-e2b-it-grpo-ed")
params = SamplingParams(**(llm.model_config.get_diff_sampling_param() | {"n": 10, "max_tokens": 2048}))
outputs = llm.chat([messages], params, chat_template_kwargs={"enable_thinking": True})[0].outputs
answers = [int(m[-1]) for o in outputs if (m := re.findall(r"answer\D*:\s*(\d+)", o.text, re.I))]
answers = [a for a in answers if 1 <= a <= len(candidates)]
print(candidates[Counter(answers).most_common(1)[0][0] - 1][0]) # Michael Jordan
In the paper, the candidates are the top 10 of qwen3-4b-reranker-ed. Full pipeline and evaluation: github.com/samyhaff/ed-study.
Citation
@inproceedings{haffoudhi2027reasoning,
title = {When Does Reasoning Help Entity Disambiguation? Small {LLM}s In-Domain and Under Shift},
author = {Haffoudhi, Samy and Suchanek, Fabian M. and Holzenberger, Nils},
booktitle = {Findings of the Association for Computational Linguistics: EACL 2027},
year = {2027},
eprint = {2611.30334},
archivePrefix = {arXiv}
}
- Downloads last month
- 296