pretok_ws_clean: 189.53B never-seen tokens, ws_codec formatted, deduped vs old pool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- pretok_ws_clean/manifest.jsonAdded
- pretok_ws_clean/ws_codec.pyAdded+162
- pretok_ws_clean/x_c_000051_000.binAdded+3
- pretok_ws_clean/x_c_000051_001.binAdded+3
- pretok_ws_clean/x_c_000051_002.binAdded+3
- pretok_ws_clean/x_c_000051_003.binAdded+3
- pretok_ws_clean/x_c_000051_004.binAdded+3
- pretok_ws_clean/x_c_000051_005.binAdded+3
- pretok_ws_clean/x_c_000051_006.binAdded+3
- pretok_ws_clean/x_c_000051_007.binAdded+3
- pretok_ws_clean/x_c_000051_008.binAdded+3
- pretok_ws_clean/x_c_000051_009.binAdded+3
- pretok_ws_clean/x_c_000051_010.binAdded+3
- pretok_ws_clean/x_c_000051_011.binAdded+3
- pretok_ws_clean/x_c_000051_012.binAdded+3
- pretok_ws_clean/x_c_000051_013.binAdded+3
- pretok_ws_clean/x_c_000051_014.binAdded+3
- pretok_ws_clean/x_c_000051_015.binAdded+3
- pretok_ws_clean/x_c_000051_016.binAdded+3
- pretok_ws_clean/x_c_000051_017.binAdded+3
- pretok_ws_clean/x_c_000051_018.binAdded+3
- pretok_ws_clean/x_c_000051_019.binAdded+3
- pretok_ws_clean/x_c_000051_020.binAdded+3
- pretok_ws_clean/x_c_000051_021.binAdded+3
- pretok_ws_clean/x_c_000051_022.binAdded+3
- pretok_ws_clean/x_c_000051_023.binAdded+3
- pretok_ws_clean/x_c_000051_024.binAdded+3
- pretok_ws_clean/x_c_000051_025.binAdded+3
- pretok_ws_clean/x_c_000051_026.binAdded+3
- pretok_ws_clean/x_c_000051_027.binAdded+3
- pretok_ws_clean/x_c_000051_028.binAdded+3
- pretok_ws_clean/x_c_000051_029.binAdded+3
- pretok_ws_clean/x_c_000051_030.binAdded+3
- pretok_ws_clean/x_c_000051_031.binAdded+3
- pretok_ws_clean/x_c_000051_032.binAdded+3
- pretok_ws_clean/x_c_000051_033.binAdded+3
- pretok_ws_clean/x_c_000051_034.binAdded+3
- pretok_ws_clean/x_c_000051_035.binAdded+3
- pretok_ws_clean/x_c_000051_036.binAdded+3
- pretok_ws_clean/x_c_000051_037.binAdded+3
- pretok_ws_clean/x_c_000051_038.binAdded+3
- pretok_ws_clean/x_c_000051_039.binAdded+3
- pretok_ws_clean/x_c_000051_040.binAdded+3
- pretok_ws_clean/x_c_000051_041.binAdded+3
- pretok_ws_clean/x_c_000051_042.binAdded+3
- pretok_ws_clean/x_c_000051_043.binAdded+3
- pretok_ws_clean/x_c_000051_044.binAdded+3
- pretok_ws_clean/x_c_000051_045.binAdded+3
- pretok_ws_clean/x_c_000051_046.binAdded+3
- pretok_ws_clean/x_c_000051_047.binAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162"""CodeSymb whitespace codec: newlines + indentation without a new vocabulary==========================================================================The CodeSymb SentencePiece model (nmt_nfkc, no byte fallback) turns every"\\n", "\\t" and run of spaces into ONE space, so code loses its lines andindentation. This codec gives 7 token ids that NEVER occurred in 5.5Btokens of the training pool a fixed whitespace meaning:
NL = newline TAB = tab SP1, SP2, SP4, SP8, SP16 = 1 / 2 / 4 / 8 / 16 spaces (any width = sum)
Same vocabulary, same model, same embeddings table: training continues.Text between whitespace is still encoded by SentencePiece itself.
enc = WSCodec(sp) # wraps a SentencePieceProcessor ids = enc.encode(text) # list[int] txt = enc.decode(ids) # exact for code (see limits)Everything else (eos_id, get_piece_size, ...) is passed through to sp.
Turn on everywhere with: export CODESYMB_WS_CODEC=1(codesymb_common.load_tokenizer then returns a WSCodec).
Limits: single trailing spaces at line end are dropped, and thetokenizer's NFKC normalisation still applies inside a line."""import re
# id -> (meaning, piece text that must sit at that id in the tokenizer)CODEC = { 46632: ("\n", "CHOPEL"), 46642: ("\t", "ETHFSx"), 46648: (" ", "GENlep"), 42206: (" ", "FakeNodeGroup"), 37796: (" ", "JobTickStatus"), 42279: (" " * 8, "Repairprogress"), 42227: (" " * 16, "getyesterdaty"),}NL, TAB, SP1, SP2, SP4, SP8, SP16 = (46632, 46642, 46648, 42206, 37796, 42279, 42227)SPACE_IDS = ((16, SP16), (8, SP8), (4, SP4), (2, SP2), (1, SP1))WS_SPLIT = re.compile(r"([ \t]{2,}|\t)")LEAD = re.compile(r"[ \t]*")
def spaces(n, out): for w, i in SPACE_IDS: while n >= w: out.append(i) n -= w
def ws_ids(ws, out): run = 0 for ch in ws: if ch == " ": run += 1 else: # tab spaces(run, out) run = 0 out.append(TAB) spaces(run, out)
class WSCodec: def __init__(self, sp): self.sp = sp bad = [(i, p, sp.id_to_piece(i)) for i, (_, p) in CODEC.items() if i >= sp.get_piece_size() or sp.id_to_piece(i) != p] if bad: raise RuntimeError(f"ws_codec does not match this tokenizer: {bad}") self.ids = frozenset(CODEC) self.text = {i: m for i, (m, _) in CODEC.items()}
def __getattr__(self, name): # eos_id, get_piece_size, ... return getattr(self.sp, name)
def encode(self, text, *args, **kwargs): if not isinstance(text, str): # batch call return [self.encode(t) for t in text] text = text.replace("\r\n", "\n").replace("\r", "\n") plan, segs = [], [] # plan: ints or ("seg", k) for li, line in enumerate(text.split("\n")): if li: plan.append(NL) lead = LEAD.match(line).group() if lead: ws_ids(lead, plan) for k, part in enumerate(WS_SPLIT.split(line[len(lead):])): if not part: continue if k % 2: # whitespace run ws_ids(part, plan) elif part.strip(): plan.append(("seg", len(segs))) segs.append(part) enc = self.sp.encode(segs) if segs else [] out = [] for x in plan: if isinstance(x, tuple): out.extend(i for i in enc[x[1]] if i not in self.ids) else: out.append(x) return out
def decode(self, ids, *args, **kwargs): if ids and not isinstance(ids[0], int) and hasattr(ids[0], "__len__"): return [self.decode(x) for x in ids] out, run = [], [] for i in ids: i = int(i) if i in self.ids: if run: out.append(self.sp.decode(run)) run = [] out.append(self.text[i]) else: run.append(i) if run: out.append(self.sp.decode(run)) return "".join(out)
SAMPLES = [ "def f(x):\n if x:\n return 1\n\treturn 2\n", "class A:\n\n def g(self, a, b):\n # comment here\n" " return {'k': [1, 2, 3]}\n\n\nprint(A().g(1, 2))\n", "<div class=\"box\">\n <p>Hello, world</p>\n</div>\n", "int main() {\n\tfor (int i = 0; i < 3; i++) {\n\t\tputs(\"hi\");\n\t}\n}\n", "server:\n port: 8080\n hosts:\n - a.example.com\n - b.example.com\n", "Plain prose line one.\nLine two, after a newline.\n\nNew paragraph.",]
def selftest(): """python3 ws_codec.py -> round-trips code samples with the REAL CodeSymb tokenizer and shows the before/after.""" import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import codesymb_common as C os.environ.pop("CODESYMB_WS_CODEC", None) sp = C.load_tokenizer(None) enc = WSCodec(sp) ok = 0 for s in SAMPLES: back = enc.decode(enc.encode(s)) flat = sp.decode(sp.encode(s)) want = "\n".join(re.sub(r"(?<=\S) $", "", line) for line in s.split("\n")) good = back == want ok += good print(f"{'OK ' if good else 'BAD'} {len(enc.encode(s)):4d} tok " f"(plain {len(sp.encode(s)):4d}) | old: {flat[:50]!r}") if not good: print(f" want {want!r}\n got {back!r}") print(f"\n{ok}/{len(SAMPLES)} samples round-trip exactly" + (" -> codec READY" if ok == len(SAMPLES) else " -> NOT ready")) return 0 if ok == len(SAMPLES) else 1
if __name__ == "__main__": raise SystemExit(selftest())123version https://git-lfs.github.com/spec/v1oid sha256:a20891cf52959eeaf4ab0fcd46f62990737595511c90a924e32f7a2a1c49175esize 198840200123version https://git-lfs.github.com/spec/v1oid sha256:d8d0b19d0f48ac9e395efb9f200c8ada5712e1cd2c0e66741b1e12ccf28e26a9size 198853622123version https://git-lfs.github.com/spec/v1oid sha256:91c157be8d320ae44f0213b42e0fee22f4781662b22748ba0864ae559f65c549size 199771576123version https://git-lfs.github.com/spec/v1oid sha256:7502ca431ef7b60893f05fbff01a4aecbfafee55e774ed6ef17d024d068b435csize 199540030123version https://git-lfs.github.com/spec/v1oid sha256:464d89695dda1b9632c7782f1d775ada118634e0d3957f473e0b9d1636bdcc8esize 198968910123version https://git-lfs.github.com/spec/v1oid sha256:5a8d4f07a16843a5cf5a4f2018277bf8953ea5416ac5b48993da49be627c6decsize 199448460123version https://git-lfs.github.com/spec/v1oid sha256:934be180711220babca03256214ed7d655665605a36f8a4e6f03a57978107e42size 199414764123version https://git-lfs.github.com/spec/v1oid sha256:2362f457b814874bbe6d77b5bd63aae21f1a244a3a5799cb5d9f10cfbcaae43csize 199984874123version https://git-lfs.github.com/spec/v1oid sha256:665068993101f4cb7d5026f49dae59e2b826df253572f5006792c0363029418dsize 199070220123version https://git-lfs.github.com/spec/v1oid sha256:bdccef9d5ca8a30c2ac22e7d921a98747b8a1dd8700e54d7194e475b108f4fbbsize 198802702123version https://git-lfs.github.com/spec/v1oid sha256:16590b34ea25103e43841978dd458021db381f5188bae152730a3f6d1039fc35size 199943394123version https://git-lfs.github.com/spec/v1oid sha256:f5bbda60513ed9289d568be56b9955773d4536df92167a57e2c84aa539c5a6basize 199010218123version https://git-lfs.github.com/spec/v1oid sha256:4dfa4eb8194c990039c5fef77280474aec61f5f8d7199965d2157e78661f1322size 198982392123version https://git-lfs.github.com/spec/v1oid sha256:607ca91444404a8f2511ebe533c07a9e966302f9fe97a975acc6484b7284bc2esize 198259554123version https://git-lfs.github.com/spec/v1oid sha256:20ac38d1e02dcfea0c34b3a45bd150394bfb838b015668fa788ac99c14f6c9f7size 199090452123version https://git-lfs.github.com/spec/v1oid sha256:f6999020738d8bd780e60423684a8b538e14e19b89fb6ccfb81a5cd1b0274238size 199718022123version https://git-lfs.github.com/spec/v1oid sha256:a80b93e2670fa54c2aea996afc52828be835a3f62f3be1acfb810557f4fa310fsize 199482902123version https://git-lfs.github.com/spec/v1oid sha256:580d5d1a1c26fb6d73c0f28667211a9a0f5c4a9774b57de925c60f5c557698dfsize 199006474123version https://git-lfs.github.com/spec/v1oid sha256:4586e43b1cf7a4b5596519f9c1e521001de95cf557bbea65232742a8685e1b38size 198464188123version https://git-lfs.github.com/spec/v1oid sha256:1d5d7a5d71a23d43772e29c708084788e76553b7110262b2a856f2b8dc6e39cdsize 199726714123version https://git-lfs.github.com/spec/v1oid sha256:4eac6f525e794a4c9a2a6902ad1c044a3946d0eb0760f96101818751e2c87799size 198771410123version https://git-lfs.github.com/spec/v1oid sha256:2e83117c8d6e3573b84b14a3ed66d97e505d4e96ec3767afafec9724fb5352efsize 199002626123version https://git-lfs.github.com/spec/v1oid sha256:93164dffb014bd88846e752ec898c368b3c57d641e9d65efd59bfb8313128250size 199155780123version https://git-lfs.github.com/spec/v1oid sha256:c54284c9b5f5248995dcb7a86a691e05b41a6790cd909b2a296b4e8dc71e2631size 198560786123version https://git-lfs.github.com/spec/v1oid sha256:7ce8b19bfe57b21b31266fe97dec5ba51c95ac37d11647be199bb4261b00a27csize 199257644123version https://git-lfs.github.com/spec/v1oid sha256:2eb3d674517e3d10a7f273c222040c28fcccb7735fa86df561818268e2195065size 200027134123version https://git-lfs.github.com/spec/v1oid sha256:0752e112734456adc1a69004956bb499c3c2155087150c05543660ba3d8414f8size 199123406123version https://git-lfs.github.com/spec/v1oid sha256:53d66c932916cbf230fc87644a98e0443011099c74db4d8f4a0b3509ca01f11dsize 199365572123version https://git-lfs.github.com/spec/v1oid sha256:54ffaf72ce36ff9c1a4debe540545409427b1222b5a919c7d56bf991b2d55e47size 199891130123version https://git-lfs.github.com/spec/v1oid sha256:4075d9a9b2af7722291cbb8080d0ab541cd8435b2343262d71fe9218a08a1ba3size 199633782123version https://git-lfs.github.com/spec/v1oid sha256:95acf940d261670b03488b2bdd32d452c609c2a9c74b6fd7faa9eb7733d58d72size 198802996123version https://git-lfs.github.com/spec/v1oid sha256:4c46035b422b8bad294ad9d213ec0585717c2165fa58cef64720b82b3a611f1asize 199645748123version https://git-lfs.github.com/spec/v1oid sha256:73ac1bca936865b77c40e94be22b06cb202764a780ef9bbf50e879199d887a80size 199749644123version https://git-lfs.github.com/spec/v1oid sha256:a19d72614f8866e421592b9992849ea884c2455181f6d6c116272d1ae02ab769size 199015936123version https://git-lfs.github.com/spec/v1oid sha256:d4186f07fee08292df9483b8af9e04ec0e837922ec104a1fcb1eb882f0657974size 198714200123version https://git-lfs.github.com/spec/v1oid sha256:045e5d9a9c3246872f8abfbd7de39485748d51fa72595e88c8aa3f700b1a15cesize 198951232123version https://git-lfs.github.com/spec/v1oid sha256:daf9ec851d53f4588668803a43300e6830c7b041bd63a356c196e17414d60b91size 199506914123version https://git-lfs.github.com/spec/v1oid sha256:225d9ee56bcf851ba3442f6f459fe3c40874082c0badc4c6218940c8c241a7bdsize 199364002123version https://git-lfs.github.com/spec/v1oid sha256:53953f871ac4ceb04c34b8139866b22fa9c7496e2ca84a80d0b17d0e2665041fsize 199132364123version https://git-lfs.github.com/spec/v1oid sha256:46f7600c7ff37e03c179b859600806341c47e323ab28292782eb045342064079size 198648968123version https://git-lfs.github.com/spec/v1oid sha256:191e01c20b396abd4f6dde97a5e42e355657fc1755674db2d7dbc644b89510b6size 199191878123version https://git-lfs.github.com/spec/v1oid sha256:47ddd1bef8a6171f943c32fca68d931a2ba32f048610fe41b91c401ea13abcbasize 199349356123version https://git-lfs.github.com/spec/v1oid sha256:21721070215f510f48fc188d02332bc7bc317267dd190d3b24665d585f5de22dsize 199554546123version https://git-lfs.github.com/spec/v1oid sha256:9e2cd086b8976d32fff6fe30051f10d3a487c8d32a0c865c91492245bfaa8d01size 198990740123version https://git-lfs.github.com/spec/v1oid sha256:ff5f33b0bbdc277e57c7477b825dd2332da6a7358d3c2a9e7855041ef0f44da0size 199603106123version https://git-lfs.github.com/spec/v1oid sha256:1c18974f82dbf70bad3898cff97d35174cba61860f3d8ea067d57eacd07c988esize 198922184123version https://git-lfs.github.com/spec/v1oid sha256:97eacaada5bdcb38ab79b139a1c87cc7574ae26310e6002656a6574cbd11388asize 199914038123version https://git-lfs.github.com/spec/v1oid sha256:9da51a5bddec79ab8ed21b0d981238b925ef8e3c4fb7839797eb9c7da78e3fd8size 198576690pretok_ws_clean/manifest.jsonAdded
pretok_ws_clean/ws_codec.pyAdded+162
pretok_ws_clean/x_c_000051_000.binAdded+3
pretok_ws_clean/x_c_000051_001.binAdded+3
pretok_ws_clean/x_c_000051_002.binAdded+3
pretok_ws_clean/x_c_000051_003.binAdded+3
pretok_ws_clean/x_c_000051_004.binAdded+3
pretok_ws_clean/x_c_000051_005.binAdded+3
pretok_ws_clean/x_c_000051_006.binAdded+3
pretok_ws_clean/x_c_000051_007.binAdded+3
pretok_ws_clean/x_c_000051_008.binAdded+3
pretok_ws_clean/x_c_000051_009.binAdded+3
pretok_ws_clean/x_c_000051_010.binAdded+3
pretok_ws_clean/x_c_000051_011.binAdded+3
pretok_ws_clean/x_c_000051_012.binAdded+3
pretok_ws_clean/x_c_000051_013.binAdded+3
pretok_ws_clean/x_c_000051_014.binAdded+3
pretok_ws_clean/x_c_000051_015.binAdded+3
pretok_ws_clean/x_c_000051_016.binAdded+3
pretok_ws_clean/x_c_000051_017.binAdded+3
pretok_ws_clean/x_c_000051_018.binAdded+3
pretok_ws_clean/x_c_000051_019.binAdded+3
pretok_ws_clean/x_c_000051_020.binAdded+3
pretok_ws_clean/x_c_000051_021.binAdded+3
pretok_ws_clean/x_c_000051_022.binAdded+3
pretok_ws_clean/x_c_000051_023.binAdded+3
pretok_ws_clean/x_c_000051_024.binAdded+3
pretok_ws_clean/x_c_000051_025.binAdded+3
pretok_ws_clean/x_c_000051_026.binAdded+3
pretok_ws_clean/x_c_000051_027.binAdded+3
pretok_ws_clean/x_c_000051_028.binAdded+3
pretok_ws_clean/x_c_000051_029.binAdded+3
pretok_ws_clean/x_c_000051_030.binAdded+3
pretok_ws_clean/x_c_000051_031.binAdded+3
pretok_ws_clean/x_c_000051_032.binAdded+3
pretok_ws_clean/x_c_000051_033.binAdded+3
pretok_ws_clean/x_c_000051_034.binAdded+3
pretok_ws_clean/x_c_000051_035.binAdded+3
pretok_ws_clean/x_c_000051_036.binAdded+3
pretok_ws_clean/x_c_000051_037.binAdded+3
pretok_ws_clean/x_c_000051_038.binAdded+3
pretok_ws_clean/x_c_000051_039.binAdded+3
pretok_ws_clean/x_c_000051_040.binAdded+3
pretok_ws_clean/x_c_000051_041.binAdded+3
pretok_ws_clean/x_c_000051_042.binAdded+3
pretok_ws_clean/x_c_000051_043.binAdded+3
pretok_ws_clean/x_c_000051_044.binAdded+3
pretok_ws_clean/x_c_000051_045.binAdded+3
pretok_ws_clean/x_c_000051_046.binAdded+3
pretok_ws_clean/x_c_000051_047.binAdded+3