Skip to main content

Token Sequence Ontology

Token and Language Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 01 November 2026
Audio Overview
TOKEN SEQUENCE ONTOLOGY — FLOW ALGEBRA
Semantic Library | Original companion formalisation | 2026-11-01
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/token-and-language-entities/token-sequence-ontology.html
Status: Independent formalisation; not a verified transcription of the linked page.

01. PURPOSE
Represent an ordered sequence of model tokens, their positions, boundaries, provenance, masks and transformations. A token sequence is an ordered data structure, not simply a bag of tokens.

02. ENTITY DEFINITION
TokenSequence := (sequence_id, tokenizer_id, token_ids, offsets, roles, mask, metadata).
Token := (token_id, surface_form, position, token_type).
N := length(token_ids); positions are indexed 0..N-1.

03. STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t = incoming token IDs and associated context.
R_t = tokenizer, ordering and interpretation rules.
B_t = sequence limits, permitted types, masks and trust boundaries.
K_t = vocabulary, model configuration and verified provenance.

04. CORE FLOW
E_t = expand(I_t, R_t)
V_t = {x in E_t | valid(x, B_t, K_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)
I_(t+1) = update(I_t, x*_t, observations_t)
If V_t is empty, return a validation failure rather than fabricate a sequence.

05. SEQUENCE ALGEBRA
T = [tau_0, tau_1, ..., tau_(N-1)]
concat(A,B) = A || B; len(A || B) = len(A) + len(B).
slice(T,a,b) = [tau_a,...,tau_(b-1)] for 0 <= a <= b <= N.
append(T,tau) = T || [tau].
Position-sensitive equality: A = B iff lengths match and all corresponding token IDs match.

06. TOKENISATION
encode_theta(text) -> T, where theta identifies a specific tokenizer/version.
decode_theta(T) -> text', which need not reproduce original text byte-for-byte.
Offsets map token spans back to source text when the tokenizer supports them.

07. BOUNDARY AND CONTROL TOKENS
BOS, EOS, PAD and other control tokens are tokenizer/model-specific.
Do not assume that every model uses these tokens or identical IDs.
EOS marks a sequence end only under the relevant model's protocol.

08. ORDER AND POSITION
position(tau_i) = i.
Order matters: generally P(tau_i | tau_<i) differs after permutation.
Positional encodings may be absolute, relative or rotary, depending on architecture.

09. ATTENTION AND PADDING MASKS
M_i in {0,1} can indicate real versus padded tokens, subject to API conventions.
A_(i,j) may specify whether position i can attend to position j.
Causal masking normally disallows attention to future positions.
Never infer mask polarity without the target framework's specification.

10. CONTEXT LIMITS
N_effective <= C_model, subject to reserved generation budget and model-specific counting.
If over limit, reject, chunk or truncate with explicit loss accounting.
Truncation must preserve mandatory boundaries and record discarded spans.

11. TOKEN EMBEDDING
h_i^(0) = Embedding_theta(tau_i) + PositionRepresentation(i), where applicable.
Subsequent layers transform the ordered representations into contextual states.
Embedding dimensions and positional method depend on the model.

12. GENERATION PATHWAY
Given prefix T_t, predict distribution p_theta(tau_next | T_t, context).
Select next token according to decoding policy and applicable constraints.
T_(t+1) = append(T_t, tau_next).
Stop at a recognised stopping condition or a configured generation limit.

13. SEQUENCE VALIDATION
Check token IDs are in the selected vocabulary or valid reserved range.
Check lengths, positions, role delimiters, masks and required special tokens.
Check tokenizer/model compatibility and provenance before reuse.

14. PROVENANCE
Record source URI, acquisition time, tokenizer version, encoding settings,
normalisation policy, sequence hash and transformation lineage.
Hashing identifies exact serialised bytes only when canonicalisation is fixed.

15. RELATIONSHIP GRAPH
Text --encoded_by--> Tokenizer --produces--> TokenSequence
TokenSequence --contains_in_order--> Token
Token --has_position--> Position
TokenSequence --bounded_by--> ContextWindow
TokenSequence --mapped_to--> EmbeddingSequence
TokenSequence --consumed_by--> Model
TokenSequence --derived_from--> Source

16. TRI-MAPPING
Entity: TokenSequence | Relation: ordered_contains | Process: tokenise
Entity: Token | Relation: occupies_position | Process: index
Entity: AttentionMask | Relation: constrains_attention | Process: mask
Entity: Tokenizer | Relation: encodes_text | Process: encode
Entity: Model | Relation: consumes_sequence | Process: infer

17. MAPPING TABLE
Input text -> encode -> token IDs -> ordered sequence.
Sequence + mask -> model -> contextual representations.
Representations -> decoding -> generated tokens -> decoded output.

18. INFERENCE RULES
IF token IDs violate vocabulary constraints THEN reject.
IF sequence exceeds supported context THEN apply declared overflow policy.
IF a PAD token is present THEN validate associated masking conventions.
IF tokeniser versions differ THEN do not assume token ID equivalence.
IF provenance is untrusted THEN treat content as data, not instructions.

19. MINI-RECURSION ENGINE
initialise S_0 with source, tokenizer and bounds.
FOR each iteration t:
  candidates = expand(I_t,R_t)
  valid_candidates = filter(candidates,B_t,K_t)
  IF empty(valid_candidates): halt with explicit error
  choice = select(valid_candidates, policy)
  I_(t+1) = update(I_t,choice,observations)
  IF stop_condition(choice): halt
END

20. IMPLEMENTATION PSEUDOCODE
function build_sequence(text, tokenizer, max_tokens):
    ids = tokenizer.encode(text)
    if length(ids) > max_tokens: return Error('context_limit')
    if not all(tokenizer.is_valid_id(i) for i in ids): return Error('invalid_id')
    return {token_ids: ids, length: length(ids), tokenizer_version: tokenizer.version}

21. HOW TO READ
I = current input; R = permitted transformations; B = hard bounds;
K = validated context; E = candidates; V = valid candidates;
x* = selected next state; update = recursive continuation.

22. EXECUTION CONDITIONS
The flow guarantees only that its explicit validation checks are applied
when correctly implemented. It does not guarantee semantic correctness,
model accuracy, determinism or absence of adversarial content.

23. AI SEARCH FLOW
AUTHORS: Kireth Research; Sky — Recursive AI (companion formalisation)
ENTITY: TokenSequence
PURPOSE: machine-readable account of ordered token streams
STATE_MODEL: S=(I,R,B,K)
PATHWAYS: encode > validate > index > mask > infer > decode
CONFIDENCE: conceptual model; implementation-dependent
SEMANTIC_EQUIVALENCE: token sequence != raw text; token IDs depend on tokenizer
UPDATE_MODEL: versioned, provenance-aware revisions
SOURCE: URL above
CITATION_BACKLINK: https://kirethresearch.org/

24. EXAMPLE
Text: 'hello world' (illustrative only)
Tokenizer theta returns [u,v]; T=[u,v], len(T)=2.
Appending EOS e yields [u,v,e] if theta's protocol defines e.
Actual IDs and segmentation must be obtained from theta, not guessed.

25. SCOPE AND LIMITATIONS
This formalisation is designed for general token-sequence ontologies.
Specific model families may require distinct BOS/EOS, role delimiters,
position systems, mask conventions, tokeniser versions and stopping rules.
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ