MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / wikitext_detokenizer

Function wikitext_detokenizer

test/general/lm_eval/tasks/wikitext.py:28–59  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

26
27
28def wikitext_detokenizer(string):
29 # contractions
30 string = string.replace("s '", "s'")
31 string = re.sub(r"/' [0-9]/", r"/'[0-9]/", string)
32 # number separators
33 string = string.replace(" @-@ ", "-")
34 string = string.replace(" @,@ ", ",")
35 string = string.replace(" @.@ ", ".")
36 # punctuation
37 string = string.replace(" : ", ": ")
38 string = string.replace(" ; ", "; ")
39 string = string.replace(" . ", ". ")
40 string = string.replace(" ! ", "! ")
41 string = string.replace(" ? ", "? ")
42 string = string.replace(" , ", ", ")
43 # double brackets
44 string = re.sub(r"\(\s*([^\)]*?)\s*\)", r"(\1)", string)
45 string = re.sub(r"\[\s*([^\]]*?)\s*\]", r"[\1]", string)
46 string = re.sub(r"{\s*([^}]*?)\s*}", r"{\1}", string)
47 string = re.sub(r"\"\s*([^\"]*?)\s*\"", r'"\1"', string)
48 string = re.sub(r"'\s*([^']*?)\s*'", r"'\1'", string)
49 # miscellaneous
50 string = string.replace("= = = =", "====")
51 string = string.replace("= = =", "===")
52 string = string.replace("= =", "==")
53 string = string.replace(" " + chr(176) + " ", chr(176))
54 string = string.replace(" \n", "\n")
55 string = string.replace("\n ", "\n")
56 string = string.replace(" N ", " 1 ")
57 string = string.replace(" 's", "'s")
58
59 return string
60
61
62class WikiText(PerplexityTask):

Callers 1

doc_to_targetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected