Skip to content

Commit b79aae3

Browse files
DrownFish19ZHUIFantasy-02
authored
[Cherry-Pick] Add PP-UIE and fix TaskFlow (#9914)
* [TaskFlow] Fix pir for taskflow (#9822) * fix pir for taskflow * update suffix for PIR(ON/OFF) * fix and revert skip * update dependency_parsing * fix pir bug * fix pir bug * fix lint * fix ci * disable test case --------- Co-authored-by: Zhong Hui <zhonghui.net@gmail.com> Co-authored-by: Fantasy-02 <1026931135@qq.com> * [LLM-IE] Add pp-uie to Taskflow (#9845) * fix taskflow * add llm/ie for SFT of ie task * remove data folder * update readme * add taskflow * remove taskflow * add sft for ie task * add multi_stage_predict of taskflow * fix some bug and rename qwen2 as uie-llm * fixed test and lint * fixed test and lint * fixed test and lint * update 0109 * update 0109 * update 0113 * updaate 0113 * remove static mode in taskflow * update 0115 * update 0115 * update 0115 * update 0116 * update 0116 * update readme.md * update readme.md * update 0116 * update taskflow.py and readme.md * rename model name * update * [DOC] Update README for PP-UIE (#9911) * update doc for pp-uie * update * update * [taskflow] Fix taskflow bug (#9930) * fix * add doc * update docs * add experiment * update readme.md --------- Co-authored-by: DrownFish19 <DrownFish19@gmail.com> --------- Co-authored-by: Zhong Hui <zhonghui.net@gmail.com> Co-authored-by: Fantasy-02 <1026931135@qq.com> Co-authored-by: ZiyiHuang <62085413+Fantasy-02@users.noreply.github.com>
1 parent 2f85a64 commit b79aae3

File tree

27 files changed

+2169
-487
lines changed

27 files changed

+2169
-487
lines changed

README.md

Lines changed: 38 additions & 28 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../llm/application/information_extraction/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../llm/application/information_extraction/doccano.md

llm/application/information_extraction/README.md

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# doccano
2+
3+
**目录**
4+
5+
* [1. 安装](#安装)
6+
* [2. 项目创建](#项目创建)
7+
* [3. 数据上传](#数据上传)
8+
* [4. 标签构建](#标签构建)
9+
* [5. 任务标注](#任务标注)
10+
* [6. 数据导出](#数据导出)
11+
* [7. 数据转换](#数据转换)
12+
13+
<a name="安装"></a>
14+
15+
## 1. 安装
16+
17+
参考[doccano 官方文档](https://github.com/doccano/doccano) 完成 doccano 的安装与初始配置。
18+
19+
**以下标注示例用到的环境配置:**
20+
21+
- doccano 1.6.2
22+
23+
<a name="项目创建"></a>
24+
25+
## 2. 项目创建
26+
27+
PP-UIE 支持抽取类型的任务,根据实际需要创建一个新的项目:
28+
29+
#### 2.1 抽取式任务项目创建
30+
31+
创建项目时选择**序列标注**任务,并勾选**Allow overlapping entity****Use relation Labeling**。适配**命名实体识别、关系抽取、事件抽取**等任务。
32+
33+
<div align="center">
34+
<img src=https://user-images.githubusercontent.com/40840292/167249142-44885510-51dc-4359-8054-9c89c9633700.png height=230 hspace='15'/>
35+
</div>
36+
37+
<a name="数据上传"></a>
38+
39+
## 3. 数据上传
40+
41+
上传的文件为 txt 格式,每一行为一条待标注文本,示例:
42+
43+
```text
44+
2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌
45+
第十四届全运会在西安举办
46+
```
47+
48+
上传数据类型**选择 TextLine**:
49+
50+
<div align="center">
51+
<img src=https://user-images.githubusercontent.com/40840292/167247061-d5795c26-7a6f-4cdb-88ad-107a3cae5446.png height=300 hspace='15'/>
52+
</div>
53+
54+
**NOTE**:doccano 支持`TextFile``TextLine``JSONL``CoNLL`四种数据上传格式,PP-UIE 定制训练中**统一使用 TextLine**这一文件格式,即上传的文件需要为 txt 格式,且在数据标注时,该文件的每一行待标注文本显示为一页内容。
55+
56+
<a name="标签构建"></a>
57+
58+
## 4. 标签构建
59+
60+
#### 4.1 构建抽取式任务标签
61+
62+
抽取式任务包含**Span****Relation**两种标签类型,Span 指**原文本中的目标信息片段**,如实体识别中某个类型的实体,事件抽取中的触发词和论元;Relation 指**原文本中 Span 之间的关系**,如关系抽取中两个实体(Subject&Object)之间的关系,事件抽取中论元和触发词之间的关系。
63+
64+
Span 类型标签构建示例:
65+
66+
<div align="center">
67+
<img src=https://user-images.githubusercontent.com/40840292/167248034-afa3f637-65c5-4038-ada0-344ffbd776a2.png height=300 hspace='15'/>
68+
</div>
69+
70+
Relation 类型标签构建示例:
71+
72+
<div align="center">
73+
<img src=https://user-images.githubusercontent.com/40840292/167248307-916c77f6-bf80-4d6b-aa71-30c719f68257.png height=260 hspace='16'/>
74+
</div>
75+
76+
77+
## 5. 任务标注
78+
79+
#### 5.1 命名实体识别
80+
81+
命名实体识别(Named Entity Recognition,简称 NER),是指识别文本中具有特定意义的实体。在开放域信息抽取中,**抽取的类别没有限制,用户可以自己定义**
82+
83+
标注示例:
84+
85+
<div align="center">
86+
<img src=https://user-images.githubusercontent.com/40840292/167248557-f1da3694-1063-465a-be9a-1bb811949530.png height=200 hspace='20'/>
87+
</div>
88+
89+
示例中定义了`时间``选手``赛事名称``得分`四种 Span 类型标签。
90+
91+
```text
92+
schema = [
93+
'时间',
94+
'选手',
95+
'赛事名称',
96+
'得分'
97+
]
98+
```
99+
100+
#### 5.2 关系抽取
101+
102+
关系抽取(Relation Extraction,简称 RE),是指从文本中识别实体并抽取实体之间的语义关系,即抽取三元组(实体一,关系类型,实体二)。
103+
104+
标注示例:
105+
106+
<div align="center">
107+
<img src=https://user-images.githubusercontent.com/40840292/167248502-16a87902-3878-4432-b5b8-9808bd8d4de5.png height=200 hspace='20'/>
108+
</div>
109+
110+
示例中定义了`作品名``人物名``时间`三种 Span 类型标签,以及`歌手``发行时间``所属专辑`三种 Relation 标签。Relation 标签**由 Subject 对应实体指向 Object 对应实体**
111+
112+
该标注示例对应的 schema 为:
113+
114+
```text
115+
schema = {
116+
'作品名': [
117+
'歌手',
118+
'发行时间',
119+
'所属专辑'
120+
]
121+
}
122+
```
123+
124+
#### 5.3 事件抽取
125+
126+
事件抽取 (Event Extraction, 简称 EE),是指从自然语言文本中抽取事件并识别事件类型和事件论元的技术。UIE 所包含的事件抽取任务,是指根据已知事件类型,抽取该事件所包含的事件论元。
127+
128+
标注示例:
129+
130+
<div align="center">
131+
<img src=https://user-images.githubusercontent.com/40840292/167248793-138a1e37-43c9-4933-bf89-f3ac7228bf9c.png height=200 hspace='20'/>
132+
</div>
133+
134+
示例中定义了`地震触发词`(触发词)、`等级`(事件论元)和`时间`(事件论元)三种 Span 标签,以及`时间``震级`两种 Relation 标签。触发词标签**统一格式为`XX 触发词`**`XX`表示具体事件类型,上例中的事件类型是`地震`,则对应触发词为`地震触发词`。Relation 标签**由触发词指向对应的事件论元**
135+
136+
该标注示例对应的 schema 为:
137+
138+
```text
139+
schema = {
140+
'地震触发词': [
141+
'时间',
142+
'震级'
143+
]
144+
}
145+
```
146+
147+
148+
<a name="数据导出"></a>
149+
150+
## 6. 数据导出
151+
152+
#### 6.1 导出抽取式任务数据
153+
154+
选择导出的文件类型为``JSONL(relation)``,导出数据示例:
155+
156+
```text
157+
{
158+
"id": 38,
159+
"text": "百科名片你知道我要什么,是歌手高明骏演唱的一首歌曲,1989年发行,收录于个人专辑《丛林男孩》中",
160+
"relations": [
161+
{
162+
"id": 20,
163+
"from_id": 51,
164+
"to_id": 53,
165+
"type": "歌手"
166+
},
167+
{
168+
"id": 21,
169+
"from_id": 51,
170+
"to_id": 55,
171+
"type": "发行时间"
172+
},
173+
{
174+
"id": 22,
175+
"from_id": 51,
176+
"to_id": 54,
177+
"type": "所属专辑"
178+
}
179+
],
180+
"entities": [
181+
{
182+
"id": 51,
183+
"start_offset": 4,
184+
"end_offset": 11,
185+
"label": "作品名"
186+
},
187+
{
188+
"id": 53,
189+
"start_offset": 15,
190+
"end_offset": 18,
191+
"label": "人物名"
192+
},
193+
{
194+
"id": 54,
195+
"start_offset": 42,
196+
"end_offset": 46,
197+
"label": "作品名"
198+
},
199+
{
200+
"id": 55,
201+
"start_offset": 26,
202+
"end_offset": 31,
203+
"label": "时间"
204+
}
205+
]
206+
}
207+
```
208+
209+
标注数据保存在同一个文本文件中,每条样例占一行且存储为``json``格式,其包含以下字段
210+
- ``id``: 样本在数据集中的唯一标识 ID。
211+
- ``text``: 原始文本数据。
212+
- ``entities``: 数据中包含的 Span 标签,每个 Span 标签包含四个字段:
213+
- ``id``: Span 在数据集中的唯一标识 ID。
214+
- ``start_offset``: Span 的起始 token 在文本中的下标。
215+
- ``end_offset``: Span 的结束 token 在文本中下标的下一个位置。
216+
- ``label``: Span 类型。
217+
- ``relations``: 数据中包含的 Relation 标签,每个 Relation 标签包含四个字段:
218+
- ``id``: (Span1, Relation, Span2)三元组在数据集中的唯一标识 ID,不同样本中的相同三元组对应同一个 ID。
219+
- ``from_id``: Span1对应的标识 ID。
220+
- ``to_id``: Span2对应的标识 ID。
221+
- ``type``: Relation 类型。
222+
223+
224+
<a name="数据转换"></a>
225+
226+
## 7.数据转换
227+
228+
该章节详细说明如何通过`doccano.py`脚本对 doccano 平台导出的标注数据进行转换,一键生成训练/验证/测试集。
229+
230+
#### 7.1 抽取式任务数据转换
231+
232+
- 当标注完成后,在 doccano 平台上导出 `JSONL(relation)` 形式的文件,并将其重命名为 `doccano_ext.json` 后,放入 `./data` 目录下。
233+
- 通过 [doccano.py](./doccano.py) 脚本进行数据形式转换,然后便可以开始进行相应模型训练。
234+
235+
```shell
236+
python doccano.py \
237+
--doccano_file ./data/doccano_ext.json \
238+
--save_dir ./data \
239+
--negative_ratio 1
240+
```
241+
242+
可配置参数说明:
243+
244+
- ``doccano_file``: 从 doccano 导出的数据标注文件。
245+
- ``save_dir``: 训练数据的保存目录,默认存储在``data``目录下。
246+
- ``negative_ratio``: 最大负例比例,该参数只对抽取类型任务有效,适当构造负例可提升模型效果。负例数量和实际的标签数量有关,最大负例数量 = negative_ratio * 正例数量。
247+
- ``splits``: 划分数据集时训练集、验证集所占的比例。默认为[0.8, 0.1, 0.1]表示按照``8:1:1``的比例将数据划分为训练集、验证集和测试集。
248+
- ``task_type``: 选择任务类型,目前只有信息抽取这一种任务。
249+
- ``is_shuffle``: 是否对数据集进行随机打散,默认为 True。
250+
- ``seed``: 随机种子,默认为1000.
251+
- ``schema_lang``: 选择 schema 的语言,可选有`ch``en`。默认为`ch`,英文数据集请选择`en`
252+
253+
备注:
254+
- 默认情况下 [doccano.py](./doccano.py) 脚本会按照比例将数据划分为 train/dev/test 数据集
255+
- 每次执行 [doccano.py](./doccano.py) 脚本,将会覆盖已有的同名数据文件
256+
- 在模型训练阶段我们推荐构造一些负例以提升模型效果,在数据转换阶段我们内置了这一功能。可通过`negative_ratio`控制自动构造的负样本比例;负样本数量 = negative_ratio * 正样本数量。
257+
- 对于从 doccano 导出的文件,默认文件中的每条数据都是经过人工正确标注的。
258+
259+
## References
260+
- **[doccano](https://github.com/doccano/doccano)**

0 commit comments

Comments
 (0)