Download tokenizer/train_tokenizer.py from Ian26/MarsLM: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/Ian26/MarsLM/resolve/main/tokenizer/train_tokenizer.py
- Command line
-
hf download hf://Ian26/MarsLM/tokenizer/train_tokenizer.py
-
curl -L -o train_tokenizer.py https://huggingface.co/Ian26/MarsLM/resolve/main/tokenizer/train_tokenizer.py
1.17 kB
| import argparse | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.append(str(ROOT)) | |
| from tokenizer.tokenizer_utils import train_bpe_tokenizer | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Train a BPE tokenizer for MarsLM") | |
| parser.add_argument("--input", nargs="+", required=True, help="Paths to raw text files") | |
| parser.add_argument("--model-prefix", default="artifacts/tokenizer/marslm", help="Destination prefix") | |
| parser.add_argument("--vocab-size", type=int, default=32000) | |
| parser.add_argument("--model-type", default="bpe", help="Retained for compatibility") | |
| args = parser.parse_args() | |
| input_files = [Path(path).resolve() for path in args.input] | |
| for path in input_files: | |
| if not path.exists(): | |
| raise FileNotFoundError(f"Input file not found: {path}") | |
| output_prefix = Path(args.model_prefix).resolve() | |
| output_path = output_prefix.with_suffix(".json") | |
| train_bpe_tokenizer(input_files, output_path, vocab_size=args.vocab_size) | |
| print(f"Tokenizer saved to {output_path}") | |
| if __name__ == "__main__": | |
| main() | |