Regularization, early-stopping and dreaming: a Hopfield-like setup to address generalization and overfitting