Learning with Hard Constraints as a Limit Case of Learning with Soft Constraints