Deep Learning Starter · free course

Free course · Lesson 3 of 5

Recurrent Neural Networks (RNNs) for Sequence Data

In this lesson you will

  • Explain how sequence data is represented
  • Describe how recurrent networks and attention differ

RNNs (Recurrent Neural Networks) are designed for sequential data — time series, text, audio, or sensor logs. Unlike regular neural networks, RNNs have a memory: they process inputs one step at a time and pass a "hidden state" from step to step. LSTMs (Long Short-Term Memory) are an advanced version that can remember information over long sequences, solving the "forgetting" problem of basic RNNs.

  • RNN/LSTM input shape: (batch_size, timesteps, features) — e.g., 30 days of 3 sensors.
  • LSTMs are used for weather forecasting, stock prediction, text generation, and speech recognition.
  • In South Sudan, LSTM models could predict river levels from historical sensor data for early flood warnings.
  • Use TensorFlow/Keras LSTM layer — simple to add to any model.

💡 Practical Skill: Process time-series data from IoT sensors or weather stations. Clean the data in Jupyter Notebooks, structure it as sequences, and train an LSTM to make predictions.

Worked exampleLSTM for Sequence Prediction
Python
# Setting up an LSTM model for time-series prediction# Input: 10 timesteps, each with 1 feature (e.g., daily temperature) import tensorflow as tf # Define the LSTM modelmodel = tf.keras.Sequential([    # LSTM layer: 50 memory units, expecting sequences of 10 steps    # input_shape = (timesteps, features)    tf.keras.layers.LSTM(50, activation='tanh', input_shape=(10, 1)),     # Dense output layer: predict the next value    tf.keras.layers.Dense(1)]) # Compile the modelmodel.compile(optimizer='adam', loss='mse') print("\u2705 LSTM model ready for sequence data!")print(f"   Input shape: (batch_size, 10 timesteps, 1 feature)")print(f"   Output: 1 value (next step prediction)") # Show model architecturemodel.summary() # Example: simulate how you'd reshape raw sensor data# Raw data: [25, 26, 27, 26, 25, 24, 23, 24, 25, 26, 27, 28]# Sequences of 10 steps => predict the 11th value print("\nData shape hint: reshape raw sensor logs to")print("   (num_sequences, 10, 1) before training.")

Practice exercise

List three sequence tasks from daily life (for example SMS sorting or voice notes) and say what the sequence and the output would be for each.

Key takeaways

  • Order matters in sequences
  • Embeddings turn words into learned vectors
  • Attention lets models look at every part of a sequence at once
In the full program Module 3: Sequence Models for Text and Time See how this topic is taught in depth, with practical activities and an assessment.

Free self-study lesson — no certificate. For the full instructor-led program, see registration options.