Sigmora
Workflows

Neural network from scratch in Python, step by step

03
Debug training

Debug a training script that fails

Your Python file should train a small network, but it stops with an error or prints strange numbers. Sigmora opens the file, finds the lines that matter, runs your training command with Shell and shows the real output in a card, so you see what happened instead of a guess. Start with one file. The agent does not train anything itself, because your code does that, and it can take as long as it takes. The loop is short: read, run, compare, change. You choose the folder, you choose the mode and you decide which change to accept. Use only code, data and computers you own or may use, and keep each experiment small enough to repeat.

01

Open the folder

Choose the working folder that holds your training script, your config file and your logs. File tools work in that folder, and list_dir shows what is inside it. Keep the data you are allowed to use in the same place, so every path in your script stays short. The file tools use this folder.

02

Ask for a read

Ask Sigmora to read the training script and explain the layers, the loss and the loop. read_file and grep quote the lines it means, so you can check the explanation against your own code. Plan only mode changes nothing. Ask again if a block is still unclear.

03

Run the command

Name your training command and pick a mode. Shell runs it in Windows, in WSL or over SSH on your own server, and the card shows the real output and exit code. Python has to be installed where the command runs. Training can take a long time on your hardware.

04

Check the result

Expand the card and read the printed error or the loss values. A zero exit code only means the script ended without an error, so judge the numbers yourself, on validation data the model has not seen, and write down what you saw. Then decide on the next small change.

Example: one neuron learns the AND gate in plain Python

perceptron_and.py
# AND gate: one neuron (perceptron) learns the table
rows = [((0,0),0), ((0,1),0), ((1,0),0), ((1,1),1)]
w = [0.0, 0.0]
b = 0.0
rate = 0.1
for epoch in range(20):
    for x, target in rows:
        total = w[0] * x[0] + w[1] * x[1] + b
        out = 1 if total > 0 else 0
        err = target - out
        w[0] += rate * err * x[0]
        w[1] += rate * err * x[1]
        b += rate * err
print("weights:", w, "bias:", b)

This file trains a single neuron to learn the AND gate with a learning rate and a short loop of weight updates, then prints the weights and the bias. It uses plain Python, no libraries and no random numbers, so every run gives the same result. Run it with Shell, change the number of epochs and run it again to see what changes in the printed weights.

Walkthrough: tracking a convolutional neural network Python experiment

Read the training code

Before anything is changed, Sigmora reads. read_file opens your training script, list_dir shows the data folder and grep finds the lines that define the layers, the loss and the loop. You see the file text in the card, so you can compare the layer sizes with the shape of your data. The agent changes nothing at this stage. Neural network models of logic gates, such as the AND file above, are the classic first exercise, and the same reading step suits a neural network from scratch in Python that you wrote last month and no longer remember. Ask for any block in plain words, or switch to Plan only if you want a written explanation and no actions. Read each explanation next to the code and check that it matches what you wrote.

Run the training command

Choose Auto-run for a run you trust, or Ask first if you want to approve actions that change something. Shell starts your training command, for example python perceptron_and.py, in the environment you picked, and the card shows the real output and the exit code. Expand the card to read the full log of your convolutional neural network Python script line by line. Training can take as long as it takes, and Sigmora does not speed it up. When the loss is not converging in a neural network, the log is where you see it first. Look at the numbers, not only at the exit code, because a zero exit code means only that the script finished. Then decide whether the code needs a change, and ask for the diff only if it does.

Fix a shape error or a slow loss

edit_file changes the script and shows a diff. In Ask first mode nothing is written until you accept the diff, while Auto-run applies the change at once. A shape error usually means the data and the first layer do not match, so the fix is often one number. A loss that barely moves may point to the learning rate, to labels that do not line up with the data, or to a model that cannot yet overfit a tiny batch. Try that tiny batch first. Overfitting and underfitting are different problems, so look at training and validation loss before you change anything big. Building a neural network for chess is a larger project, yet it starts the same way. After the edit, run the command again with Shell and compare the new numbers with the old ones.

Log the results to a CSV file

To compare runs you need numbers in a file. write_file creates a CSV file in your working folder, or append_file adds one row per epoch, and read_file loads it again so the agent can put 2 runs side by side. Sigmora does not analyse the data for you; it saves the numbers and shows them, and you decide what they mean. Keep the validation data apart from the training data and leave the test set untouched until the end. Plan only mode can write the next experiment as a plan without running anything. When you are ready, switch the mode and let the agent carry it out. Before you keep a result, open the CSV file and check that the rows match what the card printed and that each column is labelled.

Sigmora for Windows

Try the workflow on your own project

Download Sigmora ↗