Skip to content
Snippets Groups Projects
Commit fb277e97 authored by Caron Olivier's avatar Caron Olivier
Browse files

save models as text

parent f6728ceb
Branches main
No related tags found
No related merge requests found
......@@ -15,8 +15,18 @@ from gensim.models.word2vec import Word2Vec
import sys
import gensim.downloader as api
import sys
import csv
def save_model_as_text(filelocation, model):
with open(filelocation, "w") as f:
f.write(f"{len(model.wv)} {model.vector_size}\n")
for word in model.wv.key_to_index.keys():
f.write(word)
for value in model.wv[word]:
f.write(f" {value:.15f}")
f.write("\n")
def main():
......@@ -30,7 +40,9 @@ def main():
corpus = api.load(sys.argv[1])
model = Word2Vec(corpus)
model.save(f"./models/{sys.argv[1]}")
save_model_as_text(f"./models/vectors_{sys.argv[1]}.txt", model)
print(f"INFO :: model Trained {sys.argv[1]} saved in ./models")
print(f"INFO :: word vectors vectors_{sys.argv[1]}.txt saved in ./models")
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment