MCPcopy Index your code
hub / github.com/SooLab/CGFormer / bytes_to_unicode

Function bytes_to_unicode

utils/simple_tokenizer.py:16–35  ·  view source on GitHub ↗

Returns list of utf-8 byte and a corresponding list of unicode strings. The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing

()

Source from the content-addressed store, hash-verified

14
15@lru_cache()
16def bytes_to_unicode():
17 """
18 Returns list of utf-8 byte and a corresponding list of unicode strings.
19 The reversible bpe codes work on unicode strings.
20 This means you need a large # of unicode characters in your vocab if you want to avoid UNKs.
21 When you're at something like a 10B token dataset you end up needing around 5K for decent coverage.
22 This is a signficant percentage of your normal, say, 32K bpe vocab.
23 To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
24 And avoids mapping to whitespace/control characters the bpe code barfs on.
25 """
26 bs = list(range(ord("!"), ord("~")+1))+list(range(ord("¡"), ord("¬")+1))+list(range(ord("®"), ord("ÿ")+1))
27 cs = bs[:]
28 n = 0
29 for b in range(2**8):
30 if b not in bs:
31 bs.append(b)
32 cs.append(2**8+n)
33 n += 1
34 cs = [chr(n) for n in cs]
35 return dict(zip(bs, cs))
36
37
38def get_pairs(word):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected