The advent of massive data repositories has propelled machine learning techniques to the front lines of many scientific fields, and exploring new frontiers by leveraging the predictive power of machine learning will greatly accelerate big data-assisted discovery. In this work, we show that graph-based neural networks can be used to predict the near edge x-ray absorption structure spectra of molecules with exceptional accuracy. The predicted spectra reproduce nearly all the prominent peaks, with 90% of the predicted peak locations within 1 eV of the ground truth. Our study demonstrates that machine learning models can achieve practically the same accuracy as first-principles calculations in predicting complex physical quantities, such as spectral functions, but at a fraction of the cost.