There are a number of ways to get a dog to stop biting, including substituting a toy or a treat in place of a person's hand or another body part. Yelping can also stop a puppy from biting too hard, at least momentarily.
It is in a puppy's nature to mouth and nip a little bit as he grows up. When watching puppies play together, mouthing, nipping and biting is a large part of the play. Dogs can police their playmates by yelping when the biting becomes too rough. If dogs are indeed playing and not biting, a loud yelp serves to stop the play momentarily and alerts other dogs that they are biting too hard. If a dog is biting or mouthing a person's hand too hard, the owner should yelp loudly and let the hand go limp. The dog should eventually pick up on these cues and learn how hard is too hard to bite.
Some dogs, especially when they are puppies, aren't used to being petted. They may mouth when someone goes to pet them. By offering up a treat in one hand and petting with the other, the dog eventually comes to see being petted as a positive.