MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / encode

Method encode

ts_rec_data.py:21–33  ·  view source on GitHub ↗
(self, s: str, bos: bool, eos: bool)

Source from the content-addressed store, hash-verified

19
20
21 def encode(self, s: str, bos: bool, eos: bool) -> List[int]:
22 assert type(s) is str
23 t = self.tokenizer.encode(s)
24 while t[0] == self.bos_id:
25 t = t[1:]
26 while t[-1] == self.eos_id:
27 t = t[:-1]
28
29 if bos and self.bos_id is not None:
30 t = [self.bos_id] + t
31 if eos and self.eos_id is not None:
32 t = t + [self.eos_id]
33 return t
34
35 def decode(self, t: List[int]) -> str:
36 return self.tokenizer.decode(t)

Callers 4

preMethod · 0.45
preMethod · 0.45
preMethod · 0.45
preMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected