There's been a lot of work in this area over the last few years, clustering and tagging text and video. Facebook even has an open source library for it called Starspace.
If you use facebook purely for posting and viewing family baby photos, but view websites about tractors, you'll probably see ads on facebook from tractor related companies.
Starspace is used by FB to tag the sites that report that you've visited them to facebook. So they can target ads