delft icon indicating copy to clipboard operation
delft copied to clipboard

avoid setting random seed at module level

Open de-code opened this issue 6 years ago • 1 comments

It is generally preferable if module level code doesn't have side-effects. i.e. just importing a module shouldn't change anything (there may be few exceptions). It would be better if the seed was set by the main method for example.

e.g.

>>> np.random.seed(123)
>>> np.random.get_state()[1][0]
123
>>> import delft.sequenceLabelling.data_generator
Using TensorFlow backend.
>>> np.random.get_state()[1][0]
7

At the end, I would expect the seed to be the same.

(It's not a big issue as there is a simple workaround)

de-code avatar Jul 05 '19 08:07 de-code

I wonder if we should fix this, the whole issue here is that numpy has these seeds that are static. Whenever you set them I guess they will be modifying the internal state. If you, for example, instantiate the data _generator the seed will be modified.

lfoppiano avatar Dec 24 '19 12:12 lfoppiano