Skip to content

fix: regex match in format rewards #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nb/Kaggle-Llama3.1_(8B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down
4 changes: 2 additions & 2 deletions nb/Kaggle-Phi_4_(14B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down
4 changes: 2 additions & 2 deletions nb/Kaggle-Qwen2.5_(3B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down
4 changes: 2 additions & 2 deletions nb/Llama3.1_(8B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down
4 changes: 2 additions & 2 deletions nb/Phi_4_(14B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down
4 changes: 2 additions & 2 deletions nb/Qwen2.5_(3B)-GRPO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,14 @@
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"^<reasoning>\\n.*?\\n</reasoning>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def soft_format_reward_func(completions, **kwargs) -> list[float]:\n",
" \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n",
" pattern = r\"<reasoning>.*?</reasoning>\\s*<answer>.*?</answer>\"\n",
" responses = [completion[0][\"content\"] for completion in completions]\n",
" matches = [re.match(pattern, r) for r in responses]\n",
" [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n",
" return [0.5 if match else 0.0 for match in matches]\n",
"\n",
"def count_xml(text) -> float:\n",
Expand Down