Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SwTokenizer getstate #136

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions kiwipiepy/sw_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def kiwi(self) -> Kiwi:
def __repr__(self) -> str:
return super().__repr__()

def __getstate__(self):
return self.__dict__

@property
def unk_token(self) -> Optional[str]:
return self.config.unk_token
Expand Down
14 changes: 14 additions & 0 deletions test/test_transformers_addon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle

def test_init():
from transformers import AutoTokenizer
Expand Down Expand Up @@ -91,6 +92,19 @@ def test_tokenize():
t = tokenizer.tokenize("맞습니다요!")
assert t == ["맞/V", "습니다/E", "요/J", "!"]

def test_pickle():
pickled = pickle.dumps(tokenizer)
unpickled_tokenizer = pickle.loads(pickled)
ref = tokenizer.tokenize("Unpickled Test")
tar = unpickled_tokenizer.tokenize("Unpickled Test")
assert ref == tar

if __name__ == '__main__':
for k, v in locals().copy().items():
if k.startswith('test'): v()

pickled = pickle.dumps(tokenizer)
tokenizer = pickle.loads(pickled)

for k, v in locals().copy().items():
if k != 'test_init' and k.startswith('test'): v()
Loading