Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
894bd217
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看板
提交
894bd217
编写于
12月 23, 2020
作者:
S
smallv0221
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine code
上级
923a3aa7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
45 deletion
+23
-45
PaddleNLP/paddlenlp/datasets/dataset.py
PaddleNLP/paddlenlp/datasets/dataset.py
+23
-45
未找到文件。
PaddleNLP/paddlenlp/datasets/dataset.py
浏览文件 @
894bd217
...
@@ -90,25 +90,20 @@ class MapDatasetWrapper(Dataset):
...
@@ -90,25 +90,20 @@ class MapDatasetWrapper(Dataset):
def
__init__
(
self
,
data
):
def
__init__
(
self
,
data
):
self
.
data
=
data
self
.
data
=
data
self
.
_transform_pipline
=
[]
self
.
_transform_pipline
=
[]
self
.
new_data
=
[]
self
.
new_data
=
self
.
data
def
transform
(
self
,
data
,
pipline
):
def
_
transform
(
self
,
data
,
pipline
):
for
fn
in
reversed
(
pipline
):
for
fn
in
reversed
(
pipline
):
data
=
fn
(
data
)
data
=
fn
(
data
)
return
data
return
data
def
__getitem__
(
self
,
idx
):
def
__getitem__
(
self
,
idx
):
if
not
self
.
new_data
:
return
self
.
_transform
(
return
self
.
transform
(
self
.
new_data
[
idx
],
self
.
_transform_pipline
self
.
data
[
idx
],
self
.
_transform_pipline
)
if
self
.
_transform_pipline
else
self
.
new_data
[
idx
]
)
if
self
.
_transform_pipline
else
self
.
data
[
idx
]
else
:
return
self
.
transform
(
self
.
new_data
[
idx
],
self
.
_transform_pipline
)
if
self
.
_transform_pipline
else
self
.
new_data
[
idx
]
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
data
)
if
not
self
.
new_data
else
len
(
self
.
new_data
)
return
len
(
self
.
new_data
)
def
filter
(
self
,
fn
):
def
filter
(
self
,
fn
):
"""
"""
...
@@ -120,16 +115,11 @@ class MapDatasetWrapper(Dataset):
...
@@ -120,16 +115,11 @@ class MapDatasetWrapper(Dataset):
Returns:
Returns:
MapDatasetWrapper: The filtered dataset
MapDatasetWrapper: The filtered dataset
"""
"""
if
not
self
.
new_data
:
self
.
new_data
=
[
self
.
new_data
=
[
self
.
data
[
idx
]
for
idx
in
range
(
len
(
self
.
data
))
self
.
new_data
[
idx
]
for
idx
in
range
(
len
(
self
.
new_data
))
if
fn
(
self
.
data
[
idx
])
if
fn
(
self
.
new_data
[
idx
])
]
]
else
:
self
.
new_data
=
[
self
.
data
[
idx
]
for
idx
in
range
(
len
(
self
.
new_data
))
if
fn
(
self
.
new_data
[
idx
])
]
return
self
return
self
def
shard
(
self
,
num_shards
=
None
,
index
=
None
):
def
shard
(
self
,
num_shards
=
None
,
index
=
None
):
...
@@ -150,23 +140,17 @@ class MapDatasetWrapper(Dataset):
...
@@ -150,23 +140,17 @@ class MapDatasetWrapper(Dataset):
num_shards
=
dist
.
get_world_size
()
num_shards
=
dist
.
get_world_size
()
if
index
is
None
:
if
index
is
None
:
index
=
dist
.
get_rank
()
index
=
dist
.
get_rank
()
num_samples
=
int
(
math
.
ceil
(
len
(
self
.
data
)
*
1.0
/
num_shards
))
num_samples
=
int
(
math
.
ceil
(
len
(
self
.
new_data
)
*
1.0
/
num_shards
))
total_size
=
num_samples
*
num_shards
total_size
=
num_samples
*
num_shards
# add extra samples to make it evenly divisible
# add extra samples to make it evenly divisible
if
not
self
.
new_data
:
self
.
new_data
=
[
self
.
new_data
=
[
self
.
new_data
[
idx
]
for
idx
in
range
(
len
(
self
.
new_data
))
self
.
data
[
idx
]
for
idx
in
range
(
len
(
self
.
data
))
if
idx
%
num_shards
==
index
if
idx
%
num_shards
==
index
]
]
if
len
(
self
.
new_data
)
<
num_samples
:
if
len
(
self
.
new_data
)
<
num_samples
:
self
.
new_data
.
append
(
self
.
new_data
[
index
+
1
-
num_shards
])
self
.
new_data
.
append
(
self
.
data
[
index
+
1
-
num_shards
])
else
:
self
.
new_data
=
[
self
.
data
[
idx
]
for
idx
in
range
(
len
(
self
.
new_data
))
if
idx
%
num_shards
==
index
]
if
len
(
self
.
new_data
)
<
num_samples
:
self
.
new_data
.
append
(
self
.
new_data
[
index
+
1
-
num_shards
])
return
self
return
self
def
apply
(
self
,
fn
,
lazy
=
False
):
def
apply
(
self
,
fn
,
lazy
=
False
):
...
@@ -187,15 +171,9 @@ class MapDatasetWrapper(Dataset):
...
@@ -187,15 +171,9 @@ class MapDatasetWrapper(Dataset):
if
lazy
:
if
lazy
:
self
.
_transform_pipline
.
append
(
fn
)
self
.
_transform_pipline
.
append
(
fn
)
else
:
else
:
if
not
self
.
new_data
:
self
.
new_data
=
[
self
.
new_data
=
[
fn
(
self
.
new_data
[
idx
])
for
idx
in
range
(
len
(
self
.
new_data
))
fn
(
self
.
data
[
idx
])
for
idx
in
range
(
len
(
self
.
data
))
]
]
else
:
self
.
new_data
=
[
fn
(
self
.
new_data
[
idx
])
for
idx
in
range
(
len
(
self
.
new_data
))
]
return
self
return
self
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录