Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
7862c3a8
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看板
未验证
提交
7862c3a8
编写于
1月 28, 2021
作者:
J
Jiaqi Liu
提交者:
GitHub
1月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CoupletDataset (#5247)
* move coupletdataset to paddlenlp.dataset * move coupletdataset to paddlenlp.dataset
上级
a911e2d5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
49 deletion
+69
-49
PaddleNLP/examples/text_generation/couplet/data.py
PaddleNLP/examples/text_generation/couplet/data.py
+1
-48
PaddleNLP/paddlenlp/datasets/__init__.py
PaddleNLP/paddlenlp/datasets/__init__.py
+2
-1
PaddleNLP/paddlenlp/datasets/couplet.py
PaddleNLP/paddlenlp/datasets/couplet.py
+66
-0
未找到文件。
PaddleNLP/examples/text_generation/couplet/data.py
浏览文件 @
7862c3a8
...
...
@@ -21,7 +21,7 @@ import numpy as np
import
paddle
from
paddlenlp.data
import
Vocab
,
Pad
from
paddlenlp.data
import
SamplerHelper
from
paddlenlp.datasets
import
Translation
Dataset
from
paddlenlp.datasets
import
Couplet
Dataset
def
create_train_loader
(
batch_size
=
128
):
...
...
@@ -65,50 +65,3 @@ def prepare_input(insts, pad_id):
[
inst
[
1
]
for
inst
in
insts
])
tgt_mask
=
(
tgt
[:,
:
-
1
]
!=
pad_id
).
astype
(
paddle
.
get_default_dtype
())
return
src
,
src_length
,
tgt
[:,
:
-
1
],
tgt
[:,
1
:,
np
.
newaxis
],
tgt_mask
class
CoupletDataset
(
TranslationDataset
):
URL
=
"https://paddlenlp.bj.bcebos.com/datasets/couplet.tar.gz"
SPLITS
=
{
'train'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"train_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"train_tgt.tsv"
),
"ad137385ad5e264ac4a54fe8c95d1583"
,
"daf4dd79dbf26040696eee0d645ef5ad"
),
'dev'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"dev_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"dev_tgt.tsv"
),
"65bf9e72fa8fdf0482751c1fd6b6833c"
,
"3bc3b300b19d170923edfa8491352951"
),
'test'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"test_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"test_tgt.tsv"
),
"f0a7366dfa0acac884b9f4901aac2cc1"
,
"56664bff3f2edfd7a751a55a689f90c2"
)
}
VOCAB_INFO
=
(
os
.
path
.
join
(
"couplet"
,
"vocab.txt"
),
os
.
path
.
join
(
"couplet"
,
"vocab.txt"
),
"0bea1445c7c7fb659b856bb07e54a604"
,
"0bea1445c7c7fb659b856bb07e54a604"
)
UNK_TOKEN
=
'<unk>'
BOS_TOKEN
=
'<s>'
EOS_TOKEN
=
'</s>'
MD5
=
'5c0dcde8eec6a517492227041c2e2d54'
def
__init__
(
self
,
mode
=
'train'
,
root
=
None
):
data_select
=
(
'train'
,
'dev'
,
'test'
)
if
mode
not
in
data_select
:
raise
TypeError
(
'`train`, `dev` or `test` is supported but `{}` is passed in'
.
format
(
mode
))
# Download and read data
self
.
data
=
self
.
get_data
(
mode
=
mode
,
root
=
root
)
self
.
vocab
,
_
=
self
.
get_vocab
(
root
)
self
.
transform
()
def
transform
(
self
):
eos_id
=
self
.
vocab
[
self
.
EOS_TOKEN
]
bos_id
=
self
.
vocab
[
self
.
BOS_TOKEN
]
self
.
data
=
[(
[
bos_id
]
+
self
.
vocab
.
to_indices
(
data
[
0
].
split
(
"
\x02
"
))
+
[
eos_id
],
[
bos_id
]
+
self
.
vocab
.
to_indices
(
data
[
1
].
split
(
"
\x02
"
))
+
[
eos_id
])
for
data
in
self
.
data
]
PaddleNLP/paddlenlp/datasets/__init__.py
浏览文件 @
7862c3a8
...
...
@@ -24,4 +24,5 @@ from .squad import *
from
.translation
import
*
from
.dureader
import
*
from
.cnndm
import
*
from
.poetry
import
*
\ No newline at end of file
from
.poetry
import
*
from
.couplet
import
*
\ No newline at end of file
PaddleNLP/paddlenlp/datasets/couplet.py
0 → 100644
浏览文件 @
7862c3a8
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
from
paddlenlp.datasets
import
TranslationDataset
__all__
=
[
'CoupletDataset'
]
class
CoupletDataset
(
TranslationDataset
):
URL
=
"https://paddlenlp.bj.bcebos.com/datasets/couplet.tar.gz"
SPLITS
=
{
'train'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"train_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"train_tgt.tsv"
),
"ad137385ad5e264ac4a54fe8c95d1583"
,
"daf4dd79dbf26040696eee0d645ef5ad"
),
'dev'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"dev_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"dev_tgt.tsv"
),
"65bf9e72fa8fdf0482751c1fd6b6833c"
,
"3bc3b300b19d170923edfa8491352951"
),
'test'
:
TranslationDataset
.
META_INFO
(
os
.
path
.
join
(
"couplet"
,
"test_src.tsv"
),
os
.
path
.
join
(
"couplet"
,
"test_tgt.tsv"
),
"f0a7366dfa0acac884b9f4901aac2cc1"
,
"56664bff3f2edfd7a751a55a689f90c2"
)
}
VOCAB_INFO
=
(
os
.
path
.
join
(
"couplet"
,
"vocab.txt"
),
os
.
path
.
join
(
"couplet"
,
"vocab.txt"
),
"0bea1445c7c7fb659b856bb07e54a604"
,
"0bea1445c7c7fb659b856bb07e54a604"
)
UNK_TOKEN
=
'<unk>'
BOS_TOKEN
=
'<s>'
EOS_TOKEN
=
'</s>'
MD5
=
'5c0dcde8eec6a517492227041c2e2d54'
def
__init__
(
self
,
mode
=
'train'
,
root
=
None
):
data_select
=
(
'train'
,
'dev'
,
'test'
)
if
mode
not
in
data_select
:
raise
TypeError
(
'`train`, `dev` or `test` is supported but `{}` is passed in'
.
format
(
mode
))
# Download and read data
self
.
data
=
self
.
get_data
(
mode
=
mode
,
root
=
root
)
self
.
vocab
,
_
=
self
.
get_vocab
(
root
)
self
.
transform
()
def
transform
(
self
):
eos_id
=
self
.
vocab
[
self
.
EOS_TOKEN
]
bos_id
=
self
.
vocab
[
self
.
BOS_TOKEN
]
self
.
data
=
[(
[
bos_id
]
+
self
.
vocab
.
to_indices
(
data
[
0
].
split
(
"
\x02
"
))
+
[
eos_id
],
[
bos_id
]
+
self
.
vocab
.
to_indices
(
data
[
1
].
split
(
"
\x02
"
))
+
[
eos_id
])
for
data
in
self
.
data
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录