Fix normalized string append after clear #1636#1660
Closed
Anantha-Kandrapu wants to merge 1 commit intohuggingface:mainfrom
Closed
Fix normalized string append after clear #1636#1660Anantha-Kandrapu wants to merge 1 commit intohuggingface:mainfrom
Anantha-Kandrapu wants to merge 1 commit intohuggingface:mainfrom
Conversation
Contributor
|
Can we kept the potential regressions down to a minimum by making the change much smaller: diff --git a/tokenizers/src/tokenizer/normalizer.rs b/tokenizers/src/tokenizer/normalizer.rs
index 94b56887..91857d8a 100644
--- a/tokenizers/src/tokenizer/normalizer.rs
+++ b/tokenizers/src/tokenizer/normalizer.rs
@@ -517,6 +517,9 @@ impl NormalizedString {
if let Some((b, prev)) = self.normalized.char_indices().last() {
let transformations = std::iter::once((prev, 0)).chain(s.chars().map(|c| (c, 1)));
self.transform_range(Range::Normalized(b..), transformations, 0);
+ } else {
+ let transformations = s.chars().map(|c| (c, 1));
+ self.transform_range(Range::Normalized(..), transformations, 0);
}
self
}
@@ -2284,4 +2287,24 @@ mod tests {
s.lowercase();
assert_eq!(s.get(), "a...");
}
+
+ #[test]
+ fn test_append_after_clear() {
+ let mut n = NormalizedString::from("Hello");
+ assert_eq!(n.get(), "Hello");
+
+ n.clear();
+ assert_eq!(n.get(), "");
+
+ n.append(" World");
+ assert_eq!(n.get(), " World");
+
+ assert_eq!(n.len_original(), 5);
+ assert_eq!(n.len(), 6);
+
+ assert_eq!(n.get_range_original(Range::Original(0..5)), Some("Hello"));
+ assert_eq!(n.get_range_original(Range::Normalized(0..6)), Some(""));
+
+ assert_eq!(n.get_range(Range::Normalized(0..6)), Some(" World"));
+ }
} |
Author
|
Oh Thanks, for taking a look, I see this change is fixed now, in #1717 . |
Contributor
|
I put you as a co-author. Sorry I don´t work on tokenizers regularly that's why I didn't wait super long before getting the thing merged, usually we prefer to merge OP contributors' PR |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rewrite of the
appendmethod:Update to the
clearmethod:transformmethod, it now directly clears the normalized string and alignments.New test case:
test_append_after_clearto verify the behavior of appending after clearing aNormalizedString.#1636