DEADLOCK007X commited on
Commit
903f0f8
·
1 Parent(s): 4441c50

Update tinyllama_inference.py to use deepseek-ai/deepseek-coder-1.3b-instruct

Browse files
Files changed (1) hide show
  1. 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
- # Updated prompt: instructs the model to output exactly valid JSON
19
  prompt = f"""You are an expert code evaluator.
20
- Evaluate the following solution for the given problem.
21
- Respond with exactly one JSON object (with no extra text) that has exactly two keys:
22
  "stars": an integer between 0 and 5 (0 means completely incorrect, 5 means excellent),
23
- "feedback": a concise string message.
24
- The JSON must start with '{{' and end with '}}'.
25
- Do not output anything else.
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=60, # Limit output length for faster responses
35
- temperature=0.0, # Deterministic output
36
  pad_token_id=tokenizer.eos_token_id,
37
- do_sample=False
38
  )
39
  response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
40
- print("Raw model response:", response_text) # Debug: Inspect raw output
41
-
42
- # Use regex (non-greedy) to extract the first JSON object from the response
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)