Mounting is a brain pattern that is normal for dogs. Dogs do not have any emotional feeling about it nor do they feel any embarrassment, but people do. When it is driven by hormones, as in an intact male, it is more likely to be intended as a mating behavior, but neutered males and females can engage in this conduct as well, and almost all puppies do.
There can be many reasons for mounting. It can be a play behavior or a manifestation of stress or excitement. No matter what the motivation, if it is a behavior that you would like to abolish, you can distract the dog with a substitute action that he knows will earn a reward. It is important that you seem oblivious to the mounting though, and act as though the alternate behavior was a spontaneous request.
If the mounting was related to stress and you yell or punish, the stress increases. If the mounting is truly sexual, punishment will not help because reproduction is instinct and requires patience to train self-control.
Since the mounting is just another movement to your dog or puppy, punishment will only teach him to fear you and he is not likely to connect the action with the punishment. If your dog is not a breeding animal, neutering will decrease the testosterone. Mounting behavior will very likely be diminished, but because it is a normal brain pattern, it may not disappear completely. It is still smart to train your dog to use other methods to express himself. You can train your dog to eliminate the behavior with consistent training when he is hungry and ready to learn (hunger is another instinct that can be useful in training). Find a reward that is high value to the dog.
Start strongly and consistently reinforcing an alternate desirable behavior. Ask for and reward this good behavior, like sitting calmly, regularly at random times when there is no mounting. Your dog will not be surprised if you stop him from mounting in order to sit and be rewarded. Eventually your dog should learn to keep at least some of his attention on you in case of random requests (and rewards) and the embarrassing mounting episodes can be redirected, regardless of the reason.
Try not to be embarrassed when your dog engages in this normal behavior. Other dog lovers will understand. Use the training time to redirect your dog’s actions and remember that any time spent training and rewarding is also valuable bonding time for you both.