Baking soda “adsorbs” odors, which means it takes odors from the air. It neutralizes acid-based odors in water.
Liberally sprinkle baking soda on the carpet. Let set overnight, or as long as possible (the longer it sets the better it works). Sweep up the larger amounts of baking soda, and vacuum up the rest. (Note that your vacuum cleaner bag will get full and heavy.) Redo the process if you still smell odors you wish to remove. Baking soda works like magic, it sometimes just takes time and making sure you are using enough baking soda.
Tip: Potty training a puppy? This works like magic. Pour baking soda (quite a lot!) on spot and let it sit. In a few hours you will see how the baking soda pulled the urine from the carpet. Sweep with a broom and then vacuum when soaked soda is dry.
Caution: While damp baking soda works really well for many odors, damp baking soda can also get stuck onto the carpet fibers and be difficult to clean. If you live in a very humid climate you might substitute a light spray of white distilled vinegar for the baking soda.