Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
6a1af6f2
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
284
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看板
未验证
提交
6a1af6f2
编写于
9月 16, 2022
作者:
L
Linjie Chen
提交者:
GitHub
9月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug of model not found error (#2007)
* Update to Auto Model * Update to Auto Model
上级
c40b9df0
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
126 addition
and
94 deletion
+126
-94
modules/text/language_model/rbt3/README.md
modules/text/language_model/rbt3/README.md
+6
-2
modules/text/language_model/rbt3/module.py
modules/text/language_model/rbt3/module.py
+26
-21
modules/text/language_model/rbtl3/README.md
modules/text/language_model/rbtl3/README.md
+6
-2
modules/text/language_model/rbtl3/module.py
modules/text/language_model/rbtl3/module.py
+26
-21
modules/text/language_model/roberta-wwm-ext-large/README.md
modules/text/language_model/roberta-wwm-ext-large/README.md
+7
-3
modules/text/language_model/roberta-wwm-ext-large/module.py
modules/text/language_model/roberta-wwm-ext-large/module.py
+24
-21
modules/text/language_model/roberta-wwm-ext/README.md
modules/text/language_model/roberta-wwm-ext/README.md
+7
-3
modules/text/language_model/roberta-wwm-ext/module.py
modules/text/language_model/roberta-wwm-ext/module.py
+24
-21
未找到文件。
modules/text/language_model/rbt3/README.md
浏览文件 @
6a1af6f2
```
shell
$
hub
install
rtb3
==
2.0.
1
$
hub
install
rtb3
==
2.0.
2
```
<p
align=
"center"
>
<img
src=
"https://bj.bcebos.com/paddlehub/paddlehub-img/bert_network.png"
hspace=
'10'
/>
<br
/>
...
...
@@ -85,7 +85,7 @@ label_map = {0: 'negative', 1: 'positive'}
model
=
hub
.
Module
(
name
=
'rtb3'
,
version
=
'2.0.
1
'
,
version
=
'2.0.
2
'
,
task
=
'seq-cls'
,
load_checkpoint
=
'/path/to/parameters'
,
label_map
=
label_map
)
...
...
@@ -163,3 +163,7 @@ paddlehub >= 2.0.0
*
2.0.1
增加文本匹配任务
`text-matching`
*
2.0.2
更新预训练模型调用方法
modules/text/language_model/rbt3/module.py
浏览文件 @
6a1af6f2
...
...
@@ -11,17 +11,19 @@
# 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.
from
typing
import
Dict
import
os
import
math
import
os
from
typing
import
Dict
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddlenlp.transformers.roberta.modeling
import
RobertaForSequenceClassification
,
RobertaForTokenClassification
,
RobertaModel
from
paddlenlp.transformers.roberta.tokenizer
import
RobertaTokenizer
from
paddlenlp.metrics
import
ChunkEvaluator
from
paddlenlp.transformers
import
AutoModel
from
paddlenlp.transformers
import
AutoModelForSequenceClassification
from
paddlenlp.transformers
import
AutoModelForTokenClassification
from
paddlenlp.transformers
import
AutoTokenizer
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.nlp_module
import
TransformerModule
from
paddlehub.utils.log
import
logger
...
...
@@ -29,7 +31,7 @@ from paddlehub.utils.log import logger
@
moduleinfo
(
name
=
"rbt3"
,
version
=
"2.0.
1
"
,
version
=
"2.0.
2
"
,
summary
=
"rbt3, 3-layer, 768-hidden, 12-heads, 38M parameters "
,
author
=
"ymcui"
,
author_email
=
"ymcui@ir.hit.edu.cn"
,
...
...
@@ -42,13 +44,13 @@ class Roberta(nn.Layer):
"""
def
__init__
(
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
):
super
(
Roberta
,
self
).
__init__
()
if
label_map
:
...
...
@@ -63,23 +65,26 @@ class Roberta(nn.Layer):
"current task name 'sequence_classification' was renamed to 'seq-cls', "
"'sequence_classification' has been deprecated and will be removed in the future."
,
)
if
task
==
'seq-cls'
:
self
.
model
=
RobertaForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'rbt3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModelForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/rbt3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
==
'token-cls'
:
self
.
model
=
RobertaForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'rbt3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModelForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/rbt3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
elif
task
==
'text-matching'
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbt3'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbt3'
,
**
kwargs
)
self
.
dropout
=
paddle
.
nn
.
Dropout
(
0.1
)
self
.
classifier
=
paddle
.
nn
.
Linear
(
self
.
model
.
config
[
'hidden_size'
]
*
3
,
2
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
is
None
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbt3'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbt3'
,
**
kwargs
)
else
:
raise
RuntimeError
(
"Unknown task {}, task should be one in {}"
.
format
(
task
,
self
.
_tasks_supported
))
...
...
@@ -171,4 +176,4 @@ class Roberta(nn.Layer):
"""
Gets the tokenizer that is customized for this module.
"""
return
RobertaTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbt3'
,
*
args
,
**
kwargs
)
return
AutoTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbt3'
,
*
args
,
**
kwargs
)
modules/text/language_model/rbtl3/README.md
浏览文件 @
6a1af6f2
```
shell
$
hub
install
rbtl3
==
2.0.
1
$
hub
install
rbtl3
==
2.0.
2
```
<p
align=
"center"
>
<img
src=
"https://bj.bcebos.com/paddlehub/paddlehub-img/bert_network.png"
hspace=
'10'
/>
<br
/>
...
...
@@ -85,7 +85,7 @@ label_map = {0: 'negative', 1: 'positive'}
model
=
hub
.
Module
(
name
=
'rbtl3'
,
version
=
'2.0.
1
'
,
version
=
'2.0.
2
'
,
task
=
'seq-cls'
,
load_checkpoint
=
'/path/to/parameters'
,
label_map
=
label_map
)
...
...
@@ -163,3 +163,7 @@ paddlehub >= 2.0.0
*
2.0.1
增加文本匹配任务
`text-matching`
*
2.0.2
更新预训练模型调用方法
modules/text/language_model/rbtl3/module.py
浏览文件 @
6a1af6f2
...
...
@@ -11,17 +11,19 @@
# 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.
from
typing
import
Dict
import
os
import
math
import
os
from
typing
import
Dict
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddlenlp.transformers.roberta.modeling
import
RobertaForSequenceClassification
,
RobertaForTokenClassification
,
RobertaModel
from
paddlenlp.transformers.roberta.tokenizer
import
RobertaTokenizer
from
paddlenlp.metrics
import
ChunkEvaluator
from
paddlenlp.transformers
import
AutoModel
from
paddlenlp.transformers
import
AutoModelForSequenceClassification
from
paddlenlp.transformers
import
AutoModelForTokenClassification
from
paddlenlp.transformers
import
AutoTokenizer
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.nlp_module
import
TransformerModule
from
paddlehub.utils.log
import
logger
...
...
@@ -29,7 +31,7 @@ from paddlehub.utils.log import logger
@
moduleinfo
(
name
=
"rbtl3"
,
version
=
"2.0.
1
"
,
version
=
"2.0.
2
"
,
summary
=
"rbtl3, 3-layer, 1024-hidden, 16-heads, 61M parameters "
,
author
=
"ymcui"
,
author_email
=
"ymcui@ir.hit.edu.cn"
,
...
...
@@ -42,13 +44,13 @@ class Roberta(nn.Layer):
"""
def
__init__
(
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
):
super
(
Roberta
,
self
).
__init__
()
if
label_map
:
...
...
@@ -63,23 +65,26 @@ class Roberta(nn.Layer):
"current task name 'sequence_classification' was renamed to 'seq-cls', "
"'sequence_classification' has been deprecated and will be removed in the future."
,
)
if
task
==
'seq-cls'
:
self
.
model
=
RobertaForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'rbtl3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModelForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/rbtl3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
==
'token-cls'
:
self
.
model
=
RobertaForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'rbtl3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModelForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/rbtl3'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
elif
task
==
'text-matching'
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbtl3'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbtl3'
,
**
kwargs
)
self
.
dropout
=
paddle
.
nn
.
Dropout
(
0.1
)
self
.
classifier
=
paddle
.
nn
.
Linear
(
self
.
model
.
config
[
'hidden_size'
]
*
3
,
2
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
is
None
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbtl3'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbtl3'
,
**
kwargs
)
else
:
raise
RuntimeError
(
"Unknown task {}, task should be one in {}"
.
format
(
task
,
self
.
_tasks_supported
))
...
...
@@ -171,4 +176,4 @@ class Roberta(nn.Layer):
"""
Gets the tokenizer that is customized for this module.
"""
return
RobertaTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'
rbtl3'
,
*
args
,
**
kwargs
)
return
AutoTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
rbtl3'
,
*
args
,
**
kwargs
)
modules/text/language_model/roberta-wwm-ext-large/README.md
浏览文件 @
6a1af6f2
# roberta-wwm-ext-large
|模型名称|roberta-wwm-ext-large|
| :--- | :---: |
| :--- | :---: |
|类别|文本-语义模型|
|网络|roberta-wwm-ext-large|
|数据集|百度自建数据集|
...
...
@@ -51,7 +51,7 @@ label_map = {0: 'negative', 1: 'positive'}
model
=
hub
.
Module
(
name
=
'roberta-wwm-ext-large'
,
version
=
'2.0.
2
'
,
version
=
'2.0.
3
'
,
task
=
'seq-cls'
,
load_checkpoint
=
'/path/to/parameters'
,
label_map
=
label_map
)
...
...
@@ -181,6 +181,10 @@ for idx, text in enumerate(data):
*
2.0.2
增加文本匹配任务
`text-matching`
*
2.0.3
更新预训练模型调用方法
```
shell
$
hub
install
roberta-wwm-ext
-large
==
2.0.2
$
hub
install
roberta-wwm-ext
==
2.0.3
```
modules/text/language_model/roberta-wwm-ext-large/module.py
浏览文件 @
6a1af6f2
...
...
@@ -11,17 +11,19 @@
# 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.
from
typing
import
Dict
import
os
import
math
import
os
from
typing
import
Dict
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddlenlp.transformers.roberta.modeling
import
RobertaForSequenceClassification
,
RobertaForTokenClassification
,
RobertaModel
from
paddlenlp.transformers.roberta.tokenizer
import
RobertaTokenizer
from
paddlenlp.metrics
import
ChunkEvaluator
from
paddlenlp.transformers
import
AutoModel
from
paddlenlp.transformers
import
AutoModelForSequenceClassification
from
paddlenlp.transformers
import
AutoModelForTokenClassification
from
paddlenlp.transformers
import
AutoTokenizer
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.nlp_module
import
TransformerModule
from
paddlehub.utils.log
import
logger
...
...
@@ -29,7 +31,7 @@ from paddlehub.utils.log import logger
@
moduleinfo
(
name
=
"roberta-wwm-ext-large"
,
version
=
"2.0.
2
"
,
version
=
"2.0.
3
"
,
summary
=
"chinese-roberta-wwm-ext-large, 24-layer, 1024-hidden, 16-heads, 340M parameters. The module is executed as paddle.dygraph."
,
author
=
"ymcui"
,
...
...
@@ -43,13 +45,13 @@ class Roberta(nn.Layer):
"""
def
__init__
(
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
):
super
(
Roberta
,
self
).
__init__
()
if
label_map
:
...
...
@@ -64,23 +66,24 @@ class Roberta(nn.Layer):
"current task name 'sequence_classification' was renamed to 'seq-cls', "
"'sequence_classification' has been deprecated and will be removed in the future."
,
)
if
task
==
'seq-cls'
:
self
.
model
=
Roberta
ForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'roberta-wwm-ext-large'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModel
ForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'
hfl/
roberta-wwm-ext-large'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
==
'token-cls'
:
self
.
model
=
Roberta
ForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'roberta-wwm-ext-large'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModel
ForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'
hfl/
roberta-wwm-ext-large'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
elif
task
==
'text-matching'
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext-large'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext-large'
,
**
kwargs
)
self
.
dropout
=
paddle
.
nn
.
Dropout
(
0.1
)
self
.
classifier
=
paddle
.
nn
.
Linear
(
self
.
model
.
config
[
'hidden_size'
]
*
3
,
2
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
is
None
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext-large'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext-large'
,
**
kwargs
)
else
:
raise
RuntimeError
(
"Unknown task {}, task should be one in {}"
.
format
(
task
,
self
.
_tasks_supported
))
...
...
@@ -172,4 +175,4 @@ class Roberta(nn.Layer):
"""
Gets the tokenizer that is customized for this module.
"""
return
RobertaTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext-large'
,
*
args
,
**
kwargs
)
return
AutoTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext-large'
,
*
args
,
**
kwargs
)
modules/text/language_model/roberta-wwm-ext/README.md
浏览文件 @
6a1af6f2
# roberta-wwm-ext
|模型名称|roberta-wwm-ext|
| :--- | :---: |
| :--- | :---: |
|类别|文本-语义模型|
|网络|roberta-wwm-ext|
|数据集|百度自建数据集|
...
...
@@ -51,7 +51,7 @@ label_map = {0: 'negative', 1: 'positive'}
model
=
hub
.
Module
(
name
=
'roberta-wwm-ext'
,
version
=
'2.0.
2
'
,
version
=
'2.0.
3
'
,
task
=
'seq-cls'
,
load_checkpoint
=
'/path/to/parameters'
,
label_map
=
label_map
)
...
...
@@ -181,6 +181,10 @@ for idx, text in enumerate(data):
*
2.0.2
增加文本匹配任务
`text-matching`
*
2.0.3
更新预训练模型调用方法
```
shell
$
hub
install
roberta-wwm-ext
==
2.0.
2
$
hub
install
roberta-wwm-ext
==
2.0.
3
```
modules/text/language_model/roberta-wwm-ext/module.py
浏览文件 @
6a1af6f2
...
...
@@ -11,17 +11,19 @@
# 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.
from
typing
import
Dict
import
os
import
math
import
os
from
typing
import
Dict
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddlenlp.transformers.roberta.modeling
import
RobertaForSequenceClassification
,
RobertaForTokenClassification
,
RobertaModel
from
paddlenlp.transformers.roberta.tokenizer
import
RobertaTokenizer
from
paddlenlp.metrics
import
ChunkEvaluator
from
paddlenlp.transformers
import
AutoModel
from
paddlenlp.transformers
import
AutoModelForSequenceClassification
from
paddlenlp.transformers
import
AutoModelForTokenClassification
from
paddlenlp.transformers
import
AutoTokenizer
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.nlp_module
import
TransformerModule
from
paddlehub.utils.log
import
logger
...
...
@@ -29,7 +31,7 @@ from paddlehub.utils.log import logger
@
moduleinfo
(
name
=
"roberta-wwm-ext"
,
version
=
"2.0.
2
"
,
version
=
"2.0.
3
"
,
summary
=
"chinese-roberta-wwm-ext, 12-layer, 768-hidden, 12-heads, 110M parameters. The module is executed as paddle.dygraph."
,
author
=
"ymcui"
,
...
...
@@ -43,13 +45,13 @@ class Roberta(nn.Layer):
"""
def
__init__
(
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
self
,
task
:
str
=
None
,
load_checkpoint
:
str
=
None
,
label_map
:
Dict
=
None
,
num_classes
:
int
=
2
,
suffix
:
bool
=
False
,
**
kwargs
,
):
super
(
Roberta
,
self
).
__init__
()
if
label_map
:
...
...
@@ -64,23 +66,24 @@ class Roberta(nn.Layer):
"current task name 'sequence_classification' was renamed to 'seq-cls', "
"'sequence_classification' has been deprecated and will be removed in the future."
,
)
if
task
==
'seq-cls'
:
self
.
model
=
Roberta
ForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'roberta-wwm-ext'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModel
ForSequenceClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'
hfl/
roberta-wwm-ext'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
==
'token-cls'
:
self
.
model
=
Roberta
ForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'roberta-wwm-ext'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
model
=
AutoModel
ForTokenClassification
.
from_pretrained
(
pretrained_model_name_or_path
=
'
hfl/
roberta-wwm-ext'
,
num_classes
=
self
.
num_classes
,
**
kwargs
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
self
.
metric
=
ChunkEvaluator
(
label_list
=
[
self
.
label_map
[
i
]
for
i
in
sorted
(
self
.
label_map
.
keys
())],
suffix
=
suffix
)
elif
task
==
'text-matching'
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext'
,
**
kwargs
)
self
.
dropout
=
paddle
.
nn
.
Dropout
(
0.1
)
self
.
classifier
=
paddle
.
nn
.
Linear
(
self
.
model
.
config
[
'hidden_size'
]
*
3
,
2
)
self
.
criterion
=
paddle
.
nn
.
loss
.
CrossEntropyLoss
()
self
.
metric
=
paddle
.
metric
.
Accuracy
()
elif
task
is
None
:
self
.
model
=
RobertaModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext'
,
**
kwargs
)
self
.
model
=
AutoModel
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext'
,
**
kwargs
)
else
:
raise
RuntimeError
(
"Unknown task {}, task should be one in {}"
.
format
(
task
,
self
.
_tasks_supported
))
...
...
@@ -172,4 +175,4 @@ class Roberta(nn.Layer):
"""
Gets the tokenizer that is customized for this module.
"""
return
RobertaTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'
roberta-wwm-ext'
,
*
args
,
**
kwargs
)
return
AutoTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
'hfl/
roberta-wwm-ext'
,
*
args
,
**
kwargs
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录