  We present a structure-preserving Eulerian algorithm for solving
$L^2$-gradient flows and a structure-preserving Lagrangian algorithm for
solving generalized diffusions. Both algorithms employ neural networks as tools
for spatial discretization. Unlike most existing methods that construct
numerical discretizations based on the strong or weak form of the underlying
PDE, the proposed schemes are constructed based on the energy-dissipation law
directly. This guarantees the monotonic decay of the system's free energy,
which avoids unphysical states of solutions and is crucial for the long-term
stability of numerical computations. To address challenges arising from
nonlinear neural network discretization, we perform temporal discretizations on
these variational systems before spatial discretizations. This approach is
computationally memory-efficient when implementing neural network-based
algorithms. The proposed neural network-based schemes are mesh-free, allowing
us to solve gradient flows in high dimensions. Various numerical experiments
are presented to demonstrate the accuracy and energy stability of the proposed
numerical schemes.
