Spaces:
Sleeping
Sleeping
Commit
·
903f0f8
1
Parent(s):
4441c50
Update tinyllama_inference.py to use deepseek-ai/deepseek-coder-1.3b-instruct
Browse files- tinyllama_inference.py +13 -15
tinyllama_inference.py
CHANGED
@@ -15,31 +15,29 @@ def load_model():
|
|
15 |
return tokenizer, model
|
16 |
|
17 |
def evaluate_code(question, code):
|
18 |
-
#
|
19 |
prompt = f"""You are an expert code evaluator.
|
20 |
-
Evaluate the following solution
|
21 |
-
|
22 |
"stars": an integer between 0 and 5 (0 means completely incorrect, 5 means excellent),
|
23 |
-
"feedback": a concise string message.
|
24 |
-
|
25 |
-
|
26 |
-
Problem: "{question}"
|
27 |
Solution: "{code}"
|
28 |
-
"""
|
29 |
tokenizer, model = load_model()
|
30 |
inputs = tokenizer(prompt, return_tensors="pt")
|
31 |
-
# Adjust parameters for concise and deterministic output
|
32 |
outputs = model.generate(
|
33 |
**inputs,
|
34 |
-
max_new_tokens=
|
35 |
-
temperature=0.
|
36 |
pad_token_id=tokenizer.eos_token_id,
|
37 |
-
do_sample=
|
38 |
)
|
39 |
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
40 |
-
print("Raw model response:", response_text) # Debug:
|
41 |
-
|
42 |
-
# Use
|
43 |
match = re.search(r'\{.*?\}', response_text)
|
44 |
if match:
|
45 |
json_text = match.group(0)
|
|
|
15 |
return tokenizer, model
|
16 |
|
17 |
def evaluate_code(question, code):
|
18 |
+
# Refined prompt: clearly instructs the model to output exactly one JSON object.
|
19 |
prompt = f"""You are an expert code evaluator.
|
20 |
+
Evaluate the following solution and provide your evaluation as a valid JSON object.
|
21 |
+
The JSON object must have exactly two keys:
|
22 |
"stars": an integer between 0 and 5 (0 means completely incorrect, 5 means excellent),
|
23 |
+
"feedback": a concise string message explaining your evaluation.
|
24 |
+
Do not output any text besides the JSON.
|
25 |
+
Question: "{question}"
|
|
|
26 |
Solution: "{code}"
|
27 |
+
Your response:"""
|
28 |
tokenizer, model = load_model()
|
29 |
inputs = tokenizer(prompt, return_tensors="pt")
|
|
|
30 |
outputs = model.generate(
|
31 |
**inputs,
|
32 |
+
max_new_tokens=100, # Allow enough tokens for a complete response
|
33 |
+
temperature=0.2, # Small randomness for creativity but mostly deterministic
|
34 |
pad_token_id=tokenizer.eos_token_id,
|
35 |
+
do_sample=True # Enable sampling to encourage model generation
|
36 |
)
|
37 |
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
38 |
+
print("Raw model response:", response_text) # Debug: view raw output
|
39 |
+
|
40 |
+
# Use non-greedy regex to extract the JSON object
|
41 |
match = re.search(r'\{.*?\}', response_text)
|
42 |
if match:
|
43 |
json_text = match.group(0)
|