Learning Spectral Methods by Transformers