@@ -668,7 +668,7 @@ from paddlenlp import Taskflow
668
668
```python
669
669
>>> schema = [{'Person': ['Company', 'Position']}]
670
670
>>> ie_en.set_schema(schema)
671
- >>> ie_en('In 1997, Steve was excited to become the CEO of Apple.')
671
+ >>> pprint( ie_en('In 1997, Steve was excited to become the CEO of Apple.') )
672
672
[{'Person': [{'end': 14,
673
673
'probability': 0.999631971804547,
674
674
'relations': {'Company': [{'end': 53,
@@ -711,7 +711,7 @@ from paddlenlp import Taskflow
711
711
[{'地震触发词': [{'text': '地震', 'start': 56, 'end': 58, 'probability': 0.9987181623528585, 'relations': {'地震强度': [{'text': '3.5级', 'start': 52, 'end': 56, 'probability': 0.9962985320905915}], '时间': [{'text': '5月16日06时08分', 'start': 11, 'end': 22, 'probability': 0.9882578028575182}], '震中位置': [{'text': '云南临沧市凤庆县(北纬24.34度,东经99.98度)', 'start': 23, 'end': 50, 'probability': 0.8551415716584501}], '震源深度': [{'text': '10千米', 'start': 63, 'end': 67, 'probability': 0.999158304648045}]}}]}]
712
712
```
713
713
714
- - 英文模型 **暂不支持事件抽取**
714
+ - 英文模型zero-shot方式 **暂不支持事件抽取**,如有英文事件抽取相关语料请进行训练定制。
715
715
716
716
#### 评论观点抽取
717
717
@@ -770,19 +770,19 @@ from paddlenlp import Taskflow
770
770
英文模型调用示例:
771
771
772
772
```python
773
- >>> schema = [{'Comment object ': ['Opinion', 'Sentiment classification [negative, positive]']}]
773
+ >>> schema = [{'Aspect ': ['Opinion', 'Sentiment classification [negative, positive]']}]
774
774
>>> ie_en.set_schema(schema)
775
- >>> ie_en("overall i 'm happy with my toy." )
776
- [{'Comment object ': [{'end': 30 ,
777
- 'probability': 0.9774399346859042 ,
778
- 'relations': {'Opinion': [{'end': 18 ,
779
- 'probability': 0.6168918705033555 ,
780
- 'start': 13 ,
781
- 'text': 'happy '}],
782
- 'Sentiment classification [negative, positive]': [{'probability': 0.9999556545777182 ,
783
- 'text': 'positive'}]},
784
- 'start': 24 ,
785
- 'text': 'my toy '}]}]
775
+ >>> pprint( ie_en("The teacher is very nice.") )
776
+ [{'Aspect ': [{'end': 11 ,
777
+ 'probability': 0.4301476415932193 ,
778
+ 'relations': {'Opinion': [{'end': 24 ,
779
+ 'probability': 0.9072940447883724 ,
780
+ 'start': 15 ,
781
+ 'text': 'very nice '}],
782
+ 'Sentiment classification [negative, positive]': [{'probability': 0.9998571920670685 ,
783
+ 'text': 'positive'}]},
784
+ 'start': 4 ,
785
+ 'text': 'teacher '}]}]
786
786
```
787
787
788
788
#### 情感分类
@@ -811,7 +811,7 @@ from paddlenlp import Taskflow
811
811
英文模型调用示例:
812
812
813
813
```python
814
- >>> schema = [{'Person': ['Company', 'Position']}]
814
+ >>> schema = 'Sentiment classification [negative, positive]'
815
815
>>> ie_en.set_schema(schema)
816
816
>>> ie_en('I am sorry but this is the worst film I have ever seen in my life.')
817
817
[{'Sentiment classification [negative, positive]': [{'text': 'negative', 'probability': 0.9998415771287057}]}]
@@ -874,8 +874,10 @@ from paddlenlp import Taskflow
874
874
| `uie-mini`| 6-layers, 384-hidden, 12-heads | 中文 |
875
875
| `uie-micro`| 4-layers, 384-hidden, 12-heads | 中文 |
876
876
| `uie-nano`| 4-layers, 312-hidden, 12-heads | 中文 |
877
+ | `uie-m-large`| 24-layers, 1024-hidden, 16-heads | 中、英文 |
878
+ | `uie-m-base`| 12-layers, 768-hidden, 12-heads | 中、英文 |
877
879
878
- - `uie-nano`调用示例
880
+ - `uie-nano`调用示例:
879
881
880
882
```python
881
883
>>> from paddlenlp import Taskflow
@@ -886,6 +888,41 @@ from paddlenlp import Taskflow
886
888
[{'时间': [{'text': '2月8日上午', 'start': 0, 'end': 6, 'probability': 0.6513581678349247}], '选手': [{'text': '谷爱凌', 'start': 28, 'end': 31, 'probability': 0.9819330659468051}], '赛事名称': [{'text': '北京冬奥会自由式滑雪女子大跳台决赛', 'start': 6, 'end': 23, 'probability': 0.4908131110420939}]}]
887
889
```
888
890
891
+ - ` uie-m-base ` 和` uie-m-large ` 支持中英文混合抽取,调用示例:
892
+
893
+ ``` python
894
+ >> > from pprint import pprint
895
+ >> > from paddlenlp import Taskflow
896
+
897
+ >> > schema = [' Time' , ' Player' , ' Competition' , ' Score' ]
898
+ >> > ie = Taskflow(' information_extraction' , schema = schema, model = " uie-m-base" , schema_lang = " en" )
899
+ >> > pprint(ie([" 2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!" , " Rafael Nadal wins French Open Final!" ]))
900
+ [{' Competition' : [{' end' : 23 ,
901
+ ' probability' : 0.9373889907291257 ,
902
+ ' start' : 6 ,
903
+ ' text' : ' 北京冬奥会自由式滑雪女子大跳台决赛' }],
904
+ ' Player' : [{' end' : 31 ,
905
+ ' probability' : 0.6981119555336441 ,
906
+ ' start' : 28 ,
907
+ ' text' : ' 谷爱凌' }],
908
+ ' Score' : [{' end' : 39 ,
909
+ ' probability' : 0.9888507878270296 ,
910
+ ' start' : 32 ,
911
+ ' text' : ' 188.25分' }],
912
+ ' Time' : [{' end' : 6 ,
913
+ ' probability' : 0.9784080036931151 ,
914
+ ' start' : 0 ,
915
+ ' text' : ' 2月8日上午' }]},
916
+ {' Competition' : [{' end' : 35 ,
917
+ ' probability' : 0.9851549932171295 ,
918
+ ' start' : 18 ,
919
+ ' text' : ' French Open Final' }],
920
+ ' Player' : [{' end' : 12 ,
921
+ ' probability' : 0.9379371275888104 ,
922
+ ' start' : 0 ,
923
+ ' text' : ' Rafael Nadal' }]}]
924
+ ```
925
+
889
926
#### 定制训练
890
927
891
928
对于简单的抽取目标可以直接使用``` paddlenlp.Taskflow ``` 实现零样本(zero-shot)抽取,对于细分场景我们推荐使用[ 定制训练] ( https://github.com/PaddlePaddle/PaddleNLP/tree/develop/model_zoo/uie ) (标注少量数据进行模型微调)以进一步提升效果。
@@ -895,19 +932,24 @@ from paddlenlp import Taskflow
895
932
<table >
896
933
<tr ><th row_span =' 2 ' ><th colspan =' 2 ' >金融<th colspan =' 2 ' >医疗<th colspan =' 2 ' >互联网
897
934
<tr ><td ><th >0-shot<th >5-shot<th >0-shot<th >5-shot<th >0-shot<th >5-shot
898
- <tr ><td >uie-base (12L768H)<td >< b > 46.43</ b >< td >< b > 70.92</ b >< td ><b >71.83</b ><td >< b > 85.72</ b >< td >< b > 78.33</ b >< td >< b > 81.86</ b >
935
+ <tr ><td >uie-base (12L768H)<td >46.43<td >70.92<td ><b >71.83</b ><td >85.72<td >78.33<td >81.86
899
936
<tr ><td >uie-medium (6L768H)<td >41.11<td >64.53<td >65.40<td >75.72<td >78.32<td >79.68
900
937
<tr ><td >uie-mini (6L384H)<td >37.04<td >64.65<td >60.50<td >78.36<td >72.09<td >76.38
901
938
<tr ><td >uie-micro (4L384H)<td >37.53<td >62.11<td >57.04<td >75.92<td >66.00<td >70.22
902
939
<tr ><td >uie-nano (4L312H)<td >38.94<td >66.83<td >48.29<td >76.74<td >62.86<td >72.35
903
940
</table >
941
+ <tr ><td >uie-m-large (24L1024H)<td ><b >49.35</b ><td ><b >74.55</b ><td >70.50<td ><b >92.66</b ><td ><b >78.49</b ><td ><b >83.02</b >
942
+ <tr ><td >uie-m-base (12L768H)<td >38.46<td >74.31<td >63.37<td >87.32<td >76.27<td >80.13
943
+ </table >
904
944
905
- 0-shot表示无训练数据直接通过``` paddlenlp.Taskflow ``` 进行预测,5-shot表示基于5条标注数据进行模型微调 。** 实验表明UIE在垂类场景可以通过少量数据(few-shot)进一步提升效果** 。
945
+ 0-shot表示无训练数据直接通过``` paddlenlp.Taskflow ``` 进行预测,5-shot表示每个类别包含5条标注数据进行模型微调 。** 实验表明UIE在垂类场景可以通过少量数据(few-shot)进一步提升效果** 。
906
946
907
947
#### 可配置参数说明
948
+
949
+ * ` schema ` :定义任务抽取目标,可参考开箱即用中不同任务的调用示例进行配置。
950
+ * ` schema_lang ` :设置schema的语言,默认为` zh ` , 可选有` zh ` 和` en ` 。因为中英schema的构造有所不同,因此需要指定schema的语言。该参数只对` uie-m-base ` 和` uie-m-large ` 模型有效。
908
951
* ` batch_size ` :批处理大小,请结合机器情况进行调整,默认为1。
909
952
* ` model ` :选择任务使用的模型,默认为` uie-base ` ,可选有` uie-base ` , ` uie-medium ` , ` uie-mini ` , ` uie-micro ` , ` uie-nano ` , ` uie-medical-base ` , ` uie-base-en ` 。
910
- * ` schema ` :定义任务抽取目标,可参考开箱即用中不同任务的调用示例进行配置。
911
953
* ` position_prob ` :模型对于span的起始位置/终止位置的结果概率0~ 1之间,返回结果去掉小于这个阈值的结果,默认为0.5,span的最终概率输出为起始位置概率和终止位置概率的乘积。
912
954
* ` precision ` :选择模型精度,默认为` fp32 ` ,可选有` fp16 ` 和` fp32 ` 。` fp16 ` 推理速度更快。如果选择` fp16 ` ,请先确保机器正确安装NVIDIA相关驱动和基础软件,** 确保CUDA>=11.2,cuDNN>=8.1.1** ,初次使用需按照提示安装相关依赖(主要是** 确保安装onnxruntime-gpu** )。其次,需要确保GPU设备的CUDA计算能力(CUDA Compute Capability)大于7.0,典型的设备包括V100、T4、A10、A100、GTX 20系列和30系列显卡等。更多关于CUDA Compute Capability和精度支持情况请参考NVIDIA文档:[ GPU硬件与支持精度对照表] ( https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-840-ea/support-matrix/index.html#hardware-precision-matrix ) 。
913
955
</div ></details >
0 commit comments