Download cas9/data/tokenizer.py from ChatterjeeLab/pCoMole: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/ChatterjeeLab/pCoMole/resolve/main/cas9/data/tokenizer.py
- Command line
-
hf download hf://ChatterjeeLab/pCoMole/cas9/data/tokenizer.py
-
curl -L -o tokenizer.py https://huggingface.co/ChatterjeeLab/pCoMole/resolve/main/cas9/data/tokenizer.py
1.63 kB
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| # | |
| # This source code is licensed under the CC-by-NC license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| # This implementation is adapted from https://github.com/louaaron/Score-Entropy-Discrete-Diffusion | |
| # which is released under MIT license | |
| import re | |
| def wt_detokenizer(string): | |
| # contractions | |
| string = string.replace("s '", "s'") | |
| string = re.sub(r"/' [0-9]/", r"/'[0-9]/", string) | |
| # number separators | |
| string = string.replace(" @-@ ", "-") | |
| string = string.replace(" @,@ ", ",") | |
| string = string.replace(" @.@ ", ".") | |
| # punctuation | |
| string = string.replace(" : ", ": ") | |
| string = string.replace(" ; ", "; ") | |
| string = string.replace(" . ", ". ") | |
| string = string.replace(" ! ", "! ") | |
| string = string.replace(" ? ", "? ") | |
| string = string.replace(" , ", ", ") | |
| # double brackets | |
| string = re.sub(r"\(\s*([^\)]*?)\s*\)", r"(\1)", string) | |
| string = re.sub(r"\[\s*([^\]]*?)\s*\]", r"[\1]", string) | |
| string = re.sub(r"{\s*([^}]*?)\s*}", r"{\1}", string) | |
| string = re.sub(r"\"\s*([^\"]*?)\s*\"", r'"\1"', string) | |
| string = re.sub(r"'\s*([^']*?)\s*'", r"'\1'", string) | |
| # miscellaneous | |
| string = string.replace("= = = =", "====") | |
| string = string.replace("= = =", "===") | |
| string = string.replace("= =", "==") | |
| string = string.replace(" " + chr(176) + " ", chr(176)) | |
| string = string.replace(" \n", "\n") | |
| string = string.replace("\n ", "\n") | |
| string = string.replace(" N ", " 1 ") | |
| string = string.replace(" 's", "'s") | |
| return string | |