I think that the big difference in STEM is that nerdy boys exist in such a number that they can still get acceptance and support. It's not as normal as, say, being a football player, but male nerds aren't exactly rare.
In contrast, because there are much fewer female nerds, their awkwardness is even more exaggerated, and this feeds back on itself to heighten the pressure to conform. Boys find some support in numbers, and their interest in the subjects smooths over any discomfort. Girls don't have any of that support, so if they aren't absolute fanatics about the subjects, they're going to conform.