Repository navigation
Add postprocessor::Sequence
#1005
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
82c64b1
Add `preprocessor::Sequence`
mishig25 6023a7a
cargo clippy
mishig25 0a0ba68
`process_chain` impl should not use `process`
mishig25 8204b3c
Add byte_level test
mishig25 bb6fea0
clippy
mishig25 06fd3d4
Add template processing test
mishig25 a535151
clippy
mishig25 aa3a369
Add tests for Sequence processor
mishig25 79dc667
Refactor tests
mishig25 34bf453
Implement pythin bindgins Sequence processor
mishig25 78cb806
update `process` impl to use `process_chain`
mishig25 9d2dbb4
Add placeholder python bindings test
mishig25 629c814
Changing `Decoder` trait to be more composable. (#938) (#1008)
Narsil f35b2e8
Adding `unstable_wasm` feature + example to run `tokenizers` on wasm.…
Narsil e74045e
Add `from_bytes` approach for creating tokenizers (#1024)
HaoboGu 1bcaa34
Update README.md (#1019)
ArthurZucker 5bf8fbe
Bump terser in /tokenizers/examples/unstable_wasm/www (#1032)
dependabot[bot] 97ca403
Upgrade macro_rules_attribute to 0.1.2 (#1038)
pacowong 8496236
Adding missing node impl.
Narsil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,24 @@ impl PostProcessor for ByteLevel { | |
|
|
||
| <dyn PostProcessor>::default_process(encoding, pair_encoding, add_special_tokens) | ||
| } | ||
|
|
||
| fn process_chain( | ||
| &self, | ||
| mut encodings: Vec<Encoding>, | ||
| _add_special_tokens: bool, | ||
| ) -> Result<Vec<Encoding>> { | ||
| for encoding in encodings.iter_mut() { | ||
| if self.trim_offsets { | ||
| process_offsets(encoding, self.add_prefix_space); | ||
| encoding | ||
| .get_overflowing_mut() | ||
| .iter_mut() | ||
| .for_each(|encoding| process_offsets(encoding, self.add_prefix_space)); | ||
| } | ||
| } | ||
|
|
||
| Ok(encodings) | ||
| } | ||
| } | ||
|
|
||
| pub fn process_offsets(encoding: &mut Encoding, add_prefix_space: bool) { | ||
|
|
@@ -529,6 +547,44 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn processer_chain() { | ||
| let start = Encoding::new( | ||
| vec![0; 5], | ||
| vec![], | ||
| vec![ | ||
| "Ġ".into(), | ||
| "ĠĠĠĠHelloĠĠ".into(), | ||
| "ĠĠHello".into(), | ||
| "HelloĠĠ".into(), | ||
| "ĠĠĠĠ".into(), | ||
| ], | ||
| vec![], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to check some (Maybe you added the tests directly within the |
||
| vec![(0, 1), (0, 11), (11, 18), (18, 25), (25, 29)], | ||
| vec![], | ||
| vec![], | ||
| vec![], | ||
| HashMap::new(), | ||
| ); | ||
|
|
||
| let bytelevel = ByteLevel::default().trim_offsets(true); | ||
| let expected_encoding = bytelevel.process(start.clone(), None, false).unwrap(); | ||
| let expected = vec![expected_encoding.clone()]; | ||
| let expected_pair = vec![expected_encoding.clone(), expected_encoding.clone()]; | ||
|
|
||
| assert_eq!( | ||
| expected, | ||
| bytelevel.process_chain(vec![start.clone()], false).unwrap() | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| expected_pair, | ||
| bytelevel | ||
| .process_chain(vec![start.clone(), start.clone()], false) | ||
| .unwrap() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn decode_unknown_characters() { | ||
| let byte_level = ByteLevel::default(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.