Documentation

Hesper.Training.AlpacaDataset

Alpaca Dataset Loader #

Parses Stanford Alpaca-format JSON datasets for instruction finetuning.

Format #

[
  {
    "instruction": "Give three tips for staying healthy.",
    "input": "",
    "output": "1. Eat a balanced diet..."
  },
  ...
]

Prompt Template #

Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
{instruction}

### Input:
{input}

### Response:
{output}

The model is trained with teacher forcing: the loss is computed only on the output tokens (after "### Response:\n").

A single Alpaca training example

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      A tokenized training example ready for the model

      • tokens : Array Nat

        Full token sequence (prompt + output + EOS)

      • promptLen : Nat

        Index where the output starts (loss computed from here)

      • seqLen : Nat

        Total sequence length

      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Format an Alpaca example into the standard prompt template

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Parse a single JSON object into an Alpaca Example

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Load an Alpaca dataset from a JSON file. The file should contain a JSON array of objects.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Hesper.Training.AlpacaDataset.tokenizeExample (encode : StringArray Nat) (ex : Example) (eosToken : Nat) (maxSeqLen : Nat := 512) :

                Tokenize an Alpaca example using the provided encode function.

                @param encode Tokenizer encode function (String → Array Nat) @param example The Alpaca example @param eosToken End-of-sequence token ID @param maxSeqLen Maximum sequence length (truncate if longer) @return TokenizedExample with prompt boundary marked

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Hesper.Training.AlpacaDataset.tokenizeDataset (encode : StringArray Nat) (examples : Array Example) (eosToken : Nat) (maxSeqLen : Nat := 512) :

                  Tokenize an entire dataset

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Print dataset statistics

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For