TorchLean API

NN.API.Text.Options

Text Workflow Configuration #

Display helpers, generation and corpus option records, training-log metadata, and CLI parsers for text workflows.

Causal LM Display Helpers #

def TorchLean.text.tokenWindow (t : Tokenizer) (n : ) (input : String) (offset padId : := 0) :

Return a fixed-length token window from a text string.

offset = 0 is the model prompt window; offset = 1 is the usual next-token target window for causal language modeling. Missing tokens are padded with padId, matching causalLmXYOneHotMatFloat.

Instances For
    def TorchLean.text.decodeWindow (t : Tokenizer) (n : ) (input : String) (offset padId : := 0) :

    Decode a fixed token window extracted by tokenWindow.

    Instances For

      Escape a short text fragment for one-line terminal output.

      Display-only: this does not change tokenizer semantics. Quotes and backslashes use their usual escapes, common whitespace controls use \\n, \\r, and \\t, and every other ASCII control character is written as \\xNN. Thus byte-token predictions cannot turn a log into a binary file.

      Instances For

        Sampling Helpers (Top-k) #

        Shared text-generation flags for GPT-style examples.

        • prompt : String

          Prompt used to seed autoregressive generation.

        • generate :

          Number of new tokens to append.

        • temperature : Float

          Softmax temperature. Must be positive.

        • topK :

          Top-k cutoff. 1 gives greedy decoding.

        • repeatPenalty : Float

          Penalty subtracted for repeated recent tokens. 0 disables it.

        • repeatWindow :

          Number of recent tokens considered by the repeat penalty. 0 disables the window.

        • seed :

          Deterministic RNG seed for sampling.

        • asciiOnly : Bool

          Restrict generated ids to a model-specific ASCII allow-list.

        Instances For

          Defaults for parseGenerationOptions.

          Instances For

            Parse --ascii-only, accepting either a bare flag or true/false value.

            Instances For

              Parse the generation flags shared by GPT-style examples.

              The model file still owns its training/data flags. This helper only handles prompt, sampling, repeat penalty, deterministic seed, and ASCII restriction.

              Instances For

                Parse generation flags using a full GenerationOptions value as defaults.

                This is the public API shape used by model commands: they provide a concrete default prompt and sampling policy, and the shared parser handles the stable CLI surface.

                Instances For

                  Text Workflow Option Records #

                  Required text-corpus path plus the explicit small-data option used by local corpus trainers.

                  • dataFile : System.FilePath

                    UTF-8 or raw-byte corpus path selected by --data-file.

                  • allowSmallData : Bool

                    Allow local runs below the normal corpus-size floor.

                  Instances For

                    Parse the required --data-file corpus flag and optional --allow-small-data switch.

                    Instances For

                      Optional text-corpus path selected by --data-file, with caller-supplied default.

                      Instances For

                        Parse an optional --data-file flag using the supplied default path.

                        Instances For

                          Optional second corpus pass after the main training run.

                          • finetuneFile? : Option System.FilePath

                            Optional corpus used for a second fine-tuning pass.

                          • finetuneSteps :

                            Number of optimizer steps used on that second corpus when present.

                          Instances For

                            Parse the optional --finetune-file / --finetune-steps pair.

                            The caller supplies the default step count so commands can reuse their main training-step default.

                            Instances For

                              Optional GPT-2 BPE tokenizer bundle plus an optional bounded-text cap.

                              Instances For

                                Parse the optional GPT-2 BPE tokenizer bundle.

                                --bpe-vocab and --bpe-merges must appear together; --max-chars is independent.

                                Instances For

                                  Shared terminal-REPL toggle used by interactive text examples.

                                  • interactive : Bool

                                    Keep the trained model alive and read prompts from stdin.

                                  Instances For

                                    Parse the shared --interactive flag used by text examples with a terminal prompt loop.

                                    Instances For

                                      Shared prompt plus continuation-length options for simple text-generation commands.

                                      • prompt : String

                                        Prompt used for before/after reports and generation.

                                      • generate :

                                        Number of generated tokens or characters after training.

                                      Instances For

                                        Parse the shared --prompt / --generate flags.

                                        Instances For

                                          Text TrainLog Notes #

                                          TrainLog note fields for generation-capable text commands.

                                          The stable generation surface is prompt, continuation length, temperature/top-k, repetition control, RNG seed, and ASCII-only filtering. Model commands can prepend dataset or architecture notes through extra.

                                          Instances For

                                            TrainLog note fields for prompt-based text commands that do not expose the full sampling surface.

                                            Instances For
                                              def TorchLean.text.writeGenerationTrainLog (log : Training.LogDestination) (title : String) (steps : ) (beforeLoss afterLoss : Float) (gen : GenerationOptions) (generated? : Option String := none) (extra : Array String := #[]) :

                                              Write a before/after loss log for a generation-capable text training command.

                                              Instances For
                                                def TorchLean.text.writePromptTrainLog (log : Training.LogDestination) (title : String) (steps : ) (beforeLoss afterLoss : Float) (gen : PromptGenerationOptions) (generated? : Option String := none) (extra : Array String := #[]) :

                                                Write a before/after loss log for a prompt-based text training command.

                                                Instances For

                                                  Shared "load one parameter pack, then sample" option surface.

                                                  Instances For

                                                    Parse the shared saved-parameter sampling flags used by inference-only text commands.

                                                    Instances For

                                                      Text Training Option Combinators #

                                                      Number of corpus windows used by a finite or cyclic text-training command.

                                                      • windows :

                                                        Number of windows available to the training sampler.

                                                      Instances For

                                                        Parse a positive --windows value.

                                                        Instances For

                                                          Optional parameter-checkpoint paths for text training and generation.

                                                          Instances For

                                                            Parse --load-params and --save-params.

                                                            Instances For

                                                              Build the shared logged-training + interactive option record.

                                                              Instances For

                                                                Build the shared train-flags + interactive option record.

                                                                Instances For
                                                                  def TorchLean.text.InteractiveTrainOptions.parse (exeName : String) (args : List String) (defaultLogJson : System.FilePath) (defaultSteps : ) (defaultLr : Float) (allowZeroSteps : Bool := false) :

                                                                  Parse the shared "train + interactive" option surface.

                                                                  Instances For

                                                                    Build the shared logged-training + prompt + interactive option record.

                                                                    Instances For

                                                                      Parse the shared "logged train + prompt + interactive" option surface.

                                                                      Instances For

                                                                        Corpus-training options for promptable text commands.

                                                                        This combines the common corpus, fine-tune, BPE, prompt, logging, and interactive controls without tying them to a particular model implementation.

                                                                        Instances For

                                                                          Parse the shared "corpus + logged train + prompt + interactive + optional fine-tune/BPE" surface.

                                                                          Instances For

                                                                            Build the shared train + generation option record.

                                                                            Instances For

                                                                              Build the shared train + generation + windows option record.

                                                                              Instances For
                                                                                def TorchLean.text.WindowedTrainGenerationOptions.parse (exeName : String) (args : List String) (defaultLogJson : System.FilePath) (defaultSteps : ) (defaultLr : Float) (defaultWindows : ) (genDefaults : GenerationOptions) (allowZeroSteps : Bool := false) :

                                                                                Parse the standard "train + generate + windows" option surface.

                                                                                Instances For

                                                                                  Build the shared train + generation + windows + checkpoint option record.

                                                                                  Instances For
                                                                                    def TorchLean.text.CheckpointedWindowedTrainGenerationOptions.parse (exeName : String) (args : List String) (defaultLogJson : System.FilePath) (defaultSteps : ) (defaultLr : Float) (defaultWindows : ) (genDefaults : GenerationOptions) (allowZeroSteps : Bool := false) :

                                                                                    Parse the shared "train + generate + windows + checkpoint" option surface.

                                                                                    Instances For

                                                                                      Training options for text commands with generic batch and context-length controls.

                                                                                      Instances For
                                                                                        def TorchLean.text.BatchedCheckpointedWindowedTrainGenerationOptions.parse (exeName : String) (args : List String) (defaultLogJson : System.FilePath) (defaultSteps : ) (defaultLr : Float) (defaultWindows defaultBatch defaultSeqLen : ) (genDefaults : GenerationOptions) (allowZeroSteps : Bool := false) :

                                                                                        Parse the shared "train + generate + windows + checkpoint + batch + seq-len" option surface.

                                                                                        Instances For

                                                                                          Build the full train + generation + windows + checkpoint + interactive option record.

                                                                                          Instances For
                                                                                            def TorchLean.text.InteractiveCheckpointedWindowedTrainGenerationOptions.parse (exeName : String) (args : List String) (defaultLogJson : System.FilePath) (defaultSteps : ) (defaultLr : Float) (defaultWindows : ) (genDefaults : GenerationOptions) (allowZeroSteps : Bool := false) :

                                                                                            Parse the full "train + generate + windows + checkpoint + interactive" option surface.

                                                                                            Instances For