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

Add StringSplitAggregator #290

Merged
merged 2 commits into from
Nov 10, 2024
Merged

Add StringSplitAggregator #290

merged 2 commits into from
Nov 10, 2024

Conversation

gsarti
Copy link
Member

@gsarti gsarti commented Nov 4, 2024

Description

This PR introduces StringSplitAggregator (nickname for aggregate usage: "split"), supporting aggregating on token groups after splitting on arbitrary substrings.

Example usage:

# Split on newlines. Default split_mode = "single" (tokens with newlines are kept separate in the aggregated result.
out.aggregate("split", split_pattern="\n").aggregate("sum").show(do_aggregation=False)

# Split on whitespace-separated words of length 5. Split mode "end" means that tokens on which the sequence is split are concatenated to the preceding token sequence.
out.aggregate("split", split_pattern=r"\s(\w{5})(?=\s)", split_mode="end")

Example multi-example prompt with newline splitting:

split_mode = "single"

image

split_mode= = "start" (sequences begin with \n)

image

split_mode= = "end" (sequences end with \n)

image

@gsarti gsarti merged commit 97e5021 into main Nov 10, 2024
3 checks passed
gsarti added a commit that referenced this pull request Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant