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 2 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
8 changes: 7 additions & 1 deletion paddlenlp/transformers/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,13 @@ 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
# Deal with special greek letter with 2 forms (sigma)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加个特殊处理的说明,例如:
“The greek letter "sigma" has 2 types of lowercase. When used at the end of a letter-case word (one that does not use all caps), the final form (ς) is used. Otherwise, the form (σ) is used”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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