I think they do it with us more than other people as they know they can. It's an affectionate thing really - they don't realise they are hurting us but enjoy the reaction. It's playful, though is starting to show up in anger too. They are testing boundaries on us as it is safe to do so - they know we love them and are pretty sure of our reaction.
When it is playful I stop smiling, say no and distract. Refusing to engage in the game.
When it is done in anger I shout am far firmer and put them down and walk away.
Then I reward good behaviour with lots of cuddles and praise.
Honestly I don't think it works particularly - toddlers all go through violent phases and grow out of it when they realise it just isn't socially acceptable. DD1 is learning that her friends won't play with her if she hurts them, and in turn is teaching the same lesson to them - she sulks if one of her friends hits her. Nursery are quite lax and will separate children if they are hurting each other but take a step back and let them sort things themselves if it is just rough interaction. Once they are done they will take the children aside and explain things, punishing if necessary. If one is attacking another unprovoked then that child is dealt with far more quickly.
It seems to work. But we do have a violent nature at that age and it's a question of working through it with the least damage done.
I don't believe in the long explanations advocated by some parenting books - they just don't see further than the next few minutes. But maybe I am just being French and too strict. Talking to our kids is great but I was reading another thread earlier all about negotiating with them and just thought oh ffs :) I'll find a link it's quite funny.