I work totally the other way.
I write something close to a poem, and the music seems to get out of the words (the rhythm of the sentences etc.)
I have written melodies, but I always have a hard time matching words to it. I usually come up with a riff by repeating a sentence in my head (I actually talk in my head when I solo, as if each note was a syllable of the words I'm saying).