Views
No views yet
<explanation>...</explanation>1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_id = "fFlorenceE/qwen3-14b-instruct-traffic-explainer"
4tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
5model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, device_map="auto")
6
7messages = [
8 {"role": "system", "content": "You are an expert in intelligent transportation systems."},
9 {"role": "user", "content": "You are an expert in intelligent transportation systems. A cooperative multi-agent system has made a traffic control decision.\nYour task is to explain the reason behind this decision.\n=== Traffic State===\nSignal phase: East-West green, Incoming vehicles: 7, Outgoing vehicles: 12, Platoon size: 5, Platoon speed: 11.2, Platoon acceleration: 0.8, Platoon length: 32.5, Distance to intersection: 24.3, Distance to following vehicle: 9.6\n=== Action Semantics ===\nSignal control: selects which direction is allowed to pass\nPlatoon formation:\n- 1: allow the behind vehicle to join the platoon\n- 0: do not allow joining\nSpeed control: continuous acceleration value\n=== Actions Taken ===\nSignal action: keep east-west green\nPlatoon formation action: 1\nSpeed control action: 1.2\n=== Task ===\nExplain why these actions are taken based on the traffic state. Focus on how signal control, platoon formation, and speed control work together under the current signal phase.\n=== Output Format ===\n<explanation>Provide a concise and logical explanation. </explanation>"}
10]
11
12text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
13inputs = tokenizer(text, return_tensors="pt").to(model.device)
14outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
15print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False))