compile: Compile a Model

compile.ggml_sequential_modelR Documentation

Compile a Model

Description

Configures the model for training by setting the optimizer, loss function, and metrics. This is the keras-compatible interface; it delegates to ggml_compile.

Usage

## S3 method for class 'ggml_sequential_model'
compile(
  object,
  optimizer = "adam",
  loss = "categorical_crossentropy",
  metrics = c("accuracy"),
  ...
)

## S3 method for class 'ggml_functional_model'
compile(
  object,
  optimizer = "adam",
  loss = "categorical_crossentropy",
  metrics = c("accuracy"),
  ...
)

Arguments

object

A model object (e.g. ggml_sequential_model or ggml_functional_model).

optimizer

Character: "adam", "adamw", or "sgd".

loss

Character: "categorical_crossentropy", "mse", "mae", "huber" or "binary_crossentropy". For a multi-output model, a list with one loss per head.

metrics

Character vector of metrics (default "accuracy"); see ggml_compile for the full list.

...

Additional arguments passed to ggml_compile.

Value

The compiled model (invisibly).

Examples


model <- ggml_model_sequential() |>
  ggml_layer_dense(10, activation = "softmax", input_shape = 4)
model <- compile(model, optimizer = "adam",
                 loss = "categorical_crossentropy")


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.