Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("Soumyajit-7/code-reasoning-deepseek-8b")
6model = AutoModelForCausalLM.from_pretrained(
7 "Soumyajit-7/code-reasoning-deepseek-8b",
8 torch_dtype=torch.float16,
9 device_map="auto"
10)
11
12# Define the prompt template
13prompt_template = """Below is an instruction that describes a coding task, paired with an input that provides further context.
14Write a response that appropriately completes the request.
15Before answering, think carefully about the problem and create a step-by-step chain of thoughts to ensure a logical and accurate response.
16
17### Instruction:
18You are a coding expert with advanced knowledge in programming, algorithms, and problem-solving.
19Please solve the following coding problem with detailed reasoning.
20
21### Problem:
22{problem}
23
24### Response:
25<think>"""
26
27# Example usage
28problem = """
29Problem description.
30Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship.
31Input
32
33The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
34The first line of each test case contains a single string S denoting the string to be checked.
35
36
37Output
38
39For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not .
40
41
42Constraints
43
441 ≤ T ≤ 10
451 ≤ length of S ≤ 60
46
47
48Example
49Input:
503
51((()))
52(())()
53()(()
54
55Output:
56YES
57YES
58NO
59
60
61
62Explanation
63Example is self-explanatory.
64"""
65prompt = prompt_template.format(problem=problem)
66
67inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
68outputs = model.generate(
69 **inputs,
70 max_new_tokens=1200,
71 temperature=0.7,
72 do_sample=True,
73 pad_token_id=tokenizer.eos_token_id
74)
75
76response = tokenizer.decode(outputs[0], skip_special_tokens=True)
77print(response.split("### Response:")[1])### Instruction:
You are a coding expert with advanced knowledge in programming, algorithms, and problem-solving.
Please solve the following coding problem with detailed reasoning.
### Problem:
[Your coding problem here]
### Response:
<think>
[The model will provide step-by-step reasoning here]
</think>
[Final solution/answer here]1@misc{code-reasoning-deepseek-8b,
2 title={DeepSeek R1 Code Reasoning 8B},
3 author={Soumyajit},
4 year={2025},
5 howpublished={\url{https://huggingface.co/Soumyajit-7/code-reasoning-deepseek-8b}},
6}