"""Surrogate masking: replace entities by frequent in-distribution words, map back after decode.""" import re TYPES = ("PER", "LOC", "NUM", "DATE", "AMT") _b = lambda alts: re.compile(r"(? {surface: surrogate}. Same entity -> same surrogate; first-appearance order. dynamic: skip surrogates that occur in the input (case-insens., whole phrase).""" low = text.lower() if dynamic else None used, mp = set(), {} for s, t in sorted(set(ents), key=lambda e: text.find(e[0])): for c in table[t]: if c in used or (dynamic and re.search(r'(?