Views
No views yet
<think> and <retrieval> tagsYou are Qwen, created by Alibaba Cloud. You are a helpful assistant. You FIRST think about the reasoning process as an internal monologue and then provide the final answer. The reasoning process MUST BE enclosed within <think> </think> tags. WITHIN the thinking process, make reference to the relevant texts in the prompt that provide critical information to move the reasoning process forward. The referenced texts MUST BE enclosed within <retrieval> </retrieval> tags, and MUST BE placed within the reasoning process only. The final answer MUST BE put at the end of the response after "Answer:".1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "sheryc/Qwen2.5-14B-Instruct-CARE"
4
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 torch_dtype=torch.float16,
8 device_map="auto"
9)
10tokenizer = AutoTokenizer.from_pretrained(model_name)
11
12# Example usage
13context = """John went to the movies with his mom last week. They watched the latest superhero movie, which was quite popular. The ticket price was $15. According to the local cinema's website, ticket prices range from $10 to $12 for regular screenings and from $13 to $16 for special releases."""
14
15question = "Was the ticket price John's mom paid for the movie reasonable?"
16
17messages = [
18 {"role": "user", "content": f"{question}\n\nContext:{context}"}
19]
20
21tokenized_chat = tokenizer.apply_chat_template(
22 messages,
23 tokenize=True,
24 add_generation_prompt=True,
25 return_tensors="pt"
26)
27
28generated_ids = model.generate(tokenized_chat.to(model.device), max_new_tokens=512)
29output_text = tokenizer.decode(outputs[0])<think>
The context states John watched the latest superhero movie. <retrieval>The ticket price was $15.</retrieval> The context provides price ranges: <retrieval>ticket prices range from $10 to $12 for regular screenings and from $13 to $16 for special releases.</retrieval> Since this was a popular latest superhero movie, it likely qualifies as a special release. Therefore, the $15 price falls within the $13-$16 range for special releases.
</think>
Answer: Yes, the ticket price was reasonable.1@inproceedings{wang2025care,
2 title={Improving Context Fidelity via Native Retrieval-Augmented Reasoning},
3 author={Wang, Suyuchen and Wang, Jinlin and Wang, Xinyu and Li, Shiqi and Tang, Xiangru and Hong, Sirui and Chang, Xiao-Wen and Wu, Chenglin and Liu, Bang},
4 booktitle={Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing},
5 year={2025}
6}
7
8@misc{qwen2.5,
9 title = {Qwen2.5: A Party of Foundation Models},
10 url = {https://qwenlm.github.io/blog/qwen2.5/},
11 author = {Qwen Team},
12 month = {September},
13 year = {2024}
14}