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" or "mse".

metrics

Character vector of metrics (default "accuracy").

...

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 July 14, 2026, 1:08 a.m.