Even though AdSense's algorithms do a pretty good job with this, it's still not perfect, and it's still a computer program making deciding relevance, not a human being.
The best thing you can do to improve ad relevancy is to write content that's focused on your subject matter. Don't stray off topic with anecdotes on your mother's cooking, or something cute your dog did. The keywords in those sentences cause AdSense to figure them into determine relevant ads.
Stuff your articles with keywords! Take a look at this very article, you'll notice that I have the word "AdSense" in every paragraph. I also have it in the domain name, and I also have it in the filename for this article "getting-relevant-ads-on-adsense.htm".
Here's a great AdSense optimization tip: Make sure you have your most relevant keyword in the HTML coding of your article. There are places where you can do this...
- The TITLE tag
- The META Keywords
- The "Alt=" attribute of your images
- The "Title=" attribute of your links
Over time, AdSense will monitor which ads are getting clicked on the most from your website, and will display them more often. This has the effect of optimizing the best ads to display. But you can help it get there faster by focusing your content on the subject matter, and including as many top-level keywords.