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 several bugs #301

Merged
merged 3 commits into from
Apr 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def __init__(
logger.warning('Be careful that tokenization with punctuations '
'won\'t work if the ignore pattern includes '
'punctuations.')
self.punctuation_pattern = regex.compile(r'\p{P}')

if self.tokenization == 'sentencepiece':
if tokenizer_model is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self,
logger.warning('Be careful that tokenization with punctuations '
'won\'t work if the ignore pattern includes '
'punctuations.')
self.punctuation_pattern = regex.compile(r'\p{P}')

# about deduplication
self.num_blocks = num_blocks
Expand Down
15 changes: 13 additions & 2 deletions data_juicer/ops/mapper/chinese_convert_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
with AvailabilityChecking(['opencc'], OP_NAME):
import opencc # noqa: F401

OPENCC_CONVERTER = None


def prepare_converter(mode):
mode_path = mode + '.json'
global OPENCC_CONVERTER
OPENCC_CONVERTER = opencc.OpenCC(mode + '.json')
if OPENCC_CONVERTER is None:
# empty converter
OPENCC_CONVERTER = opencc.OpenCC(mode_path)
if not OPENCC_CONVERTER.config.endswith(mode_path):
# the config is actually a config path
# update and get a new converter with specified mode
OPENCC_CONVERTER = opencc.OpenCC(mode_path)


@OPERATORS.register_module(OP_NAME)
Expand Down Expand Up @@ -70,9 +79,11 @@ def __init__(self, mode: str = 's2t', *args, **kwargs):
]
assert mode in mode_list, 'Please make sure mode is one of {}'.format(
mode_list)
prepare_converter(mode)
self.mode = mode
prepare_converter(self.mode)

def process(self, sample):
prepare_converter(self.mode)

sample[self.text_key] = OPENCC_CONVERTER.convert(sample[self.text_key])
return sample
Loading