womogenes / semantle-bot

8 stars 2 forks source link

vectorization suggestion #2

Closed LuukSuurmeijer closed 2 years ago

LuukSuurmeijer commented 2 years ago

Hi! Thanks for the awesome idea and video about cracking Semantle. Your brute-force algorithm can actually be vectorized (rewritten in terms of matrix-vector operations), which is much faster than looping over all words as you do currently. I have written the code to do this, and on today's (04-07-2022) Semantle the vectorized code achieves a ~4.5 times speed-up over the vanilla code.

Guess: 'house', sim: 8.43

Method                    Elapsed time              Time per cosine          
Vanilla:                  4.242002490995219         4.354389278267298e-05    
Vectorized:               0.9111559660013882        9.35295954589339e-06     
Speed-up factor: 4.655

If you're interested you can add me to the repo and I'll upload the code to a separate branch. Or just shoot me an e-mail luuksuurmeijer@gmail.com.

Best,

Luuk

womogenes commented 2 years ago

Hi Luuk, thanks for the suggestion--I hadn't thought of that! I've invited you as a collaborator to the repo so that you can make a branch and open a PR directly.