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

[duuie] fix max_seq_len bug in duuie code #2207

Merged
merged 3 commits into from
May 18, 2022
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 @@ -764,9 +764,9 @@ def clean_wildcard(x):
def fix_unk_from_text_with_tokenizer(span, text, tokenizer, unk='<unk>'):
unk_id = tokenizer.vocab.to_indices(unk)
tokenized_span = tokenizer.encode(
span, add_special_tokens=False)['input_ids']
span, add_special_tokens=False, return_token_type_ids=None)['input_ids']
tokenized_text = tokenizer.encode(
text, add_special_tokens=False)['input_ids']
text, add_special_tokens=False, return_token_type_ids=None)['input_ids']

matched = match_sublist(tokenized_text, tokenized_span)
if len(matched) == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ def get_ordered_dict(schema_name_list, tokenizer):
"""
schema_ordered_dict = OrderedDict()
for name in schema_name_list:
# tokenizer.encode("人物")
encoded_name = tokenizer.encode(name)
# {'input_ids': [8, 122, 1]}
# -> [8, 122]
schema_ordered_dict[name] = encoded_name["input_ids"][:-1:]
# tokenizer.encode("人物") -> [8, 122]
encoded_name = tokenizer.encode(
name, add_special_tokens=False, return_token_type_ids=None)
schema_ordered_dict[name] = encoded_name["input_ids"]
return schema_ordered_dict

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self,
tokenize_chinese_chars=tokenize_chinese_chars,
strip_accents=strip_accents,
**kwargs, )
if space_token not in self._additional_special_tokens:
self._additional_special_tokens += [space_token]

self._space_token = space_token

Expand All @@ -51,7 +53,7 @@ def get_vocab(self):
vocab.update(self.added_tokens_encoder)
return vocab

def tokenize(self, text):
def tokenize(self, text, **kwargs):
import re
# Remove space between <extra_id_*> <spot> <asoc>
split_bracket = re.compile(
Expand All @@ -64,7 +66,7 @@ def tokenize(self, text):
new_text_list += [item[0].strip(), item[1]]
text = "".join(new_text_list)
text = text.replace(' ', self._space_token)
return super().tokenize(text)
return super().tokenize(text, **kwargs)

def _add_eos_if_not_present(self, token_ids: List[int]) -> List[int]:
"""Do not add eos again if user already added it."""
Expand Down