Last active
December 7, 2019 03:09
-
-
Save eumesy/1912f9967ffefb4911444d1419cde2ac to your computer and use it in GitHub Desktop.
This file contains 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
def loadGloveModel(gloveFile): | |
# via https://stackoverflow.com/a/38230349 | |
# output: dict (word -> embedding) | |
print("Loading Glove Model", file=sys.stderr) | |
model = {} | |
for i, line in enumerate(gloveFile, start=1): | |
if i % 100000 == 0: | |
print("load {} data".format(i), file=sys.stderr) | |
splitLine = line.split(' ') | |
word = splitLine[0] | |
embedding = np.array([float(val) for val in splitLine[1:]]) | |
model[word] = embedding | |
print("Done.",len(model)," words loaded!", file=sys.stderr) | |
return model | |
def loadGloveVectors(gloveFile): | |
# input: file | |
# output: numpy ndarray (n, dim) | |
return np.array([np.array(line.split(' ')[1:]).astype(float) | |
for line in tqdm(gloveFile)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
load words