Machine learning methods have been lately used to solve differential equations and dynamical systems. These approaches have been developed into a novel research field known as scientific machine learning in which techniques such as deep neural networks and statistical learning are applied to classical problems of applied mathematics. Because neural networks provide an approximation capability, computational parameterization through machine learning and optimization methods achieve noticeable performance when solving various partial differential equations (PDEs). In this paper, we develop a novel numerical algorithm that incorporates machine learning and artificial intelligence to solve PDEs. In particular, we propose an unsupervised machine learning algorithm based on the Legendre-Galerkin neural network to find an accurate approximation to the solution of different types of PDEs. The proposed neural network is applied to the general 1D and 2D PDEs as well as singularly perturbed PDEs that possess boundary layer behavior.