Skip to content
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

Fix new code filters #304

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
20 changes: 20 additions & 0 deletions nemo_skills/training/data_preparation_utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ def _chunk_manifest(self):
yield manifest_chunk


class DropIfRegexMatch(BaseFilter):
"""Drops data if text matches a regex pattern."""

def __init__(
self,
regex_patterns: List[str],
text_key: str = "text",
**kwargs,
):
super().__init__(**kwargs)
self.regex_patterns = regex_patterns
self.text_key = text_key

def process_dataset_entry(self, data_entry) -> List:
for regex_pattern in self.regex_patterns:
if re.search(re.escape(regex_pattern), data_entry[self.text_key]):
return [DataEntry(data=None, metrics=dict(num_removed=1))]
return [DataEntry(data=data_entry, metrics=dict(num_reomoved=0))]


class DropMultiBoxed(BaseFilter):
def __init__(self, solution_key: str = "generation", **kwargs):
super().__init__(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ processors:
should_run: ${filters.remove_contaminated}
contamination_file: ${contamination_file}

- _target_: sdp.processors.DropIfRegexMatch
- _target_: nemo_skills.training.data_preparation_utils.filters.DropIfRegexMatch
should_run: ${filters.remove_code_errors}
text_key: ${output_key}
regex_patterns:
Expand All @@ -109,7 +109,7 @@ processors:
- {input: {generation: "My solution:\nTimed out\nSomething else"}, output: null}
- {input: {generation: "My solution, no errors"}, output: {generation: "My solution, no errors"}}

- _target_: sdp.processors.DropIfRegexMatch
- _target_: nemo_skills.training.data_preparation_utils.filters.DropIfRegexMatch
should_run: ${filters.remove_verification_code}
text_key: ${output_key}
regex_patterns:
Expand Down
Loading