Emergence of a stochastic resonance in machine learning