Text Datasets #
Causal language-model sample and dataset constructors.
Split exact (sequenceLength + 1) token windows into causal-LM input and target tensors.
For a window $[t_0,t_1,\ldots,t_{\mathrm{sequenceLength}}]$, the model input is $[t_0,\ldots,t_{\mathrm{sequenceLength}-1}]$ and the target is $[t_1,\ldots,t_{\mathrm{sequenceLength}}]$. Corpus readers perform any requested padding before constructing this tensor, so the split itself cannot invent or discard tokens.
Instances For
Build a one-hot causal-language-model sample over an arbitrary batch shape.
The input and target both append sequence and vocabulary axes to batchShape.
Instances For
Build a batched one-hot causal-language-model sample from a token tensor by choosing one
deterministic (sequenceLength + 1) window per batch row.
Use this for GPT-style trainers that keep a tokenized corpus in memory and derive each batch from
the same (tokens, seed, step) rule.
Instances For
Build an indexed-token causal-language-model batch from a tensor corpus.
The result contains the input and next-token target as separate bounded-index tensors. Validation happens once at this corpus boundary; model code therefore has no out-of-range token case.
Instances For
Build one unbatched one-hot causal-language-model sample from a text corpus string.
This takes one (sequenceLength + 1) byte window from the UTF-8 bytes of text, converts it to
one-hot input/target matrices, and casts the result into the runtime-selected arithmetic
representation.
Instances For
Build a finite causal-language-model dataset from approximately evenly spaced byte windows.
Offsets are measured in UTF-8 bytes, matching byteSample. Short corpora remain total because
byteTokenWindow pads beyond the end, while windowCount = 0 returns an empty dataset.
Instances For
Build one fixed-batch one-hot causal-language-model sample from a text corpus string by repeating the same text window across every batch row.