File size: 478 Bytes
7ab99c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3

import sys

from transformers import AutoTokenizer

import json

model = sys.argv[1] if len(sys.argv) >= 2 else "nghuyong/ernie-3.0-base-zh"

tokenizer = AutoTokenizer.from_pretrained(model)

vocabulary = tokenizer.get_vocab()

vocab_json = f"./encoder_vocab_{model.split('/')[-1]}.json"

with open(vocab_json, "w", encoding='utf8') as log_file:
    json.dump(dict(sorted(vocabulary.items(), key=lambda x: x[1])), log_file, indent=4, ensure_ascii=False)