Why do we use np.tile function?

hi
in C2_W1_Lab02_CoffeeRoasting_TF, it says : ‘Tile/copy our data to increase the training set size and reduce the number of training epochs.’
why do we need to just copy and paste the training data? after all it is the same data. how can it assist the training process with the same data?

2 Likes

By increasing the data set size you are increasing the number of times you adjust your parameters. This means you get more adjustments per epoch. Say you have 10 data examples. If you duplicate it 10 times you get 100 items in your training set. This way you get 100 times of adjusting the w and b per epoch. Otherwise you’d have to run 10 epochs to get the same number of adjustments to w and b.

2 Likes

thank you for the response

1 Like

I had the same question and multiplication of the same data 1000 times still does not makes sense to me. It is the same data, it will not provide any new information. And what “does reduce the number of training epochs” mean in this context ? I am guessing that we will learn more about it next week when we learn more about “compile” step ?

1 Like

Hello @ealtan,

I think the reason for np.tile in that particular lab is simply to save some epochs. The idea is that, instead of running our original (before tile) samples for 1000 epochs so that the algorithm will see them 1000 times, we now tile my samples so that the algorithm will see them 1000 times within 1 epoch.

I believe the reason for saving some epoch is for speed. There is overhead in Tensorflow when it swiches from one epoch to another epoch. Now we save 1000 times those overheads by the np.tile arrangement.

We can do this when we already know that repeating samples that many times won’t hurt the final performance.

Cheers,
Raymond

2 Likes

Hello, @rmwkwok .
I have run this lab maintaining m=200 (without using np.tile()) and putting epochs=10.000, instead m=200.000 and epochs=10. I have got loss=0,0016 to the first option against loss=0,002 to the second one. I have been penalized by the time of running, but the result was better. I do not know if this time increase would be unacceptable for a large dataset. How could I know when to use each option (increasing dataset and decreasing epochs or vice-versa) ?
Thank you.

1 Like

Hello @Fac_Port,

The core idea of my last reply is only about the time. This is how, I believe, the lab was considering when deciding to do that.

For your cases, I have no particular suggestion as to when to do what. I recommend you to study your problem and algorithm on a case-by-case basis, and decide what to do on your own. It is also cruical for you to understand what is going on there. For example, why would the loss be different? Should they be different? What have you done to generate explanations and what have you done to persuade yourself your explanation is right?

Good luck!
Raymond

1 Like

Thank you.

1 Like