Mostly by tone of voice and body language than words, but repeated words I think they figure out associations. But there must be more subtle things they pick up as well because my boy can tell a lot about my emotions even though I haven't said anything, or done anything in particular differently.