Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Created November 14, 2019 02:05
Show Gist options
  • Save bowbowbow/203a47b957cb7c019ccdce940f54f12a to your computer and use it in GitHub Desktop.
Save bowbowbow/203a47b957cb7c019ccdce940f54f12a to your computer and use it in GitHub Desktop.
def load_glove(glove_path):
word2vec = {}
with open(glove_path, 'r') as f:
for line in f:
split_line = line.split()
word = split_line[0]
embedding = np.array([float(val) for val in split_line[1:]])
word2vec[word] = embedding
print("Done.",len(word2vec)," words loaded!")
return word2vec
word2vec = load_glove('../data/glove.6B.300d.txt')
print(word2vec['apple'])
@bowbowbow
Copy link
Author

Done. 400000 words loaded!
[-0.20842 -0.019668 0.063981 -0.71403 -0.21181 -0.59283
-0.15316 0.044217 0.63289 -0.84821 -0.21129 -0.19763
0.19029 -0.56226 0.27126 0.23782 -0.5189 -0.24518
0.035243 0.096833 0.24898 0.71279 0.038279 -0.10514
-0.4779 -0.39515 -0.27194 -0.44428 0.06113 -0.2318
-0.35901 -0.18239 0.035507 -0.087719 -1.0816 -0.42521
0.003224 -0.45991 -0.043462 -0.39031 0.519 0.21139
-0.25527 1.1805 -0.19041 -0.12156 0.034186 -0.062316
0.14421 -0.53366 0.47425 -0.4471 0.58047 0.43578
0.1321 -0.095712 -0.37182 -0.013837 0.20601 -0.10099
0.10685 -0.33723 0.10986 0.34796 -0.099839 0.36942
-0.52917 0.12407 -0.46127 -0.38483 -0.10114 -0.17634
0.37574 0.16377 -0.2198 -0.26841 0.84706 -0.35619
-0.083992 -0.20276 -0.56542 0.19112 -0.14134 -0.7812
0.69188 -0.083628 -0.54293 0.16437 0.037606 -0.68896
-0.68711 -0.13367 -0.4779 0.20125 0.085122 -0.063865
-0.17104 -0.32432 -0.17623 -0.514 -0.50289 0.23204
-0.11324 -1.064 -0.035359 -0.5068 -0.27118 -0.16621
-0.63016 0.054252 -0.048178 0.29282 -0.030666 -0.24645
-0.27084 -0.42563 -0.39171 0.18428 -0.017772 -0.35334
-0.49075 -0.90782 0.13872 -0.76521 -0.46318 -0.32124
-0.086228 1.0448 -0.39919 0.69478 -0.10377 0.86715
0.22742 0.4384 0.085767 -0.22846 0.4309 0.064187
-0.027926 -0.093056 0.65188 0.59143 -0.3376 -0.37732
0.0052212 1.1193 -0.23845 -0.16029 0.42877 -0.16228
-0.12202 -0.1061 0.015761 0.022745 -0.17734 -0.091711
-0.29158 0.19034 -0.35168 0.27563 -0.20577 0.11472
-0.34126 -0.0065915 0.14896 -0.026762 0.0019373 0.53279
-0.76088 0.063085 -0.72089 -0.04128 -0.96164 0.020769
0.16123 -0.34342 0.69713 -0.16018 -0.11701 -0.070239
-0.30774 0.39741 0.39994 -0.678 0.57684 -0.48099
0.59317 -0.42262 0.28613 -0.26203 0.052727 0.61659
-0.36801 -0.28429 -0.40054 -0.30055 -0.27444 -0.045729
-0.56105 0.24176 0.86631 -0.83715 0.13562 0.26196
-0.43055 0.34558 0.059441 0.61845 0.11837 -0.019168
0.47697 -0.32465 -0.15463 -0.23556 -0.64263 -0.092156
-0.19622 0.40666 0.18009 0.094309 0.046917 0.26369
-0.50727 0.37491 -0.66773 0.35095 -0.033835 0.30534
0.23166 0.023526 -0.68365 0.26078 -0.22526 -0.2656
0.59967 0.2598 0.36248 0.15564 -0.45549 0.11153
-0.33287 0.081364 -0.36989 -0.25543 -1.1628 -0.14622
-0.032971 -0.55619 0.47717 -0.29021 0.42688 1.2397
-0.81391 0.21084 -0.25426 -0.08684 -0.078412 0.26035
0.3281 -0.23777 0.05138 -0.030247 -0.15669 0.057147
0.33902 0.12795 -0.21468 -0.75208 0.41422 0.0062719
-0.52904 0.92193 -0.42179 -0.69638 0.074115 0.19071
-1.2031 -0.081333 -0.4914 -0.22159 -0.29876 0.30094
0.018634 0.18786 -0.45429 -0.29296 0.3695 -0.24218
-0.11803 0.071775 0.44026 -0.59978 0.45354 0.17854
-0.17155 0.018811 -0.62354 -0.014163 0.16799 -0.064392 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment