RNN (recurrent network)

How a Neural Network Predicts Day Seven From Six Days of Sales: RNN

A recurrent neural network for sales forecasting, computed step by step.

A recurrent neural network (RNN) reads a series value by value and uses a hidden state to keep track of what has happened so far. This page works through a trained network with 97 parameters on a sales series. For each of the six days, you see how the new value and the previous state together produce the next state.

Vanilla RNN · trained 97 parameters 8 hidden values tanh Time series

At the top, choose an example series and change sales for the last day if you like. “Play” runs the calculation on its own, and the step list takes you to any point.

All computations run in your browser. Teaching example, not a production forecast.

What the Walkthrough Shows and Where It Ends

The walkthrough shows a simple recurrent network, often called a vanilla RNN. It receives the daily sales of six days one after another and estimates sales for the seventh. In every time step, the same cell computes with the same weights. The only things that change from step to step are the input value and the hidden state of eight numbers.

The weights were trained with PyTorch. Your browser carries out the calculation steps on this page with these weights. For the four example series, the result matches that of PyTorch. The training and test metrics come from the training run.

All series on this page are synthetic, including the training and test series. They rise, fall, or stay stable. Weekly rhythm, holidays, and promotions do not occur. The page is a teaching example, not a forecast for real sales data. On the synthetic test series, the network is no more accurate than a straight line through the six days. On long series, a simple RNN loses early information because the gradients can vanish or grow too large during training. LSTM and GRU counter this loss of information with gates. The LSTM walkthrough shows how an LSTM computes.