未验证 提交 6a1af6f2 编写于 作者: L Linjie Chen 提交者: GitHub

fix bug of model not found error (#2007)

* Update to Auto Model

* Update to Auto Model
上级 c40b9df0
```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
更新预训练模型调用方法
......@@ -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)
```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
更新预训练模型调用方法
......@@ -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)
# 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
```
......@@ -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 = RobertaForSequenceClassification.from_pretrained(
pretrained_model_name_or_path='roberta-wwm-ext-large', num_classes=self.num_classes, **kwargs)
self.model = AutoModelForSequenceClassification.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 = RobertaForTokenClassification.from_pretrained(
pretrained_model_name_or_path='roberta-wwm-ext-large', num_classes=self.num_classes, **kwargs)
self.model = AutoModelForTokenClassification.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)
# 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
```
......@@ -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 = RobertaForSequenceClassification.from_pretrained(
pretrained_model_name_or_path='roberta-wwm-ext', num_classes=self.num_classes, **kwargs)
self.model = AutoModelForSequenceClassification.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 = RobertaForTokenClassification.from_pretrained(
pretrained_model_name_or_path='roberta-wwm-ext', num_classes=self.num_classes, **kwargs)
self.model = AutoModelForTokenClassification.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.
先完成此消息的编辑!
想要评论请 注册