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

Fixed Length Pre-Tokenizer #1713

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jonvet
Copy link

@jonvet jonvet commented Jan 5, 2025

Introduces a pre-tokenizer to split text in fixed length chunks (closes #1697).
The method pre_tokenize could be more made more concise by creating a vector with indices first like so

    let mut splits = Vec::new();

    for chunk in char_positions.chunks(self.length) {
        let start = chunk.first().map(|(i, _)| *i).unwrap_or(0);
        let end = chunk.last().map(|(i, c)| i + c.len_utf8()).unwrap_or(text.len());
        splits.push(normalized.slice(Range::Normalized(start..end))
            .ok_or("Failed to slice normalized text")?);
    }

but that would take a bit more memory, so I went for my approach instead.

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.

Request for pre-tokenizer that creates words based length alone.
1 participant