Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
0faa6fb3
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0faa6fb3
编写于
4月 12, 2019
作者:
Z
zhangwenhui03
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix train.py dict
上级
93e202ad
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
14 deletion
+13
-14
PaddleRec/word2vec/README.md
PaddleRec/word2vec/README.md
+2
-2
PaddleRec/word2vec/preprocess.py
PaddleRec/word2vec/preprocess.py
+6
-0
PaddleRec/word2vec/reader.py
PaddleRec/word2vec/reader.py
+5
-12
未找到文件。
PaddleRec/word2vec/README.md
浏览文件 @
0faa6fb3
...
@@ -72,7 +72,7 @@ nine 250430
...
@@ -72,7 +72,7 @@ nine 250430
python preprocess.py
--build_dict
--build_dict_corpus_dir
data/text/
--dict_path
data/test_build_dict
python preprocess.py
--build_dict
--build_dict_corpus_dir
data/text/
--dict_path
data/test_build_dict
```
```
第二步根据词典将文本转成id, 同时进行downsample,按照概率过滤常见词。
第二步根据词典将文本转成id, 同时进行downsample,按照概率过滤常见词
, 同时生成word和id映射的文件,文件名为词典+"_word_to_id_"
。
```
bash
```
bash
python preprocess.py
--filter_corpus
--dict_path
data/test_build_dict
--input_corpus_dir
data/text/
--output_corpus_dir
data/convert_text8
--min_count
5
--downsample
0.001
python preprocess.py
--filter_corpus
--dict_path
data/test_build_dict
--input_corpus_dir
data/text/
--output_corpus_dir
data/convert_text8
--min_count
5
--downsample
0.001
...
@@ -107,7 +107,7 @@ wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar
...
@@ -107,7 +107,7 @@ wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar
wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
```
```
预测命令,注意词典名称需要加后缀"_word_to_id_", 此文件是
训练
阶段生成的。
预测命令,注意词典名称需要加后缀"_word_to_id_", 此文件是
预处理
阶段生成的。
```
bash
```
bash
python infer.py
--infer_epoch
--test_dir
data/test_mid_dir/
--dict_path
data/test_build_dict_word_to_id_
--batch_size
20000
--model_dir
v1_cpu5_b100_lr1dir/
--start_index
0
python infer.py
--infer_epoch
--test_dir
data/test_mid_dir/
--dict_path
data/test_build_dict_word_to_id_
--batch_size
20000
--model_dir
v1_cpu5_b100_lr1dir/
--start_index
0
```
```
PaddleRec/word2vec/preprocess.py
浏览文件 @
0faa6fb3
...
@@ -100,6 +100,12 @@ def filter_corpus(args):
...
@@ -100,6 +100,12 @@ def filter_corpus(args):
id_counts
.
append
(
count
)
id_counts
.
append
(
count
)
word_all_count
+=
count
word_all_count
+=
count
#write word2id file
print
(
"write word2id file to : "
+
dict_path
+
"_word_to_id_"
)
with
io
.
open
(
args
.
dict_path
+
"_word_to_id_"
,
'w+'
,
encoding
=
'utf-8'
)
as
fid
:
for
k
,
v
in
word_to_id_
.
items
():
fid
.
write
(
k
+
" "
+
str
(
v
)
+
'
\n
'
)
#filter corpus and convert id
#filter corpus and convert id
if
not
os
.
path
.
exists
(
args
.
output_corpus_dir
):
if
not
os
.
path
.
exists
(
args
.
output_corpus_dir
):
os
.
makedirs
(
args
.
output_corpus_dir
)
os
.
makedirs
(
args
.
output_corpus_dir
)
...
...
PaddleRec/word2vec/reader.py
浏览文件 @
0faa6fb3
...
@@ -41,9 +41,6 @@ class Word2VecReader(object):
...
@@ -41,9 +41,6 @@ class Word2VecReader(object):
self
.
window_size_
=
window_size
self
.
window_size_
=
window_size
self
.
data_path_
=
data_path
self
.
data_path_
=
data_path
self
.
filelist
=
filelist
self
.
filelist
=
filelist
self
.
word_to_id_
=
dict
()
self
.
id_to_word
=
dict
()
self
.
word_count
=
dict
()
self
.
trainer_id
=
trainer_id
self
.
trainer_id
=
trainer_id
self
.
trainer_num
=
trainer_num
self
.
trainer_num
=
trainer_num
...
@@ -52,24 +49,20 @@ class Word2VecReader(object):
...
@@ -52,24 +49,20 @@ class Word2VecReader(object):
word_id
=
0
word_id
=
0
with
io
.
open
(
dict_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
with
io
.
open
(
dict_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
ll
=
0
for
line
in
f
:
for
line
in
f
:
ll
+=
1
if
ll
%
100000
==
1
:
print
(
ll
)
word
,
count
=
line
.
split
()[
0
],
int
(
line
.
split
()[
1
])
word
,
count
=
line
.
split
()[
0
],
int
(
line
.
split
()[
1
])
self
.
word_count
[
word
]
=
count
self
.
word_to_id_
[
word
]
=
word_id
self
.
id_to_word
[
word_id
]
=
word
#build id to word dict
word_id
+=
1
word_id
+=
1
id_counts
.
append
(
count
)
id_counts
.
append
(
count
)
word_all_count
+=
count
word_all_count
+=
count
self
.
word_all_count
=
word_all_count
self
.
word_all_count
=
word_all_count
self
.
corpus_size_
=
word_all_count
self
.
corpus_size_
=
word_all_count
self
.
dict_size
=
len
(
self
.
word_to_id_
)
self
.
dict_size
=
len
(
id_counts
)
self
.
id_counts_
=
id_counts
self
.
id_counts_
=
id_counts
#write word2id file
print
(
"write word2id file to : "
+
dict_path
+
"_word_to_id_"
)
with
io
.
open
(
dict_path
+
"_word_to_id_"
,
'w+'
,
encoding
=
'utf-8'
)
as
f6
:
for
k
,
v
in
self
.
word_to_id_
.
items
():
f6
.
write
(
k
+
" "
+
str
(
v
)
+
'
\n
'
)
print
(
"corpus_size:"
,
self
.
corpus_size_
)
print
(
"corpus_size:"
,
self
.
corpus_size_
)
self
.
id_frequencys
=
[
self
.
id_frequencys
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录