RNN Flashcards

1
Q

What is the big idea behind RNN?

A

RNNs are designed for sequential data — where order matters (e.g., time series, text, speech, etc.).

Unlike feedforward networks, RNNs have loops, which means they use their previous output as input for the next step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In one sentence how can i describe RNN?

A

RNNs are designed to handle sequential data — they remember what they’ve seen before.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why are there two outputs in an RNN cell?

A

✅ 1. hₜ → the hidden state
This is the internal memory of the RNN.
It gets passed to the next time step — helps carry context forward.
It’s always computed at every time step.

✅ 2. yₜ → the model output (optional)
This is the actual prediction/output — like sentiment, next word, etc.
It’s computed only if the task needs output at every time step.

For example:
In language modeling → you want output (next word) at each time step → need yₜ for each t.

In sentiment classification → you want only the final answer → use only the last hₜ.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an RNN cell?

A

Structure of an RNN Cell
Input at time t (xₜ): Current word (e.g., “love”).

Hidden state (hₜ₋₁): Memory from the previous step (e.g., h₁ = info about “I”).

Output (hₜ): Updated memory (passed to the next step).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Rnn hidden state math

A

The RNN cell computes:
hₜ = tanh(Wᵢ · xₜ + Wₕ · hₜ₋₁ + b)

Wᵢ: Weight matrix for the input.

Wₕ: Weight matrix for the hidden state.

b: Bias term.

tanh: Activation function (squashes values between -1 and 1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how I Understand the Difference between ANN and RNN

A

Understanding the Difference between ANN and RNN:

I now understand the key difference between ANN and RNN.
In a normal ANN, the entire sentence “I love this movie” is treated as a single input at once — like one flat vector going through the network.

But in an RNN, the sentence “I love this movie” is processed sequentially — one word at a time.

Each word is passed through the RNN cell along with the hidden state from the previous step. This process continues word by word, allowing the model to remember the context through these hidden states.

Only after the final word is processed, the final hidden state (which has accumulated the gist of the whole sentence) is passed to the output layer to make the final prediction.

Until that point, the sentence flows through a loop inside the RNN, updating the hidden state at each step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Example of how RNN works with sentiment analysis

A
  1. Text Data Collection
    You start with a dataset containing sentences and their sentiment labels (like “I love this!” = Positive, “Worst experience!” = Negative).
  2. Text Preprocessing
    Clean the sentences — remove punctuation, lowercase everything, handle contractions if needed.
  3. Tokenization
    Convert each word into a unique integer using a tokenizer (for example, “I love this” → [1, 5, 9]).
  4. Padding Sequences
    Make all sentence sequences the same length by padding shorter ones with zeros (so the model processes them uniformly).
  5. Embedding Layer
    Map each word token to a dense vector using embeddings (e.g., from a 10,000-word vocab → 100-dim vectors).
  6. RNN Layer
    for each entry in dataset, the RNN reads one word at a time, updating its hidden state after each word, capturing the meaning and context over time.
  7. Dense Output Layer
    The final hidden state (the learned context) is passed to a dense layer with sigmoid activation to give a sentiment prediction (like 0.87 → Positive).
  8. Model Training
    Feed the input-output pairs to the model and train it by minimizing loss (like binary cross-entropy).
  9. Prediction
    After training, input a new sentence and get the predicted sentiment — the model uses learned patterns to decide.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

RNN Sentiment Analysis — Simple Flow

A

RNN Sentiment Analysis — Simple Flow (Cheat Sheet)
Text Data: Sentences + Labels (Positive = 1, Negative = 0)

Preprocessing: Clean the text (lowercase, remove punctuation, etc.)

Tokenization: Convert words to numbers

Padding: Make all sequences same length

Embedding Layer: Turn numbers into word vectors

RNN Layer: Reads word-by-word, keeps memory (context)

Dense Layer: Takes final hidden state, predicts sentiment

Train: Use loss function + backpropagation to learn

Predict: Feed new sentence, get 0 or 1 output (negative or positive)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Rnns price prediction model

A

Summary Flow:
Collect stock prices
Create X and y using a sliding window
Normalize (MinMaxScaler is great here)
Build RNN : RNN Layer reads price by price, keeps memory track from hidden state
Train on (X, y)
Predict future price

here the dataset is like:
X (Input – Past 10 days) y (Target – Next Day)
[145.0, 147.2, …, 157.0] 158.5
[147.2, …, 158.5] 160.0
[149.1, …, 160.0] 162.3

RNN Architecture in Simple Terms:
This is where the magic happens!

📥 Input:
Each X is a sequence of 10 prices.
Shape = (timesteps=10, features=1)

🔄 RNN Cell:
The RNN reads price 1, updates hidden state.
Reads price 2, updates again…
…until price 10.

Now the final hidden state = context of last 10 days.

📤 Output:
Final hidden state → passed to a dense layer
🎯 Dense layer gives you: predicted price of day 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly