MCPcopy Create free account
hub / github.com/Gadersd/stable-diffusion-burn / bytes_to_unicode

Function bytes_to_unicode

python/dump.py:477–496  ·  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 around

()

Source from the content-addressed store, hash-verified

475 return text
476
477def bytes_to_unicode():
478 """
479 Returns list of utf-8 byte and a corresponding list of unicode strings.
480 The reversible bpe codes work on unicode strings.
481 This means you need a large # of unicode characters in your vocab if you want to avoid UNKs.
482 When you're at something like a 10B token dataset you end up needing around 5K for decent coverage.
483 This is a signficant percentage of your normal, say, 32K bpe vocab.
484 To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
485 And avoids mapping to whitespace/control characters the bpe code barfs on.
486 """
487 bs = list(range(ord("!"), ord("~")+1))+list(range(ord("¡"), ord("¬")+1))+list(range(ord("®"), ord("ÿ")+1))
488 cs = bs[:]
489 n = 0
490 for b in range(2**8):
491 if b not in bs:
492 bs.append(b)
493 cs.append(2**8+n)
494 n += 1
495 cs = [chr(n) for n in cs]
496 return dict(zip(bs, cs))
497
498class ClipTokenizer:
499 def __init__(self, bpe_path: str = default_bpe()):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected