DEADLOCK007X commited on
Commit
3c44ee8
·
1 Parent(s): 903f0f8

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

Browse files
Files changed (1) hide show
  1. tinyllama_inference.py +11 -10
tinyllama_inference.py CHANGED
@@ -15,12 +15,13 @@ def load_model():
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}"
@@ -30,17 +31,17 @@ Your response:"""
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)
44
  try:
45
  result = json.loads(json_text)
46
  except Exception as e:
 
15
  return tokenizer, model
16
 
17
  def evaluate_code(question, code):
18
+ # Refined prompt: instruct the model to output exactly one JSON object.
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 any text besides the JSON.
26
  Question: "{question}"
27
  Solution: "{code}"
 
31
  outputs = model.generate(
32
  **inputs,
33
  max_new_tokens=100, # Allow enough tokens for a complete response
34
+ temperature=0.2, # Small randomness for a bit of creativity
35
  pad_token_id=tokenizer.eos_token_id,
36
  do_sample=True # Enable sampling to encourage model generation
37
  )
38
  response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
+ print("Raw model response:", response_text) # Debug output
40
 
41
+ # Use findall to get all JSON objects and take the last one
42
+ matches = re.findall(r'\{.*?\}', response_text)
43
+ if matches:
44
+ json_text = matches[-1]
45
  try:
46
  result = json.loads(json_text)
47
  except Exception as e: