Created
August 9, 2026 04:27
-
-
Save ramsunvtech/b7a176f54c637d983723cd78d048f2c8 to your computer and use it in GitHub Desktop.
Google Colab Code to test Word2Vec model to find cosine and OOV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gensim.downloader as api | |
| # 1. Load pre-trained Google News Word2Vec model (~1.5 GB download) | |
| # Note: For a faster download during testing, you can use "glove-wiki-gigaword-50" | |
| print("Loading Word2Vec model...") | |
| model = api.load("word2vec-google-news-300") | |
| print("Model loaded successfully!\n") | |
| # 2. List of test samples | |
| test_words = [ | |
| # --- User-Provided Samples --- | |
| "unhappines", # Typo / missing subword "un" | |
| "tokenization", # Rare/technical term absent in 2013 Google News | |
| "cat", # Standard word (from "the cat") | |
| # --- 3 Additional Samples --- | |
| "quickkkly", # Multi-letter typo | |
| "hyperparameter", # Specialized machine learning term | |
| "skibidi" # Modern slang / new word | |
| ] | |
| # 3. Test OOV status in Word2Vec | |
| print(f"{'WORD / TOKEN':<18} | {'STATUS':<15} | {'SIMILAR / VECTOR ACTION'}") | |
| print("-" * 65) | |
| for word in test_words: | |
| if word in model.key_to_index: | |
| # Get most similar word to prove it has a vector | |
| similar = model.most_similar(word, topn=1)[0][0] | |
| print(f"{word:<18} | ✅ IN VOCAB | Top Neighbor: '{similar}'") | |
| else: | |
| print(f"{word:<18} | ❌ OOV (KeyError) | Cannot process vector!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment