moonbitstack/moontoken/piece does not have a README file

    Kind

    pub(all) enum Kind {
    Normal
    Unknown
    Control
    UserDefined
    Unused
    RawByte
    } derive(Eq)

    What a piece is for.

    Kind::equal

    fn Kind::equal(Kind, Kind) -> Bool

    Kind::not_equal

    fn Kind::not_equal(x : Kind, y : Kind) -> Bool

    ModelKind

    pub(all) enum ModelKind {
    Unigram
    Bpe
    Word
    Char
    } derive(Eq)

    What kind of model a file was trained as.

    ModelKind::equal

    fn ModelKind::equal(ModelKind, ModelKind) -> Bool

    ModelKind::not_equal

    fn ModelKind::not_equal(x : ModelKind, y : ModelKind) -> Bool

    Piece

    pub(all) struct Piece {
    text : Bytes
    score : Float
    kind : Kind
    }

    One entry of a vocabulary: the text it stands for, the log probability the trainer gave it, and what it is.

    PieceBpe

    pub struct PieceBpe {
    pieces : Pieces
    normalizer :
    Normalizer

    user_defined : Map[Int, Array[Bytes]]
    }

    A model that segments text by merging neighbouring symbols, the sentence-piece flavour: symbols are merged in order of the score of the piece they would form, until no merge is left that the vocabulary has.

    PieceBpe::decode

    fn PieceBpe::decode(self : PieceBpe, ids : ArrayView[Int]) -> String raise
    Refused

    The text a list of tokens stands for.

    PieceBpe::encode

    fn PieceBpe::encode(self : PieceBpe, text : StringView) -> Array[Int] raise
    Refused

    The tokens of text.

    PieceBpe::length

    fn PieceBpe::length(self : PieceBpe) -> Int

    How many pieces the vocabulary has.

    PieceBpe::new

    fn PieceBpe::new(pieces~ : Pieces, normalizer? :
    Normalizer
    , user_defined? : Array[Bytes]) -> PieceBpe

    PieceBpe::pieces

    fn PieceBpe::pieces(self : PieceBpe) -> Pieces

    The vocabulary.

    PieceBpe::token_bytes

    fn PieceBpe::token_bytes(self : PieceBpe, id : Int) -> Bytes?

    The token a piece id stands for.

    Pieces

    pub struct Pieces {
    items : Array[Piece]
    exact : Map[Bytes, Int]
    lattice : Map[Bytes, Int]
    longest : Int
    unk_id : Int
    unk_surface : Bytes
    byte_ids : Array[Int]
    byte_fallback : Bool
    }

    A vocabulary of pieces, with the indexes a model needs: one for the pieces segmentation may use, one for everything.

    Pieces::at

    The piece with this id.

    Pieces::byte_fallback

    fn Pieces::byte_fallback(self : Pieces) -> Bool

    Whether a character with no piece may be spelled out as bytes.

    Pieces::byte_id

    fn Pieces::byte_id(self : Pieces, b : Int) -> Int

    The id of the piece for one byte, or -1.

    Pieces::id

    fn Pieces::id(self : Pieces, text : BytesView) -> Int?

    The id of a piece, whatever kind it is.

    Pieces::lattice_id

    fn Pieces::lattice_id(self : Pieces, text : BytesView) -> Int?

    The id of a piece segmentation may use: an ordinary one or a declared one.

    Pieces::length

    fn Pieces::length(self : Pieces) -> Int

    How many pieces there are; ids run from 0 to this less one.

    Pieces::longest

    fn Pieces::longest(self : Pieces) -> Int

    The longest piece segmentation may use, in bytes.

    Pieces::new

    fn Pieces::new(items~ : Array[Piece], unk_id? : Int, unk_surface? : String, byte_fallback? : Bool) -> Pieces raise
    Refused

    Builds the tables over a list of pieces.

    unk_id is the piece that stands in for text nothing covers, and byte_fallback says whether the model can spell a character out as bytes.

    Pieces::unk_id

    fn Pieces::unk_id(self : Pieces) -> Int

    The id of the piece that stands in for uncovered text, or -1.

    Pieces::unk_surface

    fn Pieces::unk_surface(self : Pieces) -> Bytes

    The text an unknown token stands for when it is decoded.

    Proto

    pub struct Proto {
    pieces : Pieces
    trainer : Trainer
    normalizer :
    Spec

    }

    A model file: its pieces, how it was trained, and how text is normalised before segmentation.

    Proto::normalizer

    The normalisation the model expects, ready to apply.

    Proto::of

    Reads a model file.

    Proto::pieces

    fn Proto::pieces(self : Proto) -> Pieces

    The vocabulary.

    Proto::spec

    The normalisation the model expects, as written in the file.

    Proto::trainer

    fn Proto::trainer(self : Proto) -> Trainer

    How the model was trained.

    Proto::user_defined

    fn Proto::user_defined(self : Proto) -> Array[Bytes]

    The symbols the caller reserved, in the order the file lists them.

    Span

    pub struct Span {
    start : Int
    stop : Int
    id : Int
    }

    What segmentation produced, before the tokens a model reserves are dealt with: a span of the normalised bytes and the piece that covers it.

    Trainer

    pub(all) struct Trainer {
    kind : ModelKind
    unk_id : Int
    byte_fallback : Bool
    treat_whitespace_as_suffix : Bool
    unk_piece : String
    unk_surface : String
    }

    The settings a model was trained with that change how it runs.

    Unigram

    pub struct Unigram {
    pieces : Pieces
    normalizer :
    Normalizer

    min_score : Float
    }

    A model that segments text by the most likely sequence of pieces.

    Each piece carries the log probability the trainer measured for it, and the segmentation is the one whose pieces add up to the largest total. Text that no piece covers becomes the unknown piece, or, when the model can spell it out, one token per byte.

    Unigram::decode

    fn Unigram::decode(self : Unigram, ids : ArrayView[Int]) -> String raise
    Refused

    The text a list of tokens stands for.

    Unigram::encode

    fn Unigram::encode(self : Unigram, text : StringView) -> Array[Int] raise
    Refused

    The tokens of text.

    Unigram::length

    fn Unigram::length(self : Unigram) -> Int

    How many pieces the vocabulary has.

    Unigram::new

    Builds the model over a vocabulary.

    Raises when the vocabulary has neither an unknown piece nor byte fallback, because text outside the vocabulary would then have no encoding at all.

    Unigram::pieces

    fn Unigram::pieces(self : Unigram) -> Pieces

    The vocabulary.

    Unigram::token_bytes

    fn Unigram::token_bytes(self : Unigram, id : Int) -> Bytes?

    The token a piece id stands for, for callers that want the spelling.

    byte_of_piece

    fn byte_of_piece(text : Bytes) -> Int?

    The byte a <0xNN> spelling stands for, when it is one.

    byte_piece

    fn byte_piece(b : Int) -> String

    The text of the piece that stands for one byte.