$ python Python 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:38:11) [Clang 14.0.6 ] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import gensim >>> import nltk >>> from nltk.data import find >>> word2vec_sample = str(find('models/word2vec_sample/pruned.word2vec.txt')) >>> model = gensim.models.KeyedVectors.load_word2vec_format(word2vec_sample, binary=False) >>> model['table'] array([-0.0539292 , -0.00988398, 0.0439086 , 0.0798006 , -0.0157597 , -0.00938295, 0.0455483 , -0.0761568 , 0.0136645 , 0.0991131 , -0.0304263 , -0.0623101 , 0.0787075 , -0.0302441 , -0.0391715 , 0.0779787 , 0.0389894 , -0.0186748 , 0.0776143 , -0.02077 , 0.0783431 , 0.0521073 , -0.054658 , -0.0260536 , 0.0227742 , 0.0553867 , -0.0699622 , 0.0161241 , -0.0428154 , -0.0240495 , -0.0838089 , 0.0579375 , 0.002471 , 0.0532004 , -0.0163063 , -0.0415401 , -0.0439086 , 0.0765212 , -0.0327948 , -0.0783431 , -0.0271468 , -0.0564799 , 0.0247783 , -0.026418 , 0.0725129 , -0.0176727 , -0.00131521, 0.00947405, 0.0506497 , 0.0326126 , -0.0896391 , -0.00655896, -0.0326126 , -0.145026 , -0.0491922 , -0.0353455 , 0.0783431 , -0.0019358 , 0.0623101 , 0.0133912 , -0.115875 , -0.0466415 , -0.1545 , -0.00275567, 0.0375318 , -0.0204056 , -0.0172173 , -0.0242317 , 0.0539292 , -0.049921 , 0.0969268 , -0.0798006 , 0.0991131 , 0.0695978 , -0.0183104 , -0.0623101 , -0.0286043 , 0.0180371 , 0.0358921 , 0.00019643, 0.0457305 , -0.133365 , 0.01412 , 0.0413579 , 0.0969268 , -0.0140289 , 0.0464593 , 0.0253249 , 0.0317016 , -0.0255071 , 0.0732417 , -0.00674115, -0.0896391 , -0.0808938 , -0.0521073 , -0.0699622 , 0.0459127 , -0.0900035 , -0.0553867 , -0.0787075 , -0.0768856 , -0.0663183 , -0.036803 , -0.0502853 , -0.0419044 , -0.00318838, 0.0302441 , -0.0298797 , 0.0235029 , -0.0269646 , -0.0572087 , -0.0152131 , 0.0870884 , -0.0776143 , -0.0338879 , -0.0156686 , 0.0932829 , -0.0473702 , -0.0242317 , 0.00633122, -0.0225009 , -0.00241406, 0.0590306 , 0.0419044 , -0.131179 , -0.0725129 , -0.0375318 , -0.0495566 , -0.0293331 , -0.0117515 , 0.118061 , -0.0280578 , -0.0597594 , -0.0307907 , -0.0787075 , 0.0932829 , 0.0007914 , -0.00583018, -0.0448195 , 0.0721485 , -0.0133001 , -0.048099 , 0.0757924 , -0.0378962 , 0.0212255 , 0.133365 , -0.120248 , -0.123891 , 0.0302441 , 0.0852664 , 0.0228653 , 0.0338879 , -0.00956515, 0.0373496 , 0.00637676, -0.0218632 , -0.00375774, -0.0827157 , 0.0208611 , 0.0205878 , -0.0779787 , -0.0258714 , 0.015122 , -0.0717841 , 0.0539292 , -0.0510141 , -0.0271468 , 0.0253249 , -0.0575731 , -0.00285816, -0.0991131 , -0.0564799 , 0.0397181 , -0.0143022 , 0.00705999, -0.0765212 , -0.0275112 , 0.0147577 , 0.0275112 , 0.0413579 , -0.0954693 , 0.0648608 , 0.0630389 , 0.0223187 , 0.0324304 , 0.0163974 , -0.0666827 , 0.0827157 , -0.00897302, -0.0426332 , 0.103486 , -0.0110227 , -0.00040424, -0.0232296 , 0.032066 , 0.0524717 , -0.0816226 , -0.01412 , -0.0502853 , -0.141382 , -0.126078 , 0.0655896 , -0.0568443 , -0.0287865 , 0.00557967, 0.0262358 , 0.0213166 , 0.0798006 , -0.068869 , 0.011296 , -0.0561155 , 0.0173084 , -0.0805294 , -0.0134823 , -0.0166707 , 0.0184015 , -0.0262358 , 0.108587 , 0.0291509 , 0.0608525 , -0.0954693 , 0.0885459 , -0.0586662 , 0.0318838 , -0.052836 , -0.00348445, -0.0112049 , -0.0174906 , 0.105672 , 0.0256892 , 0.0841733 , -0.0608525 , 0.0342523 , 0.031155 , -0.0473702 , -0.0406291 , 0.0209522 , 0.137009 , 0.0502853 , 0.0417223 , -0.0226831 , -0.0187659 , 0.0190392 , 0.00696889, 0.00017792, 0.0491922 , 0.0823513 , -0.0422688 , -0.0612169 , -0.0175816 , -0.0233207 , 0.102757 , -0.00651341, -0.0947405 , -0.091461 , -0.111502 , -0.110045 , -0.0347989 , -0.0338879 , 0.0119337 , 0.00924631, -0.0477346 , -0.0604882 , -0.0583018 , -0.0732417 , 0.0776143 , -0.0823513 , 0.0228653 , -0.096198 , -0.0816226 , 0.0510141 , 0.104215 , -0.0189481 , 0.0081987 , -0.00915521, 0.153771 , 0.0557511 , -0.0881815 , -0.0315194 , -0.0124802 , 0.0191303 , 0.00674115, 0.00997508, 0.114417 , 0.00126397, 0.0159419 , -0.0502853 , 0.0900035 , -0.00300619, 0.00112732, -0.0119337 , -0.0267824 , -0.0459127 , -0.00660451, 0.00154864, -0.0286043 , 0.0260536 , -0.0355277 , -0.0366208 , -0.00457761], dtype=float32) >>> model['tables'] array([-0.0666752 , -0.0253918 , 0.0521655 , 0.078421 , -0.0652933 , -0.0357559 , -0.00747073, -0.00747073, -0.0380014 , 0.0380014 , 0.0100617 , -0.105022 , 0.131278 , -0.00032792, -0.00095543, 0.036274 , 0.0608022 , -0.0114868 , 0.042147 , -0.121604 , 0.152006 , 0.0518201 , -0.083603 , 0.0132141 , -0.00470699, 0.083603 , -0.0684025 , -0.0123505 , -0.0407651 , -0.0283283 , -0.0253918 , 0.0279828 , -0.00267737, 0.0424925 , -0.0518201 , 0.00300125, -0.0594203 , 0.0153733 , 0.0152006 , -0.0549293 , 0.0269464 , -0.0159779 , 0.0250464 , -0.0147687 , 0.144405 , -0.057693 , -0.0753118 , 0.0711662 , 0.0159779 , 0.0452562 , -0.0300556 , 0.00148983, 0.0211599 , -0.0860213 , -0.100185 , 0.0293647 , 0.0746209 , -0.0787665 , -0.0298829 , -0.0120913 , -0.0753118 , -0.0107095 , -0.112622 , -0.062875 , 0.0462926 , -0.00842076, -0.0052036 , -0.0456017 , 0.00068014, -0.0825666 , 0.160988 , -0.019778 , 0.078421 , 0.0456017 , -0.0418015 , -0.00466381, -0.0309193 , 0.0405924 , 0.0449107 , -0.0274646 , 0.0333376 , -0.125059 , -0.0405924 , 0.057693 , 0.0718572 , 0.0511291 , -0.0437016 , -0.00665024, 0.0694389 , -0.0290192 , 0.0898215 , -0.0133005 , -0.0604567 , -0.0304011 , -0.0424925 , -0.0511291 , 0.0666752 , -0.0974217 , -0.0276374 , -0.0735845 , 0.018828 , -0.0374832 , 0.0326466 , -0.0535474 , -0.0487109 , 0.0183961 , -0.0326466 , -0.0390378 , 0.0449107 , 0.0257373 , -0.0127823 , -0.0274646 , 0.0718572 , -0.0639114 , -0.0312648 , -0.0538929 , 0.0514746 , -0.0552747 , 0.0153733 , 0.0117459 , -0.0476745 , -0.0195189 , 0.0404197 , -0.0773846 , -0.0449107 , 0.0228008 , -0.0666752 , 0.0166688 , 0.0456017 , 0.0096299 , 0.0694389 , -0.0760028 , 0.0549293 , 0.0271192 , -0.0297102 , 0.104331 , 0.0179643 , -0.0808393 , -0.0514746 , 0.042147 , -0.0309193 , -0.0431834 , 0.0711662 , -0.0583839 , 0.0153733 , 0.0798029 , -0.0215917 , -0.0891305 , -0.017187 , 0.116768 , -0.026601 , 0.0597658 , -0.0385196 , 0.00528997, 0.02401 , 0.00552747, -0.0419743 , -0.0378287 , -0.073239 , -0.0905124 , -0.0566566 , -0.0257373 , 0.0500927 , -0.0715117 , 0.0632205 , -0.0198644 , -0.0044263 , 0.0201235 , -0.0241827 , -0.0849849 , -0.0880941 , -0.0549293 , -0.0241827 , 0.00157619, -0.0286738 , -0.0521655 , -0.029192 , 0.00326035, 0.0514746 , 0.0234918 , -0.0801484 , -0.0190871 , 0.0500927 , 0.0459471 , 0.0340285 , -0.0333376 , -0.0248736 , 0.0545838 , 0.00375696, -0.0715117 , 0.0746209 , -0.0690934 , -0.0742754 , 0.0146824 , 0.0247009 , 0.0449107 , -0.00954353, -0.0773846 , 0.0039081 , -0.105022 , -0.0412833 , 0.0877487 , -0.00446948, -0.0201235 , 0.00673661, 0.0202962 , 0.0780756 , 0.0190007 , -0.0870577 , 0.0666752 , -0.0338558 , 0.00099322, -0.0870577 , 0.0333376 , 0.0418015 , 0.063566 , -0.0618386 , 0.145096 , -0.0257373 , 0.0231463 , -0.094658 , 0.0361013 , -0.0918943 , -0.026601 , -0.0532019 , 0.0177916 , -0.0770392 , 0.0424925 , 0.078421 , -0.106404 , 0.0364468 , -0.0808393 , 0.057693 , -0.0213326 , -0.0430107 , -0.11124 , 0.0469835 , 0.0690934 , 0.0614932 , 0.0229736 , 0.0241827 , -0.02591 , 0.0476745 , -0.0345467 , -0.110549 , -0.0154597 , 0.0753118 , 0.0704753 , -0.178261 , -0.0295374 , 0.00072332, 0.0722026 , 0.00630478, -0.0715117 , -0.105713 , -0.156151 , -0.0552747 , -0.012955 , -0.0247009 , 0.0804938 , -0.0154597 , -0.0431834 , -0.0746209 , 0.0229736 , -0.0877487 , 0.0822212 , 0.0118322 , 0.0715117 , 0.0331648 , -0.0260828 , 0.0107095 , 0.120223 , -0.0794574 , 0.0528565 , 0.0397287 , 0.131968 , 0.023319 , -0.0646024 , 0.0115731 , -0.00582976, -0.0288465 , -0.00673661, -0.0106663 , 0.0428379 , 0.0494018 , -0.0307466 , -0.0532019 , 0.0925852 , -0.0400742 , 0.0559657 , 0.00032657, 0.0466381 , -0.0504382 , -0.0140778 , 0.0314375 , -0.0326466 , 0.100876 , -0.0044263 , -0.033683 , -0.0183098 ], dtype=float32) >>> >>> model.most_similar(positive=['woman','king'], topn=3) [('man', 0.6628608107566833), ('queen', 0.6438565254211426), ('girl', 0.6136073470115662)] >>> model.most_similar(positive=['mother','daughter'],negative=['father'], topn=3) [('niece', 0.7726002931594849), ('granddaughter', 0.7407786846160889), ('daughters', 0.7102084755897522)] >>> model.most_similar(positive=['woman','president'],negative=['man'], topn=5) [('President', 0.6533178687095642), ('executive', 0.5394407510757446), ('chairman', 0.48231008648872375), ('director', 0.47442811727523804), ('presidents', 0.4721617102622986)] >>> model.most_similar(positive=['burger','beef'],negative=['cheese'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'burger' not present in vocabulary" >>> model.most_similar(positive=['hamburger','beef'],negative=['cheese'], topn=5) [('hamburgers', 0.5429103374481201), ('meat', 0.5150913000106812), ('chicken', 0.48434528708457947), ('Beef', 0.47776034474372864), ('steaks', 0.45980146527290344)] >>> >>> model.most_similar(positive=['cheeseburger','beef'],negative=['cheese'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'cheeseburger' not present in vocabulary" >>> model.most_similar(positive=['taco','beef'],negative=['cheese'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'taco' not present in vocabulary" >>> model.most_similar(positive=['tacos','beef'],negative=['cheese'], topn=5) >>> model.most_similar(positive=['tacos','beef'],negative=['cheese'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'tacos' not present in vocabulary" >>> model.most_similar(positive=['piano','notes'],negative=['drum'], topn=5) [('harpsichord', 0.4201466739177704), ('sonata', 0.41979527473449707), ('clarinet', 0.41829079389572144), ('violin', 0.41756993532180786), ('Dohnanyi', 0.4035533666610718)] >>> model.most_similar(positive=['cow','goat'],negative=['milk'], topn=5) [('pig', 0.5785052180290222), ('sheep', 0.5515832901000977), ('rabbit', 0.550534725189209), ('bovines', 0.542060136795044), ('buffalo', 0.5282479524612427)] >>> model.most_similar(positive=['buffalo','swordfish'],negative=['horn'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'swordfish' not present in vocabulary" >>> model.most_similar(positive=['buffalo','shark'],negative=['horn'], topn=5) >>> model.most_similar(positive=['buffalo','shark'],negative=['horn'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'shark' not present in vocabulary" >>> model.most_similar(positive=['buffalo','ram'],negative=['horn'], topn=5) [('cows', 0.4445011615753174), ('buffaloes', 0.44286325573921204), ('sheep', 0.4398384690284729), ('bison', 0.4376237094402313), ('cattle', 0.42312443256378174)] >>> model.most_similar(positive=['military','woman'],negative=['man'], topn=5) [('civilian', 0.5569493174552917), ('Military', 0.552918016910553), ('naval', 0.5446915030479431), ('army', 0.5294965505599976), ('soldiers', 0.510556697845459)] >>> model.most_similar(positive=['USA'],negative=['Arizona'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'USA' not present in vocabulary" >>> model.most_similar(positive=['usa'],negative=['Arizona'], topn=5) Traceback (most recent call last): File "", line 1, in File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 841, in most_similar mean = self.get_mean_vector(keys, weight, pre_normalize=True, post_normalize=True, ignore_missing=False) File "/Users/sandiway/opt/anaconda3/lib/python3.9/site-packages/gensim/models/keyedvectors.py", line 518, in get_mean_vector raise KeyError(f"Key '{key}' not present in vocabulary") KeyError: "Key 'usa' not present in vocabulary" >>> model.most_similar(positive=['France'],negative=['Arizona'], topn=5) >>> model.most_similar(positive=['France'],negative=['Arizona'], topn=5) [('French', 0.5087677240371704), ('Paris', 0.46383631229400635), ('Guillaume', 0.433054655790329), ('Belgium', 0.4192690849304199), ('Paix', 0.40919816493988037)] >>>