# Understanding of number of cells in layers of sequential models

I am trying to teach myself RNN, but I have a question.

And so, imagine 2 layers: an input layer with three neurons $$(x1, x2, x3)$$ and a classic recurrent layer with 2 neurons and an activation function f. I will write out the outputs of each neuron of the recurrent layer. $$ht1 = f (W * [x1, [0, 0, N]] + b) ht2 = f (W * [x2, ht1] + b)$$. It turns out that $$x3$$ is not used, what to do in this case?

And also, let's imagine a slightly different RNN architecture.

An input layer with two neurons $$(x1, x2)$$ and a classic recurrent layer with 3 neurons and an activation function f. I will write out the outputs of each neuron of the recurrent layer. $$ht1 = f (W * [x1, [0, 0, N] + bias]) ht2 = f (W * [x2, ht1] + bias)$$. It turns out that the 3rd neuron of the RNN layer is not used, what to do in this case?

UPD:
I realized that i don't know how recurrent neural networks work if number of neurons in recurrent layer doesn't equal(!=) number of inputs

I have one thought:
number of inputs has to always be equal number of neurons in RNN layer. But code below contradicts with my guess.

model = Sequential()
model.summary()


That's model for predicting next word.

## RNN cell versus neuron

You are hesitating between RNN cells and neurons. I understand you refer to RNN cells in your question. And so, traditionally any layer of a sequence model will always have the same number of cells as the length of your sequence or embedding size.

See difference between cell and neuron here: Difference between cell state and hidden state

See input size for sequence models here: How can I picture an unfolded RNN as a normal Feed Forward Network?

## Re; code snippet

In SimpleRNN, the first argument is the number of units in each cell i.e. number of neurons in each cell. The number of cells is not an argument in sequential layers, and always is equal to the length of your input sequences or size of embedding layer.

model = Sequential()
# Below, 128 is the neurons of each cell, and relates to the cell memory capacity.

• And so, traditionally any layer of a sequence model will always have the same number of cells as the length of your sequence or embedding size. I have updated question. Pls, look at that. My arguments in updated area contradict with ur answer above. Dec 8, 2020 at 14:44
• See my updated above that explains your update. Dec 8, 2020 at 17:29
• @hH1sG03, Are links above great for cells understanding? I realized that i don't know what are cells. Dec 8, 2020 at 18:15
• No problem. Keras API can seem intuitively misleading in terms of the argument "units". In dense layers, units define how wide a layer is, whereas in LSTM or RNN layers it defines how wide the Cells of the layer is, whereas the width of the layer itself is always equal to embedding size. It makes sense to have it this way to avoid breaking things, but it would be more intuitive to throw an error message of "embedding and lstm layer size must match" AFAIK Dec 8, 2020 at 19:18
• Have u received +50 of reputation? Dec 9, 2020 at 7:41

Inside SimpleRNN the input (of dimensionality 256) is projected onto a representation space of dimensionality 128, by means of a matrix multiplication. The RNN operations are with these vectors of size 128. If you take a look at the source code of SimpleRNN, you can see that the projection matrix is is stored in a member variable called kernel. You can see how in method SimpleRNNCell.call one of the first things is to project the inputs with K.dot(inputs, self.kernel).

P.D.: To me, the "neurons" analogy has always been misleading. I like to think about neural network in terms of differentiable matrix operations: matrix multiplication, matrix addition, position-wise transformations like sigmoid, hyperbolic tangent, ReLU, etc. This makes it easier to reason about the dimensionality of the input and output of each computation step.

• Sorry, but ur explaining is hard. Dec 8, 2020 at 18:16
• This is a great answer. Nikto simply put, you could say that each RNN cell has a spreadsheet inside of it. The size of that spreadsheet is defined by the units argument in SimpleRNN, and one could portray each box of the spreadsheet as a neuron. Dec 8, 2020 at 19:32
• @hH1sG0n3, yes, i understand. All tutorials that i found didn't tell about cells if it wasn't LSTM or GRU. They only told about neurons. Could u give me couple of links on right tutorials. I especially appreciate videos. Dec 9, 2020 at 6:27
• I have understood. They interpreted cells like neurons, therefore for now i don't know what are neurons in cells. Dec 9, 2020 at 7:13
• The number of neurons in the cells, define their size. In other words that means, the larger the number of neurons in a cell, the larger its capacity to carry over "memories" across cells. Dec 9, 2020 at 10:09