devon7y/Toronto-Mans-4B
1681
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 