Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
5c886ced
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看板
提交
5c886ced
编写于
11月 08, 2017
作者:
W
wangmeng28
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement train data generation and preprocess for chinese poetry
上级
fb18316b
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
5128 addition
and
1 deletion
+5128
-1
generate_chinese_poetry/data/dict.txt
generate_chinese_poetry/data/dict.txt
+5037
-0
generate_chinese_poetry/data/download.sh
generate_chinese_poetry/data/download.sh
+11
-0
generate_chinese_poetry/preprocess.py
generate_chinese_poetry/preprocess.py
+79
-0
generate_chinese_poetry/train.py
generate_chinese_poetry/train.py
+1
-1
未找到文件。
generate_chinese_poetry/data/dict.txt
0 → 100644
浏览文件 @
5c886ced
此差异已折叠。
点击以展开。
generate_chinese_poetry/data/download.sh
0 → 100755
浏览文件 @
5c886ced
#!/bin/bash
git clone https://github.com/chinese-poetry/chinese-poetry.git
if
[
!
-d
raw
]
then
mkdir
raw
fi
mv
chinese-poetry/json/poet.tang.
*
raw/
rm
-rf
chinese-poetry
generate_chinese_poetry/preprocess.py
0 → 100755
浏览文件 @
5c886ced
# -*- coding: utf-8 -*-
import
os
import
io
import
re
import
json
import
click
import
collections
def
build_vocabulary
(
dataset
,
cutoff
=
0
):
dictionary
=
collections
.
defaultdict
(
int
)
for
data
in
dataset
:
for
sent
in
data
[
2
]:
for
char
in
sent
:
dictionary
[
char
]
+=
1
dictionary
=
filter
(
lambda
x
:
x
[
1
]
>=
cutoff
,
dictionary
.
items
())
dictionary
=
sorted
(
dictionary
,
key
=
lambda
x
:
(
-
x
[
1
],
x
[
0
]))
vocab
,
_
=
list
(
zip
(
*
dictionary
))
return
(
u
"<unk>"
,
u
"<s>"
,
u
"<e>"
)
+
vocab
@
click
.
command
(
"preprocess"
)
@
click
.
option
(
"--datadir"
,
type
=
str
,
help
=
"Path to raw data"
)
@
click
.
option
(
"--outfile"
,
type
=
str
,
help
=
"Path to save the training data"
)
@
click
.
option
(
"--dictfile"
,
type
=
str
,
help
=
"Path to save the dictionary file"
)
def
preprocess
(
datadir
,
outfile
,
dictfile
):
dataset
=
[]
note_pattern1
=
re
.
compile
(
u
"(.*?)"
,
re
.
U
)
note_pattern2
=
re
.
compile
(
u
"〖.*?〗"
,
re
.
U
)
note_pattern3
=
re
.
compile
(
u
"-.*?-。?"
,
re
.
U
)
note_pattern4
=
re
.
compile
(
u
"(.*$"
,
re
.
U
)
note_pattern5
=
re
.
compile
(
u
"。。.*)$"
,
re
.
U
)
note_pattern6
=
re
.
compile
(
u
"。。"
,
re
.
U
)
note_pattern7
=
re
.
compile
(
u
"[《》「」\[\]]"
,
re
.
U
)
print
(
"Loading raw data..."
)
for
fn
in
os
.
listdir
(
datadir
):
with
io
.
open
(
os
.
path
.
join
(
datadir
,
fn
),
"r"
,
encoding
=
"utf8"
)
as
f
:
for
data
in
json
.
load
(
f
):
title
=
data
[
'title'
]
author
=
data
[
'author'
]
p
=
""
.
join
(
data
[
'paragraphs'
])
p
=
""
.
join
(
p
.
split
())
p
=
note_pattern1
.
sub
(
u
""
,
p
)
p
=
note_pattern2
.
sub
(
u
""
,
p
)
p
=
note_pattern3
.
sub
(
u
""
,
p
)
p
=
note_pattern4
.
sub
(
u
""
,
p
)
p
=
note_pattern5
.
sub
(
u
"。"
,
p
)
p
=
note_pattern6
.
sub
(
u
"。"
,
p
)
p
=
note_pattern7
.
sub
(
u
""
,
p
)
if
(
p
==
u
""
or
u
"{"
in
p
or
u
"}"
in
p
or
u
"{"
in
p
or
u
"}"
in
p
or
u
"、"
in
p
or
u
":"
in
p
or
u
";"
in
p
or
u
"!"
in
p
or
u
"?"
in
p
or
u
"●"
in
p
or
u
"□"
in
p
or
u
"囗"
in
p
or
u
")"
in
p
):
continue
paragraphs
=
p
.
split
(
u
"。"
)
paragraphs
=
filter
(
lambda
x
:
len
(
x
),
paragraphs
)
if
len
(
paragraphs
)
>
1
:
dataset
.
append
((
title
,
author
,
paragraphs
))
print
(
"Finished..."
)
print
(
"Constructing vocabularies..."
)
vocab
=
build_vocabulary
(
dataset
,
cutoff
=
10
)
with
io
.
open
(
dictfile
,
"w"
,
encoding
=
"utf8"
)
as
f
:
for
v
in
vocab
:
f
.
write
(
v
+
"
\n
"
)
print
(
"Finished..."
)
print
(
"Writing processed data..."
)
with
io
.
open
(
outfile
,
"w"
,
encoding
=
"utf8"
)
as
f
:
for
data
in
dataset
:
title
=
data
[
0
]
author
=
data
[
1
]
paragraphs
=
"."
.
join
(
data
[
2
])
f
.
write
(
"
\t
"
.
join
((
title
,
author
,
paragraphs
))
+
"
\n
"
)
print
(
"Finished..."
)
if
__name__
==
"__main__"
:
preprocess
()
generate_chinese_poetry/train.py
浏览文件 @
5c886ced
...
...
@@ -44,7 +44,7 @@ def load_initial_model(model_path, parameters):
@
click
.
option
(
"--decoder_depth"
,
default
=
3
,
help
=
"The number of stacked LSTM layers in
en
coder."
)
help
=
"The number of stacked LSTM layers in
de
coder."
)
@
click
.
option
(
"--train_data_path"
,
required
=
True
,
help
=
"The path of trainning data."
)
@
click
.
option
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录