Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
b7f6f1f1
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b7f6f1f1
编写于
4月 19, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add text classification reader
上级
3298af5c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
53 addition
and
0 deletion
+53
-0
paddlehub/reader/__init__.py
paddlehub/reader/__init__.py
+1
-0
paddlehub/reader/nlp_reader.py
paddlehub/reader/nlp_reader.py
+52
-0
未找到文件。
paddlehub/reader/__init__.py
浏览文件 @
b7f6f1f1
...
@@ -14,4 +14,5 @@
...
@@ -14,4 +14,5 @@
from
.nlp_reader
import
ClassifyReader
from
.nlp_reader
import
ClassifyReader
from
.nlp_reader
import
SequenceLabelReader
from
.nlp_reader
import
SequenceLabelReader
from
.nlp_reader
import
TextClassificationReader
from
.cv_reader
import
ImageClassificationReader
from
.cv_reader
import
ImageClassificationReader
paddlehub/reader/nlp_reader.py
浏览文件 @
b7f6f1f1
...
@@ -20,11 +20,13 @@ import csv
...
@@ -20,11 +20,13 @@ import csv
import
json
import
json
from
collections
import
namedtuple
from
collections
import
namedtuple
import
paddle
import
numpy
as
np
import
numpy
as
np
from
paddlehub.reader
import
tokenization
from
paddlehub.reader
import
tokenization
from
paddlehub.common.logger
import
logger
from
paddlehub.common.logger
import
logger
from
.batching
import
pad_batch_data
from
.batching
import
pad_batch_data
import
paddlehub
as
hub
class
BaseReader
(
object
):
class
BaseReader
(
object
):
...
@@ -381,5 +383,55 @@ class ExtractEmbeddingReader(BaseReader):
...
@@ -381,5 +383,55 @@ class ExtractEmbeddingReader(BaseReader):
return
return_list
return
return_list
class
TextClassificationReader
(
object
):
def
__init__
(
self
,
dataset
,
vocab_path
,
do_lower_case
=
False
):
self
.
dataset
=
dataset
self
.
tokenizer
=
tokenization
.
FullTokenizer
(
vocab_file
=
vocab_path
,
do_lower_case
=
do_lower_case
)
self
.
vocab
=
self
.
tokenizer
.
vocab
self
.
lac
=
hub
.
Module
(
name
=
"lac"
)
self
.
feed_key
=
list
(
self
.
lac
.
processor
.
data_format
(
sign_name
=
"lexical_analysis"
).
keys
())[
0
]
def
data_generator
(
self
,
batch_size
=
1
,
phase
=
"train"
,
shuffle
=
False
,
data
=
None
):
if
phase
==
"train"
:
data
=
self
.
dataset
.
get_train_examples
()
elif
phase
==
"test"
:
shuffle
=
False
data
=
self
.
dataset
.
get_test_examples
()
elif
phase
==
"val"
or
phase
==
"dev"
:
shuffle
=
False
data
=
self
.
dataset
.
get_dev_examples
()
elif
phase
==
"predict"
:
data
=
data
def
preprocess
(
text
):
data_dict
=
{
self
.
feed_key
:
[
text
]}
processed
=
self
.
lac
.
lexical_analysis
(
data
=
data_dict
)
processed
=
[
self
.
vocab
[
word
]
for
word
in
processed
[
0
][
'word'
]
if
word
in
self
.
vocab
]
return
processed
def
_data_reader
():
if
phase
==
"predict"
:
for
text
in
data
:
text
=
preprocess
(
text
)
yield
(
text
,
)
else
:
for
item
in
data
:
text
=
preprocess
(
item
.
text_a
)
yield
(
text
,
item
.
label
)
return
paddle
.
batch
(
_data_reader
,
batch_size
=
batch_size
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
pass
pass
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录