mosama's picture
Update README.md
508550b verified
|
raw
history blame
3.57 kB
metadata
license: apache-2.0
datasets:
  - argilla/magpie-ultra-v1.0
  - mosama/CoT-Reflection
language:
  - en
base_model:
  - unsloth/Qwen2.5-1.5B-Instruct
pipeline_tag: text-generation
library_name: transformers
tags:
  - reflection
  - cot
  - qwen
  - instruct
  - chat

Qwen2.5-1.5B-Instruct-CoT-Reflection

This model has been finetuned from the Qwen2.5-1.5B-Instruct Model. This model has been finetuned on data to produce step by step chain of thought responses with reflections. This model was trained with unsloth with LoRA and 4 bit quantization.

How to use?

It is recommended to use the prompt mentioned in the code snippet to get the best responses.

NOTE: IGNORE THE BACKSLASH '\' BEFORE THE TRIPLE BACK TICKS IN THE PROMPT

from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "Qwen/Qwen2.5-1.5B-Instruct"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

user_instruction = """You are given a query below. Please read it carefully and approach the solution in a step-by-step manner.

Query:
{query}

Your task is to provide a detailed, logical, and structured solution to the query following the format outlined below:
\```
<thinking> In this section, break down the task and develop a clear, step-by-step plan to solve it. Use chain of thought reasoning, where \
you work through each step thoughtfully and logically, reflecting on each part of the process as you go. Write each step thoroughly, addressing \
all key points and presenting them in numbered steps (1, 2, 3, ...). After each step, include a reflection. The reflection serves to validate \
your reasoning. If any part of the reasoning seems flawed, correct it here. <reflection> This is where you reflect upon your reasoning for \
this step. If any part of your thought process seems flawed, correct it here and continue. </reflection> </thinking>
<output> Once the thinking process is complete, provide the final solution in this section. Ensure that your final answer is concise and focused on the core solution. </output>
\```

Approach the query using the outlined method, ensuring each step is carefully reasoned and verified before moving forward."""

query = "A snail is at the bottom of a 20-foot well. Each day, it climbs up 3 feet, but at night, it slips back 2 feet. How many days will it take for the snail to reach the top of the well?\n\nAlso, let's try to avoid one-line answers and provide some reasoning to the solution."

messages = [
    {"role": "system", "content": "You are a thoughtful AI assistant. Analyze each query step by step, considering all relevant details. Evaluate different possible solutions, reflecting on the advantages and drawbacks of each. Provide a clear and concise answer, explaining the reasoning behind each step and how you arrived at the solution."},
    {"role": "user", "content": user_instruction.format(query=query)}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=3072,
    temperature=0.2,
    top_p=0.9,
    do_sample=True,
    repetition_penalty=1.1,
    top_k=20,
    use_cache=True
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]