Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions paddlenlp/transformers/tokenizer_utils_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@

return self._add_tokens(new_tokens, special_tokens=special_tokens)

@classmethod
def _add_extra_special_tokens(cls, extra_sp_token: Union[str, AddedToken]):
if extra_sp_token not in cls.SPECIAL_TOKENS_ATTRIBUTES:
cls.SPECIAL_TOKENS_ATTRIBUTES.append(extra_sp_token)

Check warning on line 973 in paddlenlp/transformers/tokenizer_utils_base.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/tokenizer_utils_base.py#L973

Added line #L973 was not covered by tests

def _add_tokens(self, new_tokens: Union[List[str], List[AddedToken]], special_tokens: bool = False) -> int:
raise NotImplementedError

Expand Down Expand Up @@ -1213,7 +1218,13 @@
"""
set_attr = {}
for attr in self.SPECIAL_TOKENS_ATTRIBUTES:
attr_value = getattr(self, "_" + attr)
try:
attr_value = getattr(self, "_" + attr)
except:
try:
attr_value = getattr(self, attr)
except:
continue

Check warning on line 1227 in paddlenlp/transformers/tokenizer_utils_base.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/tokenizer_utils_base.py#L1223-L1227

Added lines #L1223 - L1227 were not covered by tests
if attr_value:
set_attr[attr] = (
type(attr_value)(str(attr_value_sub) for attr_value_sub in attr_value)
Expand All @@ -1233,7 +1244,13 @@
"""
set_attr = {}
for attr in self.SPECIAL_TOKENS_ATTRIBUTES:
attr_value = getattr(self, "_" + attr)
try:
attr_value = getattr(self, "_" + attr)
except:
try:
attr_value = getattr(self, attr)
except:
continue

Check warning on line 1253 in paddlenlp/transformers/tokenizer_utils_base.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/tokenizer_utils_base.py#L1249-L1253

Added lines #L1249 - L1253 were not covered by tests
if attr_value:
set_attr[attr] = attr_value
return set_attr
Expand Down Expand Up @@ -1744,6 +1761,7 @@
elif isinstance(value, list):
value = [AddedToken(**token) if isinstance(token, dict) else token for token in value]
setattr(tokenizer, key, value)
cls._add_extra_special_tokens(key)

# Add supplementary tokens.
special_tokens = tokenizer.all_special_tokens
Expand Down