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

Method encode

data.py:20–32  ·  view source on GitHub ↗
(self, s: str, bos: bool, eos: bool)

Source from the content-addressed store, hash-verified

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

Callers 10

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

Calls

no outgoing calls

Tested by

no test coverage detected