# Sampling novel sequence using np.random.choice

Sir ,do we only use the `np.random.choice` function in the first step?

Which week, and which assignment notebook?

sir not from assignment it’s from lecture “sampling novel sequence”

sir, I am confused that are we only choosing first word randomly to start the sentence or are we making whole sentence randomly by choosing random words from distribution at every timestep

Hey @Ashish_Sharma6,
If you take a look at the documentation of `np.random.choice` here, you will observe `p` as one of the arguments. What this argument does is that it helps us to specify probability distribution if needed, to sample the elements from the given collection.

If we don’t specify `p`, then it returns one of the elements at random, but if we specify `p`, it will choose elements in accordance with the probabilities. Let’s take a simple example.

``````a = [17, 23, 15]
size = 1
p = [0.1, 0.2, 0.7]
np.random.choice(a = a, size = size, p = p)
``````

You can observe that `np.sum(p) = 1`, and it must be, since the sum of probabilities for choosing elements from a given collection should be 1. This code will return 17, only 10% of the time, 23 only 20% of the time and remaining 70% of the time, it will return 15.

Now coming back to the lecture video, we are using `np.random.choice()` at every time-step, but at every time-step, we are specifying the probability distribution as well, which is nothing but the softmax distribution produced by the RNN layer at every time-step. So, we are not choosing the words randomly, but according to the softmax distribution.

Let us know if this helps you out.

Cheers,
Elemento