-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_w2v_model.py
39 lines (30 loc) · 962 Bytes
/
create_w2v_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
"""Reads a tokenized file to train an output Word2Vec model."""
import argparse
import multiprocessing
from gensim.models import Word2Vec, FastText
from gensim.models.word2vec import LineSentence
def _build_w2v_model(sourcefile: str):
source = LineSentence(sourcefile)
model = Word2Vec(
source, window=15, min_count=10, workers=multiprocessing.cpu_count()
)
return model
def main(args: argparse.Namespace) -> None:
model = _build_w2v_model(args.datasource)
model.save(args.modelfile)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--datasource",
type=str,
default="data/en.tok",
help="link to tokenized data source file",
)
parser.add_argument(
"--modelfile",
type=str,
default="data/model.w2v",
help="output model file name",
)
main(parser.parse_args())