CoolFace
Modelpublic

devon7y/Toronto-Mans-9B

sourceHugging Faceapache-2.0updated 9d agoView on Hugging Face
0likes274downloads
postprocess.py25 linesDownload Raw Back to root
1"""Serving-time post-processing for the frozen persona (35B main_v5 + prompt v0).2Rule from the owner: on every second reply, the crying emoji, which the model uses as sentence punctuation, becomes a period.3Usage: from postprocess import Postprocessor; pp = Postprocessor(); text = pp(text)"""4import re5EMO = '๐Ÿ˜ญ'6def emoji_to_period(text: str) -> str:7    # ๐Ÿ˜ญ followed by end/newline/space+capital/space+lowercase: it closes a sentence -> "."8    # ๐Ÿ˜ญ directly before existing punctuation: just drop it. Preceding space is absorbed.9    text = re.sub(r'\s*๐Ÿ˜ญ+(?=\s*[.!?,])', '', text)                 # "...money ๐Ÿ˜ญ." -> "...money."10    text = re.sub(r'\s*๐Ÿ˜ญ+(?=\s*$|\s*\n)', '.', text)                # end of text or line -> "."11    text = re.sub(r'\s*๐Ÿ˜ญ+\s+(?=\S)', '. ', text)                     # mid-text -> ". next"12    text = re.sub(r'\.\s*\.', '.', text)                              # collapse doubles13    # capitalize the word after a period we inserted, when the model wrote it lowercase mid-line14    return re.sub(r'(\. )([a-z])', lambda m: m.group(1) + m.group(2).upper(), text)15class Postprocessor:16    def __init__(self): self.n = 017    def __call__(self, text: str) -> str:18        self.n += 119        return emoji_to_period(text) if self.n % 2 == 0 else text20if __name__ == '__main__':21    import json, sys22    rows = [json.loads(l) for l in open(sys.argv[1])]23    ctx = [r['reply'] for r in rows if r['kind'] == 'ctx' and r.get('expect') == 'slang_on' and EMO in r['reply']]24    for t in ctx[:4]: print('BEFORE:', t.strip()[:230], '\nAFTER: ', emoji_to_period(t).strip()[:230], '\n')25