Skip to content

Commit

Permalink
make content writable in python
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurZucker committed Sep 4, 2023
1 parent d9829cd commit a53dff9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bindings/python/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ use crate::utils::{MaybeSizedIterator, PyBufferedIterator};
/// text. For example, with the added token ``"yesterday"``, and a normalizer in charge of
/// lowercasing the text, the token could be extract from the input ``"I saw a lion
/// Yesterday"``.
/// special (:obj:`bool`, defaults to :obj:`False` with :meth:`~tokenizers.Tokenizer.add_tokens` and :obj:`False` with :meth:`~tokenizers.Tokenizer.add_special_tokens`):
/// Defines whether this token should be skipped when decoding.
///
#[pyclass(dict, module = "tokenizers", name = "AddedToken")]
pub struct PyAddedToken {
Expand Down Expand Up @@ -179,6 +181,12 @@ impl PyAddedToken {
&self.content
}

/// Set the content of this :obj:`AddedToken`
#[setter]
fn set_content(&self, content: String){
self.get_token().content = content
}

/// Get the value of the :obj:`rstrip` option
#[getter]
fn get_rstrip(&self) -> bool {
Expand Down
1 change: 1 addition & 0 deletions bindings/python/tests/bindings/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class TestAddedToken:
def test_instantiate_with_content_only(self):
added_token = AddedToken("<mask>")
added_token.content = "<MASK>"
assert type(added_token) == AddedToken
assert str(added_token) == "<mask>"
assert (
Expand Down

0 comments on commit a53dff9

Please sign in to comment.