A theoretical framework for overfitting in energy-based modeling