So. The terms "geek" and "nerd" have definitely developed their usage and meaning over time. People call themselves nerdy and geeky now to identify their aesthetic, interests, and personalities to communicate that with other like-minded individuals.
Decades ago when it was being used as more of an insult, it wasn't really "against intelligence." Rather, it was against neurodivergence. When someone was a "geek" back then, it was usually someone who was of a single interest--someone hyper fixated on niche things and ideas. It wasn't about them being smart, it was about them being obsessive. Nerd was less insulting, I would say, but still used in opposition to someone who was more of a hermit and bookish. Bookish isn't a bad thing, but social isolation is.
The "taking back" of the terms geek and nerd began its development in the 90s when "loser culture" and "being real" was a big thing. To use the word on yourself was celebrating your deviation from acceptable social standards. In early 2000s, people started beginning to see a rise in more niche/cult subject matter because people were essentially calling themselves out for being a certain way or being into certain things--like a freaking beacon to call upon their fellow nerd, lol. The internet's developing social culture around that time allowed for both outward expression and simultaneous anonymity. And once nerdy subcultures were accepted into the social standard, we now have stores called "Think Geek" and have extremely successful industries centered around media that is consumed by people who refer to themselves as geeks and nerds.
Hope that wasn't too wordy.