Skip to content

Naming the network

H.P. Gansevoort edited this page Oct 5, 2026 · 3 revisions

Step 9 — Naming the network, or the trainer

The last step of the declaration says which network these rows are prepared for — the layers, what moves them, what judges them, when the run stops — and then running the pipeline trains exactly that network. The model is declared with the pipeline rather than written beside it, so the whole course from a file to a validated model is one artefact.

using DeepSharp.Learners.Networks;
using DeepSharp.Pipelines;

var pipeline = Pdd.Create()
    .ReadCsv("titanic.csv")
    .Declare(schema => schema.Integer("survived", "sibsp", "parch").Category("pclass", "sex").Optional("age", ColumnKind.Number).Number("fare"))
    .SplitStratified("survived", train: 0.70, validation: 0.15)
    .Target("survived")
    .FillMissing(fill => fill.Median("age"))
    .EncodeCategories()
    .Normalise("age", "fare", "sibsp", "parch")
    .WithTensorflow(network => network                // the words TensorFlow and Keras use
        .Dense(16).Relu().Dense(1)                    // the widths come from the rows
        .Adam(0.01)
        .BinaryCrossEntropy()
        .Run(seed: 20260929, epochs: 100)
        .StoppingAfter(patience: 10))
    .Build();

var trained = pipeline.Train();                       // the course, from the file to the trained model

Two vocabularies, one model. .WithTensorflow(…) reads as Keras does — stack, compile, fit. .WithTorch(…) reads as PyTorch does. They lower onto the same model, so nothing downstream knows which door you used: the same network, bit for bit, and the same file. Each writes down the number its own library would have left implicit, so the file says which run was asked for.

A network is not the only learner. .WithML(trainer => trainer.FastTree()) names a trainer from ML.NET instead, and pipeline.TrainWithML() trains it. The run is then made for what a tree needs, which leaves the scalings out and writes down which — everything else is the same steps over the same rows, so the report measures the two against each other. One learner a declaration, so comparing them is two declarations differing in this one line: ML.NET learner.

You do not have to use this step. A network written as code and fitted by hand is still fitted on the rows a pipeline prepared — compiled.Fit(prepared, options) — and still measured by that pipeline's report. Naming it here is what lets the file say what was trained behind which steps.

The engine is a name, not a dependency. The declaration may say which engine to run on; the application fills that name in. A model written against the seam cannot tell whether the light engine or libtorch is underneath, on the processor or on a graphics card.

Next: Saving and replaying · Every layer, loss, optimizer and schedule: Networks

Clone this wiki locally