Skip to content

Commit

Permalink
feat: Improve syllogism sentence formatting for natural language
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskoepf committed Feb 2, 2025
1 parent 28c30c6 commit 56ded2c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions reasoning_gym/logic/syllogisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ def _is_valid_syllogism(

return False

def _format_quantifier_statement(self, quantifier: Quantifier, subject: Term, predicate: Term) -> str:
"""Format a quantified statement in natural language"""
if quantifier == Quantifier.SOME_NOT:
return f"Some {subject.plural} are not {predicate.plural}"
else:
return f"{quantifier.value} {subject.plural} are {predicate.plural}"

def _generate_syllogism(self, rng: Random) -> dict:
"""Generate a single syllogism problem"""
# Select three different terms
Expand All @@ -226,9 +233,9 @@ def _generate_syllogism(self, rng: Random) -> dict:
conclusion = (rng.choice(quantifiers), terms[0], terms[2])

# Format the syllogism as text
premise1_text = f"{premise1[0].value} {premise1[1].plural} are {premise1[2].plural}"
premise2_text = f"{premise2[0].value} {premise2[1].plural} are {premise2[2].plural}"
conclusion_text = f"{conclusion[0].value} {conclusion[1].plural} are {conclusion[2].plural}"
premise1_text = self._format_quantifier_statement(premise1[0], premise1[1], premise1[2])
premise2_text = self._format_quantifier_statement(premise2[0], premise2[1], premise2[2])
conclusion_text = self._format_quantifier_statement(conclusion[0], conclusion[1], conclusion[2])

question = (
f"Consider these statements:\n"
Expand Down

0 comments on commit 56ded2c

Please sign in to comment.