import refrom collections import Counterfrom 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/qwen3-1.7b-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