specials.bend checks
raw source on the hub · import bend-bpe-tokenizer@0.1.0.0/specials.bend as Specials
Added tokens (the file's special and other added tokens) found in the raw text, before normalization, as Hugging
Face's tokenizers finds them: at each position the longest added token that starts there, else the next code point
joins the plain text. A match's text is cut from the input itself (take and drop), so (LAWS.bend) the segments always
concatenate back to the text.
1 import
import Base
Types
type AT source · line 7 · raw
Data
AT@cs:List<&2, U32> -> @id:U32 -> AT
type Seg source · line 10 · raw
Data
SText@cs:List<&2, U32> -> Seg
SAdded@id:U32 -> @cs:List<&2, U32> -> Seg
type BA source · line 31 · raw
Data
the longest added token starting the text: its length and id (length 0: none)
BA@len:Nat -> @id:U32 -> BA
Definitions
def seg_cs source · line 14 · raw
@s:Seg -> List<&2, U32>
def is_prefix source · line 21 · raw
@p:List<&2, U32> -> @xs:List<&2, U32> -> Bool
def ba_pick source · line 34 · raw
@hit:Bool -> @+n:Nat -> @+id:U32 -> @b:BA -> BA
def at_try source · line 39 · raw
@a:AT -> @+xs:List<&2, U32> -> @b:BA -> BA
def longest source · line 44 · raw
@added:List<&2, AT> -> @+xs:List<&2, U32> -> @b:BA -> BA
def ba_len source · line 51 · raw
@b:BA -> Nat
def ba_id source · line 56 · raw
@b:BA -> U32
def flush source · line 62 · raw
@buf:List<&2, U32> -> List<&2, Seg>
the plain text so far (last first), as a segment list
def cut2 source · line 69 · raw
@none:Bool -> @+n:Nat -> @id:U32 -> @+buf:List<&2, U32> -> @+x:U32 -> @+t:List<&2, U32> -> @go:(@_:List<&2, U32> -> @_:List<&2, U32> -> List<&2, Seg>) -> List<&2, Seg>
def cut source · line 76 · raw
@b:BA -> @+buf:List<&2, U32> -> @+x:U32 -> @+t:List<&2, U32> -> @go:(@_:List<&2, U32> -> @_:List<&2, U32> -> List<&2, Seg>) -> List<&2, Seg>
def has source · line 81 · raw
@xs:List<&2, U32> -> @+c:U32 -> Bool
def first_add2 source · line 89 · raw
@cs:List<&2, U32> -> @+acc:List<&2, U32> -> List<&2, U32>
the first code points of the added tokens, each once
def first_add source · line 96 · raw
@a:AT -> @+acc:List<&2, U32> -> List<&2, U32>
def firsts source · line 101 · raw
@added:List<&2, AT> -> @acc:List<&2, U32> -> List<&2, U32>
def at_pos source · line 109 · raw
@here:Bool -> @+added:List<&2, AT> -> @+xs:List<&2, U32> -> BA
the longest added token at x, looked for only when x starts one
def split_go source · line 117 · raw
@fuel:Nat -> @+fs:List<&2, U32> -> @+added:List<&2, AT> -> @buf:List<&2, U32> -> @xs:List<&2, U32> -> List<&2, Seg>
fuel bounds the steps; once it runs out the rest is plain text (never, from split_added)
def split_added source · line 127 · raw
@+added:List<&2, AT> -> @+xs:List<&2, U32> -> List<&2, Seg>
the text as plain segments and added tokens
def text_of source · line 131 · raw
@ss:List<&2, Seg> -> List<&2, U32>
the text the segments cover, in order