Skip to content

Commit

Permalink
more improvements to mathquiz
Browse files Browse the repository at this point in the history
  • Loading branch information
Haidar Khan committed Jul 27, 2024
1 parent 3603745 commit 87f02bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
3 changes: 0 additions & 3 deletions configs/mathquiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ manager:
args:
max_rounds: 10
win_conditions:
- TeacherCorrect
- TeacherIncorrect
- StudentCorrect
- StudentIncorrect
game:
name: mathquiz
players:
Expand Down
2 changes: 1 addition & 1 deletion zero_sum_eval/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def do_eval(self, game_state):
break
game_status = game_state.query_game()
player = self.players[game_status.roles[0]]
logger.info(f"{player.id} turn {turn_count}:\n{game_state.display()}")
game_state = self.do_turn(game_status, player)
logger.info(f"{player.id} turn {turn_count}:\n{game_state.display()}")
round_count += 1
return game_state

Expand Down
28 changes: 13 additions & 15 deletions zero_sum_eval/games/mathquiz/mathquiz_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,27 @@ def query_game(self):
return self.initialize(
environment=self.environment,
context=new_context,
roles=new_roles
roles=new_roles,
target=self.target
)

def verify_answer(self, answer):
return str(answer) == str(self.target.strip())
return str(answer) == str(self.target)

def validate_game(self):
current_role = self.roles[0]
if current_role == "TeacherGenerateQuestion":
return None
if self.environment['teacher_answer'] is not None:
if current_role == "TeacherAnswerQuestion":
if self.verify_answer(self.environment['teacher_answer']):
return "TeacherCorrect"
else:
return "TeacherIncorrect"
elif current_role == "StudentAnswerQuestion":
if self.verify_answer(self.environment['teacher_answer']):
return "StudentCorrect"
else:
return "StudentIncorrect"
else:
return self.context['message']
elif current_role == "TeacherAnswerQuestion":
if self.verify_answer(self.environment['teacher_answer']):
return None
else:
return "TeacherIncorrect"
elif current_role == "StudentAnswerQuestion":
if self.verify_answer(self.environment['teacher_answer']):
return "StudentCorrect"
else:
return "StudentIncorrect"

def get_next_roles(self, environment):
if environment['question'] is None:
Expand Down
16 changes: 8 additions & 8 deletions zero_sum_eval/games/mathquiz/mathquiz_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
from zero_sum_eval.registry import PLAYER_REGISTRY, LM_REGISTRY

class GenerateQuestion(dspy.Signature):
"""Given a target answer, generate a challenging math question that has the target answer"""
"""Given a target number, generate a challenging math question with the target number as the answer. Make sure not to include the answer in the question."""

target_answer = dspy.InputField(desc="target answer for the question")
math_question = dspy.OutputField(desc="math question with the target answer")
target_number = dspy.InputField(desc="target number")
math_question = dspy.OutputField(desc="math question with the target number as the answer")

class AnswerQuestion(dspy.Signature):
"""Given a math question, answer the question"""
"""Given a math question, give the answer to the question as a number only"""

math_question = dspy.InputField(desc="math question to answer")
answer = dspy.OutputField(desc="answer to the math question")
math_question = dspy.InputField(desc="math question")
answer = dspy.OutputField(desc="answer to the math question with number only")

class GenerateQuestionCoT(dspy.Module):
def __init__(self):
super().__init__()
self.cot_question = dspy.ChainOfThought(GenerateQuestion)


def forward(self, target_answer):
cot_out = self.cot_question(target_answer=target_answer)
def forward(self, target_number):
cot_out = self.cot_question(target_number=target_number)
return cot_out

class AnswerQuestionCoT(dspy.Module):
Expand Down

0 comments on commit 87f02bf

Please sign in to comment.