liveBook · Manning

Nan

As explained in Machine Learning System Design

NaN is a floating-point value representing an undefined or unrepresentable numerical result.

NaN, or “not a number,” appears when training produces an undefined or unrepresentable numerical result. A loss exploding toward NaN usually signals a computational or implementation problem rather than ordinary model behavior. section 9.1.3

When a loss trends toward NaN, check:

  • Exploded gradients; try gradient clipping, a lower learning rate, or different weight initialization. section 9.1.3
  • Mathematical errors such as division by zero or taking logarithms of zero or negative numbers. section 9.1.3
  • NaNs already present in the data, often indicating missing preprocessing or an implementation error. section 9.1.3

A loss curve that breaks

A model may converge normally and then suddenly trend toward NaN. Treat the break as a debugging signal: inspect gradients, numerical operations, input data, learning rate, and initialization. section 9.1.3

Figure 9.4 A model was converging until something went wrong.
figure

Use the figure to recognize a training curve that converges until a computational problem interrupts it. section 9.1.3

How Machine Learning System Design covers it

How deep it goes
Explains diagnostic causes and practical remedies, but does not derive floating-point behavior or implementation details.
Examples
Illustrates NaN through loss explosions, division by zero, invalid logarithms, and NaNs already present in data.
What it assumes
Assumes familiarity with model training, gradients, loss curves, and basic data preprocessing.
What you can do after
Diagnose unstable training by checking gradients, numerical operations, learning rate, initialization, and preprocessing.
How it connects
Connects NaN with loss curves, gradient explosion, gradient clipping, learning rate, weight initialization, and data preprocessing.

Also explained in

Compare how 9 books explain nan →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.