Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
strategy_embedding
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
strategy_embedding
Commits
89d9b293
Commit
89d9b293
authored
Oct 14, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save model
parent
22c130e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
word_to_vec.py
word_vector/word_to_vec.py
+22
-3
No files found.
word_vector/word_to_vec.py
View file @
89d9b293
import
os
import
os
from
gensim.models
import
Word2V
ec
from
gensim.models
import
word2v
ec
base_dir
=
os
.
getcwd
()
base_dir
=
os
.
getcwd
()
print
(
"base_dir: "
+
base_dir
)
print
(
"base_dir: "
+
base_dir
)
...
@@ -8,5 +8,24 @@ model_dir = os.path.join(base_dir, "_models")
...
@@ -8,5 +8,24 @@ model_dir = os.path.join(base_dir, "_models")
data_dir
=
os
.
path
.
join
(
base_dir
,
"_data"
)
data_dir
=
os
.
path
.
join
(
base_dir
,
"_data"
)
def
w2v_train
():
class
W2vSentences
:
pass
def
__init__
(
self
,
f_name
):
self
.
f_name
=
f_name
def
__iter__
(
self
):
for
line
in
open
(
self
.
f_name
,
"r"
):
yield
line
.
split
()
def
w2v_train
(
f_name
,
model_output_name
):
input_file
=
os
.
path
.
join
(
data_dir
,
f_name
)
print
(
"input: "
+
input_file
)
sentences
=
W2vSentences
(
input_file
)
w2v_model
=
word2vec
.
Word2Vec
(
sentences
,
min_count
=
2
,
workers
=
2
,
size
=
100
,
window
=
10
)
model_path
=
os
.
path
.
join
(
model_dir
,
model_output_name
)
print
(
"output: "
+
model_path
)
w2v_model
.
save
(
model_path
)
if
__name__
==
"__main__"
:
w2v_train
(
"dispose_problem.txt"
,
"w2v_model"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment