Module Lm.SSource

module Graph : sig ... end
module Optimise = Graph.Neuron.Optimise
module Init = Graph.Neuron.Init
module Activation = Graph.Neuron.Activation
module Regularisation = Graph.Neuron.Optimise.Regularisation
module E : sig ... end
module B : sig ... end
module Distribution : sig ... end
val scalar : float -> Algodiff.t
val column : float array -> Algodiff.t
val batch : Algodiff.A.arr array -> Algodiff.t
val one_hot : int -> int array -> Algodiff.t
val values : Algodiff.A.arr -> float array
val predict : Graph.network -> Algodiff.A.arr -> float array
val n_actions : (Algodiff.A.arr, int) Owl_rllib.Ndenv.t -> int
val adam : float -> Params.typ
val update : Graph.network -> Stepper.state -> Algodiff.t -> unit
val mlp : seed:int -> shape:int array -> hidden:int list -> outputs:int -> Graph.network
type init =
  1. | Default
  2. | Orthogonal of float
val orthogonal : float -> Init.typ
val mlp_with : activation:Activation.typ -> init:init -> seed:int -> shape:int array -> hidden:int list -> outputs:int -> Graph.network
val gaussian_mlp : activation:Activation.typ -> init:init -> seed:int -> shape:int array -> hidden:int list -> actions:int -> Graph.network
val cnn : seed:int -> shape:int array -> convs:(int * int * int) list -> hidden:int list -> outputs:int -> Graph.network
Sourceval vocab : int
Sourceval window : int

Context length: the longest prompt plus every answer token but the last.

Sourceval input_size : int
Sourceval encode : int array -> float array

A context as its left-padded one-hot window, row-major [position; token].

Sourceval features : int array array -> Algodiff.t

Encode a batch of contexts.

Sourceval create : ?hidden:??? -> ?outputs:??? -> seed:int -> unit -> Graph.network

Hidden layers default to [128; 128]; outputs (default vocab) can be 1 for a critic.

Sourceval token_log_probs : Algodiff.t -> int array -> Algodiff.t

log pi(action | context) for every row, differentiable in the logits.

Sourcetype sample = Make(Owl.Neural.S.Graph).sample = {
  1. prompt : int array;
  2. tokens : int array;
    (*

    generated tokens, ending with eos unless cut off

    *)
  3. log_probs : float array;
    (*

    log pi(token) under the generating network

    *)
}
Sourceval generate : ?greedy:??? -> ?max_len:??? -> rng:Random.State.t -> Graph.network -> int array array -> sample array

Generate up to max_len tokens for every prompt (default Owl_rllib_llm.Lm_task.max_answer), one batched forward pass per position; sampling by default, the most likely token with ~greedy:true.

Sourceval rows : (int array * int array) array -> int array array * int array * int array

For (prompt, tokens) pairs, one row per token: the context before it, the token, and the index of its pair.

Sourceval accuracy : ?sample:??? -> ?task:??? -> Graph.network -> Lm_task.problem array -> float

The fraction of problems answered right, with greedy decoding or one sample per problem; the sampling stream is fixed, so evaluations repeat.

Sourceval sft : ?batch_size:??? -> ?learning_rate:??? -> ?report:??? -> ?task:??? -> steps:int -> rng:Random.State.t -> Graph.network -> Lm_task.problem array -> unit

Supervised fine-tuning with teacher forcing: minimise the cross-entropy of every target token given the tokens before it. report step loss is called after every step.