Download maketoken2.py from HDTenEightyP/GPT-FFDNET: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/HDTenEightyP/GPT-FFDNET/resolve/main/maketoken2.py
- Command line
-
hf download hf://HDTenEightyP/GPT-FFDNET/maketoken2.py
-
curl -L -o maketoken2.py https://huggingface.co/HDTenEightyP/GPT-FFDNET/resolve/main/maketoken2.py
664 Bytes
| from pathlib import Path | |
| import tiktoken | |
| from transformers.integrations.tiktoken import convert_tiktoken_to_fast | |
| from transformers import PreTrainedTokenizerFast | |
| out_dir = Path("hf_tokenizer") | |
| out_dir.mkdir(exist_ok=True) | |
| # Convert | |
| encoding = tiktoken.get_encoding("cl100k_base") | |
| convert_tiktoken_to_fast(encoding, str(out_dir)) | |
| # Load the generated tokenizer | |
| tokenizer = PreTrainedTokenizerFast( | |
| tokenizer_file=str(out_dir / "tokenizer.json"), | |
| bos_token="<|endoftext|>", | |
| eos_token="<|endoftext|>", | |
| unk_token="<|endoftext|>", | |
| ) | |
| # Save all Hugging Face tokenizer files | |
| tokenizer.save_pretrained(out_dir) | |
| print(f"Saved tokenizer to {out_dir}") | |