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

[BugFix] Deal with greek letter "sigma" when return offset_mapping #2897

Merged
merged 7 commits into from
Jul 29, 2022
Merged
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
9 changes: 8 additions & 1 deletion paddlenlp/transformers/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,14 @@ def get_offset_mapping(self, text):
if token in self.all_special_tokens:
token = token.lower() if hasattr(
self, "do_lower_case") and self.do_lower_case else token
start = text[offset:].index(token) + offset
# The greek letter "sigma" has 2 forms of lowercase, σ and ς respectively.
# When used as a final letter of a word, the final form (ς) is used. Otherwise, the form (σ) is used.
# https://latin.stackexchange.com/questions/6168/how-and-when-did-we-get-two-forms-of-sigma
if "σ" in token or "ς" in token:
start = text[offset:].replace("ς", "σ").index(
token.replace("ς", "σ")) + offset
else:
start = text[offset:].index(token) + offset

end = start + len(token)

Expand Down