Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
60d5b7a0
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看板
提交
60d5b7a0
编写于
12月 17, 2020
作者:
Z
Zeyu Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove useless readme and example
上级
d0d39cc0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
0 addition
and
118 deletion
+0
-118
PaddleNLP/examples/dialogue/README.md
PaddleNLP/examples/dialogue/README.md
+0
-5
PaddleNLP/examples/hapi/train.py
PaddleNLP/examples/hapi/train.py
+0
-53
PaddleNLP/examples/hapi/train_dev.py
PaddleNLP/examples/hapi/train_dev.py
+0
-60
未找到文件。
PaddleNLP/examples/dialogue/README.md
已删除
100644 → 0
浏览文件 @
d0d39cc0
# Dialogue System
## Dialogue General Understanding
## PLATO-2
PaddleNLP/examples/hapi/train.py
已删除
100644 → 0
浏览文件 @
d0d39cc0
from
functools
import
partial
from
paddle.io
import
DistributedBatchSampler
,
DataLoader
from
paddle.static
import
InputSpec
from
paddlenlp.data
import
Stack
,
Tuple
,
Pad
from
paddlenlp.transformers
import
ErnieTokenizer
import
numpy
as
np
import
paddle
import
paddlenlp
def
convert_example
(
example
,
tokenizer
,
max_seq_length
=
128
):
text
,
label
=
example
encoded_inputs
=
tokenizer
.
encode
(
text
,
max_seq_len
=
max_seq_length
)
input_ids
,
segment_ids
=
encoded_inputs
[
"input_ids"
],
encoded_inputs
[
"segment_ids"
]
label
=
np
.
array
([
label
],
dtype
=
"int64"
)
return
input_ids
,
segment_ids
,
label
paddle
.
set_device
(
'gpu'
)
# Dataset prepare
train_ds
=
paddlenlp
.
datasets
.
ChnSentiCorp
.
get_datasets
([
'train'
])
tokenizer
=
ErnieTokenizer
.
from_pretrained
(
'ernie-1.0'
)
model
=
paddlenlp
.
models
.
Ernie
(
'ernie-1.0'
,
task
=
'seq-cls'
,
num_classes
=
2
)
trans_func
=
partial
(
convert_example
,
tokenizer
=
tokenizer
)
train_ds
=
train_ds
.
apply
(
trans_func
)
batchify_fn
=
lambda
samples
,
fn
=
Tuple
(
Pad
(
axis
=
0
,
pad_val
=
tokenizer
.
pad_token_id
),
Pad
(
axis
=
0
,
pad_val
=
tokenizer
.
pad_token_id
),
Stack
(
dtype
=
"int64"
)
):
[
data
for
data
in
fn
(
samples
)]
batch_sampler
=
DistributedBatchSampler
(
train_ds
,
batch_size
=
32
,
shuffle
=
True
)
train_loader
=
DataLoader
(
dataset
=
train_ds
,
batch_sampler
=
batch_sampler
,
collate_fn
=
batchify_fn
,
return_list
=
True
)
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
metric
=
paddle
.
metric
.
Accuracy
()
optimizer
=
paddle
.
optimizer
.
AdamW
(
learning_rate
=
5e-5
,
parameters
=
model
.
parameters
())
inputs
=
[
InputSpec
(
[
None
,
128
],
dtype
=
'int64'
,
name
=
'input_ids'
),
InputSpec
(
[
None
,
128
],
dtype
=
'int64'
,
name
=
'token_type_ids'
)
]
trainer
=
paddle
.
Model
(
model
,
inputs
)
trainer
.
prepare
(
optimizer
,
criterion
,
metric
)
trainer
.
fit
(
train_loader
,
batch_size
=
32
,
epochs
=
3
)
PaddleNLP/examples/hapi/train_dev.py
已删除
100644 → 0
浏览文件 @
d0d39cc0
from
functools
import
partial
from
paddle.io
import
DistributedBatchSampler
,
DataLoader
from
paddle.static
import
InputSpec
from
paddlenlp.data
import
Stack
,
Tuple
,
Pad
from
paddlenlp.transformers
import
ErnieTokenizer
import
numpy
as
np
import
paddle
import
paddlenlp
def
convert_example
(
example
,
tokenizer
,
max_seq_length
=
128
):
text
,
label
=
example
encoded_inputs
=
tokenizer
.
encode
(
text
,
max_seq_len
=
max_seq_length
)
input_ids
,
segment_ids
=
encoded_inputs
[
"input_ids"
],
encoded_inputs
[
"segment_ids"
]
label
=
np
.
array
([
label
],
dtype
=
"int64"
)
return
input_ids
,
segment_ids
,
label
paddle
.
set_device
(
'gpu'
)
train_ds
,
dev_ds
=
paddlenlp
.
datasets
.
ChnSentiCorp
.
get_datasets
(
[
'train'
,
'dev'
])
label_list
=
train_ds
.
get_labels
()
tokenizer
=
ErnieTokenizer
.
from_pretrained
(
'ernie-1.0'
)
trans_func
=
partial
(
convert_example
,
tokenizer
=
tokenizer
)
train_ds
=
train_ds
.
apply
(
trans_func
)
dev_ds
=
dev_ds
.
apply
(
trans_func
)
batchify_fn
=
lambda
samples
,
fn
=
Tuple
(
Pad
(
axis
=
0
,
pad_val
=
tokenizer
.
pad_token_id
),
Pad
(
axis
=
0
,
pad_val
=
tokenizer
.
pad_token_id
),
Stack
(
dtype
=
"int64"
)
):
[
data
for
data
in
fn
(
samples
)]
batch_sampler
=
DistributedBatchSampler
(
train_ds
,
batch_size
=
32
,
shuffle
=
True
)
train_loader
=
DataLoader
(
dataset
=
train_ds
,
batch_sampler
=
batch_sampler
,
collate_fn
=
batchify_fn
,
return_list
=
True
)
dev_loader
=
DataLoader
(
dataset
=
dev_ds
,
batch_size
=
32
,
shuffle
=
False
,
collate_fn
=
batchify_fn
,
return_list
=
True
)
model
=
paddlenlp
.
models
.
Ernie
(
'ernie-1.0'
,
task
=
'seq-cls'
,
num_classes
=
len
(
label_list
))
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
metric
=
paddle
.
metric
.
Accuracy
()
optimizer
=
paddle
.
optimizer
.
AdamW
(
learning_rate
=
5e-5
,
parameters
=
model
.
parameters
())
inputs
=
[
InputSpec
(
[
None
,
128
],
dtype
=
'int64'
,
name
=
'input_ids'
),
InputSpec
(
[
None
,
128
],
dtype
=
'int64'
,
name
=
'token_type_ids'
)
]
trainer
=
paddle
.
Model
(
model
,
inputs
)
trainer
.
prepare
(
optimizer
,
criterion
,
metric
)
trainer
.
fit
(
train_loader
,
dev_loader
,
batch_size
=
32
,
epochs
=
3
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录