Forward Prop using Python - how to specify the number of neurons or units?

When creating a post, please add:

  • Week -1
  • [Link to the classroom item you are referring to:]general-implementation-of-forward-propagation
  • Description:
    The video talks about implementation of forward propagation using Python. While I understood the mock code, the dense function was defined as dense(a_in, W, b). This was missing the no.of units or neurons parameter? How is that accommodated in this mock code? Am I misunderstanding this?

units = W.shape[1] # 3 units in the example from the video as there are 3 columns in W

1 Like

Hello, @proficio20,

Welcome to our community!

In the previous Tensorflow lesson, we know that tensorflow’s Dense needs the units parameter. Behind the scene, tensorflow uses it to create the Dense’s weight matrix because the matrix’s shape is (number of units in previous layer, number of units for this layer).

However, in this lesson, since we are already giving this dense the W weight matrix, it would not need the units parameter for it to create any weight matrix, instead, we can tell the units from the shape of W which @mappx has pointed out for us.
Cheers,
Raymond

A slide from a previous Tensorflow lecture:

A relevant slide for this lecture:

1 Like