below algorithm is wrong because (logic error) 024-11-15 00:05:31,634 [INFO] Loaded…
- User
below algorithm is wrong because (logic error) 024-11-15 00:05:31,634 [INFO] Loaded 48895 BPE merge rules. 2024-11-15 00:05:31,667 [INFO] Tokenizer initialization complete. Encoded: [12887, 49408, 11, 49408, 2334, 49408, 0, 49408, 4340, 49408, 595, 49408, 64, 49408, 7738, 49408, 684, 49408, 599, 49408, 19018, 32634, 2845, 517, 49408, 13, 49408] Decoded: 'hello<|endoftext|>,<|endoftext|>world<|endoftext|>!<|endoftext|>this<|endoftext|>is<|endoftext|>a<|endoftext|>test<|endoftext|>of<|endoftext|>the<|endoftext|>simpletokenizer<|endoftext|>.<|endoftext|>' import gzip import html import os import sys from functools import lru_cache from typing import Dict, List, Set, Tuple, Optional
import ftfy import regex as re import logging
Configure logging
logging.basicConfig( level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s', handlers=[ logging.StreamHandler(sys.stdout) ] ) logger = logging.getLogger(name)
@lru_cache(maxsize=1) def default_bpe_path() -> str: """ Returns the default path to the BPE vocabulary file.
codeReturns: str: Absolute path to 'bpe_simple_vocab_16e6.txt.gz' located in the same directory as this script. """ try: return os.path.join(os.path.dirname(os.path.abspath(__file__)), "bpe_simple_vocab_16e6.txt.gz") except Exception as e: logger.error(f"Error determining BPE file path: {e}") raise@lru_cache(maxsize=1) def bytes_to_unicode_mapping() -> Dict[int, str]: """ Generates a mapping from byte values to unicode characters.
codeThis ensures reversible BPE operations without introducing unknowns by avoiding whitespace/control characters. Returns: Dict[int, str]: A dictionary mapping byte integers to unique unicode characters. """ try: initial_bytes = ( list(range(ord("!"), ord("~") + 1)) + list(range(ord("¡"), ord("¬") + 1)) + list(range(ord("®"), ord("ÿ") + 1)) ) byte_map = initial_bytes.copy() unicode_map = byte_map.copy() n = 0 for b in range(256): if b not in byte_map: byte_map.append(b) unicode_map.append(256 + n) n += 1 unicode_chars = [chr(code_point) for code_point in unicode_map] return dict(zip(byte_map, unicode_chars)) except Exception as e: logger.error(f"Error creating bytes to unicode mapping: {e}") raise - Assistant