Generalized Lagrangian Neural Networks