ggml_default_mlp: Default MLP builder for classification and regression

View source: R/default_mlp.R

ggml_default_mlpR Documentation

Default MLP builder for classification and regression

Description

Constructs an uncompiled sequential multi-layer perceptron suitable as a starting point for tabular classification or regression. This is the default model_fn used by LearnerClassifGGML and LearnerRegrGGML when the user does not supply a custom builder, and it is also exported for direct use or as a template for user-defined builders.

Usage

ggml_default_mlp(
  n_features,
  n_out,
  task_type = c("classif", "regr"),
  hidden_layers = c(128L, 64L),
  activation = "relu",
  dropout = 0.2
)

Arguments

n_features

Integer. Number of input features. Required.

n_out

Integer. Number of output units. For classification this is the number of classes; for regression this is typically 1.

task_type

Character. One of "classif" or "regr". Controls the final layer's activation.

hidden_layers

Integer vector. Widths of the hidden dense layers. Default c(128L, 64L). Pass integer(0) for a linear model.

activation

Character. Activation applied to each hidden layer. Default "relu". Passed through to ggml_layer_dense.

dropout

Numeric in [0, 1). Dropout rate applied after each hidden layer. Set to 0 to disable dropout. Default 0.2.

Details

The returned model is not compiled: the caller is responsible for calling ggml_compile with the appropriate loss ("categorical_crossentropy" for classification, "mse" for regression) before training.

The final layer is chosen based on task_type:

  • "classif" — dense with units = n_out and softmax activation.

  • "regr" — dense with units = n_out and no activation (identity / linear output).

Value

An uncompiled ggml_sequential_model object. Call ggml_compile before ggml_fit.

See Also

ggml_model_sequential, ggml_layer_dense, ggml_layer_dropout, ggml_compile

Examples

## Not run: 
# 3-class classifier on 20 features
model <- ggml_default_mlp(
  n_features   = 20L,
  n_out        = 3L,
  task_type    = "classif",
  hidden_layers = c(64L, 32L),
  dropout      = 0.1
)
model <- ggml_compile(model, optimizer = "adam",
                      loss = "categorical_crossentropy")

# Single-output regressor
reg <- ggml_default_mlp(
  n_features = 10L,
  n_out      = 1L,
  task_type  = "regr"
)
reg <- ggml_compile(reg, optimizer = "adam", loss = "mse")

## End(Not run)

ggmlR documentation built on July 14, 2026, 1:08 a.m.