Views
No views yet
cl100k_base BPE token id.jsanzolac/ga_wikipedia (English Wikipedia dump 2023-11-01)tiktoken.cl100k_base| File | Purpose |
|---|---|
vectors.txt | GloVe text format: <bpe_id> v1 v2 ... v512 |
vectors.bin | Binary format (-binary 2) |
vocab.txt | BPE id and its corpus count |
token_id_to_string.json | Mapping from BPE id → decoded cl100k_base string |
1import numpy as np, tiktoken
2from huggingface_hub import hf_hub_download
3
4vec_path = hf_hub_download("jsanzolac/bpe_glove_512", "vectors.txt")
5enc = tiktoken.get_encoding("cl100k_base")
6
7embeddings = {}
8with open(vec_path) as f:
9 for line in f:
10 parts = line.rstrip().split(" ")
11 embeddings[int(parts[0])] = np.asarray(parts[1:], dtype=np.float32)
12
13def embed(text):
14 ids = enc.encode(text)
15 return np.mean([embeddings[i] for i in ids if i in embeddings], axis=0)