The most effective way is to have them professionally cleaned. That's the most expensive, unfortunately. Next best is to thoroughly vacuum and steam clean them with a cleaner made for the steamer.
Hi Marilyn. You can rent a steam carpet cleaner from most grocery stores. The soap will be displayed right by the steam cleaners. I rent one every Spring when I do my spring cleaning. And I am always surprised how much dirt I get up. I clear almost all of the furniture from the rooms with carpet and I vacuum them too. I rent a steam cleaner for 6 hours so I want to be ready to clean as soon as I get home with the steamer. Good luck Marilyn.
Hire a professional to have steam cleaned. I have mine done every 3 months, but I have a lot of pets. If that isn't in the budget yet, you can rent a machine from any hardware store or home improvement center. Be sure to not use too much "soap" or "cleaner" as if it is not rinsed out well, it actually can attract more dirt.
If the carpet is saggy you can have them re-stretched from carpet installers. I've been thinking of cleaning mine and having them re-stretched. I haven't inquired about price just as of yet.