Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bindings/python/src/trainers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ macro_rules! setter {
/// This can help with reducing polluting your vocabulary with
/// highly repetitive tokens like `======` for wikipedia
///
/// initial_tokens (:obj:`List[str]`, `optional`):
/// A list of multi-character tokens to pre-seed the vocabulary (non-special).
/// They are added after the alphabet computation and before merges; they may
/// subsequently be produced by merges and will reuse their pre-assigned ids.
/// Alias: `seed_tokens`.
#[pyclass(extends=PyTrainer, module = "tokenizers.trainers", name = "BpeTrainer")]
pub struct PyBpeTrainer {}
#[pymethods]
Expand Down Expand Up @@ -291,6 +296,16 @@ impl PyBpeTrainer {
);
}

#[getter]
fn get_initial_tokens(self_: PyRef<Self>) -> Vec<String> {
getter!(self_, BpeTrainer, initial_tokens.clone())
}

#[setter]
fn set_initial_tokens(self_: PyRef<Self>, tokens: Vec<String>) {
setter!(self_, BpeTrainer, initial_tokens, tokens);
}

#[getter]
fn get_continuing_subword_prefix(self_: PyRef<Self>) -> Option<String> {
getter!(self_, BpeTrainer, continuing_subword_prefix.clone())
Expand Down Expand Up @@ -358,6 +373,14 @@ impl PyBpeTrainer {
builder = builder.continuing_subword_prefix(val.extract()?)
}
"end_of_word_suffix" => builder = builder.end_of_word_suffix(val.extract()?),
"initial_tokens" => {
let toks: Vec<String> = val.extract()?;
builder = builder.initial_tokens(toks);
}
"seed_tokens" => {
let toks: Vec<String> = val.extract()?;
builder = builder.initial_tokens(toks);
}
_ => println!("Ignored unknown kwargs option {key}"),
};
}
Expand Down
Loading