Recognizing Beam Profiles from Silicon Photonics Gratings using Transformer Model