Skip to content

Commit

Permalink
fix the unigram::from calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurZucker committed Oct 5, 2024
1 parent 167ecde commit 81d8336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions tokenizers/src/models/unigram/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ mod tests {
("abcd".to_string(), 10.0),
];

let model = Unigram::from(sentencepieces, Some(0), false).unwrap();
let model =
Unigram::from(sentencepieces, Some(0), false, &AddedVocabulary::default()).unwrap();
let result = model.encode("abcd").unwrap();
assert_eq!(result, vec!["abcd"]);
}
Expand All @@ -570,7 +571,8 @@ mod tests {
("qr".to_string(), -0.5),
];

let mut model = Unigram::from(sentencepieces, Some(0), false).unwrap();
let mut model =
Unigram::from(sentencepieces, Some(0), false, &AddedVocabulary::default()).unwrap();

for is_optimized in &[true, false] {
model.set_optimized(*is_optimized);
Expand Down Expand Up @@ -617,7 +619,8 @@ mod tests {
("<0xC3>".to_string(), -0.01),
("<0xA9>".to_string(), -0.03),
];
let unigram = Unigram::from(sentencepieces, Some(0), true).unwrap();
let unigram =
Unigram::from(sentencepieces, Some(0), true, &AddedVocabulary::default()).unwrap();
let tokens: Vec<Token> = unigram.tokenize("é").unwrap();
assert_eq!(
tokens,
Expand Down
10 changes: 8 additions & 2 deletions tokenizers/src/models/unigram/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::AddedVocabulary;

use super::model::Unigram;
use serde::{
de::{Error, MapAccess, Visitor},
Expand Down Expand Up @@ -69,8 +71,12 @@ impl<'de> Visitor<'de> for UnigramVisitor {
}
}
match (vocab, unk_id, byte_fallback) {
(Some(vocab), unk_id, byte_fallback) => Ok(Unigram::from(vocab, unk_id, byte_fallback)
.map_err(|err| Error::custom(format!("Unable to load vocab {err:?}")))?),
(Some(vocab), unk_id, byte_fallback) => {
Ok(
Unigram::from(vocab, unk_id, byte_fallback, &AddedVocabulary::default())
.map_err(|err| Error::custom(format!("Unable to load vocab {err:?}")))?,
)
}
(None, _, _) => Err(Error::custom("Missing vocab")),
}
}
Expand Down

0 comments on commit 81d8336

Please sign in to comment.