Hi Steven Liu , that is a great question!
I do this with the following method: First, I try to identify the song’s key. I usually do this by finding the standard pentatonic shape and start improvising. Most pop songs stay in one key anyway, so that shouldn’t take too long to figure out the key.
After knowing what my playground is, I start to improvise until I figure out the main melody. Melodies tend to have a complex rhythm, so what helps me a lot is saying the words while improvising. Then I have a much easier time figuring out the specific rhythm!