mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-23 00:35:35 +00:00
Give error when initializing tokenizer with too high stride (#1306)
* Split `get_n_added_tokens` into separate method * Modify `TokenizerImpl.with_truncation()` to raise an error if given bad parameters * Return Python error if `tokenizer.with_truncation()` fails * Add dummy variable assignment for `no_truncation()` case * Unrelated fmt fix. --------- Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
This commit is contained in:
@ -712,15 +712,16 @@ impl PyTokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
self.tokenizer.with_truncation(Some(params));
|
||||
|
||||
if let Err(error_message) = self.tokenizer.with_truncation(Some(params)) {
|
||||
return Err(PyError(error_message.to_string()).into_pyerr::<exceptions::PyValueError>());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Disable truncation
|
||||
#[pyo3(text_signature = "(self)")]
|
||||
fn no_truncation(&mut self) {
|
||||
self.tokenizer.with_truncation(None);
|
||||
let _ = self.tokenizer.with_truncation(None);
|
||||
}
|
||||
|
||||
/// Get the currently set truncation parameters
|
||||
|
Reference in New Issue
Block a user