File size: 546 Bytes
751936e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
## 封装

__all__ = ['icetk']
sentencepiece_model_pb2 给包装起来了,

## ss
ss
"""

import sentencepiece as spm
from icetk import sentencepiece_model_pb2 as model

def __init__(self, model_path):
    self.proto = model.ModelProto()
    with open(model_path, 'rb') as fin:
        proto_str = fin.read()
        self.proto.ParseFromString(proto_str)
    self.refresh()

def refresh(self):
    self.sp = spm.SentencePieceProcessor()
    self.sp.Load(model_proto=self.proto.SerializeToString())
    self.num_tokens = self.sp.vocab_size()