Datasets:

ArXiv:
License:
ghh001 commited on
Commit
61ba7a0
1 Parent(s): 797782c

Update README_ZH.md

Browse files
Files changed (1) hide show
  1. README_ZH.md +202 -171
README_ZH.md CHANGED
@@ -1,55 +1,64 @@
1
- # IEPile: Unearthing Large-Scale Schema-Based Information Extraction Corpus
2
-
3
  <p align="left">
4
  <b> <a href="https://huggingface.co/datasets/zjunlp/IEPILE/blob/main/README.md">English</a> | 简体中文 </b>
5
  </p>
6
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- - [IEPile: Unearthing Large-Scale Schema-Based Information Extraction Corpus](#iepile-unearthing-large-scale-schema-based-information-extraction-corpus)
 
 
 
9
  - [🎯1.介绍](#1介绍)
10
  - [📊2.数据](#2数据)
11
- - [2.1IEPILE的构造](#21iepile的构造)
12
- - [2.2IEPILE的数据统计分析](#22iepile的数据统计分析)
13
- - [🚴3使用IEPILE训练模型](#3使用iepile训练模型)
14
  - [3.1环境](#31环境)
15
- - [3.2下载数据](#32下载数据)
16
- - [3.3模型](#33模型)
17
- - [3.4LoRA微调训练](#34lora微调训练)
18
- - [3.4.1LoRA微调LLaMA2](#341lora微调llama2)
19
- - [3.4.3LoRA微调Baichuan2](#343lora微调baichuan2)
20
- - [3.4.3LoRA微调其他模型](#343lora微调其他模型)
21
- - [3.5模型继续训练](#35模型继续训练)
22
- - [3.5.1训练数据转换](#351训练数据转换)
23
- - [3.5.2继续训练](#352继续训练)
24
- - [4.预测](#4预测)
25
- - [4.1测试数据转换](#41测试数据转换)
26
- - [4.2IE专用模型预测](#42ie专用模型预测)
27
- - [4.3基础模型+Lora预测](#43基础模型lora预测)
28
- - [5.评估](#5评估)
29
- - [6.声明和许可](#6声明和许可)
30
- - [7.局限](#7局限)
31
 
32
 
33
  ## 🎯1.介绍
34
 
35
 
36
- **`IEPILE`** 数据集下载链接:[Google Drive](https://drive.google.com/file/d/1jPdvXOTTxlAmHkn5XkeaaCFXQkYJk5Ng/view?usp=sharing) | [Hugging Face](https://huggingface.co/datasets/zjunlp/IEPILE)
37
 
38
 
39
  > 请注意,以上提供的数据集链接中所含数据已经排除了与ACE2005数据集相关的部分。若您需要访问未经过滤的完整数据集,并且已成功获取所需的权限,敬请通过电子邮件方式联系 [email protected][email protected]。我们将提供完整数据集资源。
40
 
41
 
42
- **`LLaMA2-IEPILE`** | **`Baichuan2-IEPILE`** | **`KnowLM-IE-v2`** 模型下载链接:[zjunlp/llama2-13b-iepile-lora](https://huggingface.co/zjunlp/llama2-13b-iepile-lora/tree/main) | [zjunlp/baichuan2-13b-iepile-lora](https://huggingface.co/zjunlp/baichuan2-13b-iepile-lora) | [zjunlp/KnowLM-IE-v2]()
43
 
44
 
45
- **大型语言模型(LLMs)** 在各种领域中表现出了显著的潜力,然而,在 **信息提取(IE)** 方面,LLM存在显著的性能差距。当前IE数据集往往规模较小,分布散乱,且schema不规范。我们通过收集和清洗现有的IE数据,并采取本研究所提出的 `基于schema的指令构造方法`,成功创建了一个名为 **IEPILE** 的综合性包含约 `0.32B tokens` 的IE指令微调数据集。实验结果表明,IEPILE显著提高了LLMs在基于schema的IE上的**零样本泛化**能力。我们开源了自己的数据集和代码,为学术界提供了宝贵的支持。
46
-
47
  ![statistic](./assets/statistic.jpg)
48
 
49
- 我们总共收集了15个英文NER数据集,3个中文NER数据集,8个英文RE数据集,2个中��RE数据集,以及3个英文EE数据集和2个中文EE数据集。图1展示了这些数据集的统计信息, 覆盖了**通用**、**生物**、**金融**等众多领域。我们不仅统一了各类任务上的数据格式,而且对每个数据集进行了仔细的审计,为每个数据集创建了详细的**数据记录**,包括数据量、领域、模式等重要信息。
50
 
 
51
 
52
- 基于**IEPILE**,我们使用`Lora`技术对`Baichuan2-13B-Chat`、`LLaMA2-13B-Chat`模型进行了微调。实验结果显示, 微调后的模型`Baichuan2-IEPILE`, `LLaMA2-IEPILE` 不仅在全监督训练集上取得了可比的结果, 还在**零样本信息抽取**上取得了显著提升。
53
 
54
 
55
  ![zero_en](./assets/zero_en.jpg)
@@ -72,16 +81,17 @@
72
  ## 📊2.数据
73
 
74
 
75
- ### 2.1IEPILE的构造
76
 
77
- 我们专注于基于schema的信息抽取,因此指令中的schema的构造至关重要,因为它反映着具体抽取需求,是动态可变的。然而,现有研究在构造指令时往往采取一种较为**粗放的schema处理策略**,即利用标签集内全部schema进行指令构建。这种方法潜在地存在2个重要的问题:
78
  1. **训练和评估阶段schema询问的数量不一致,即使这些schema在内容上相似,可能损害模型的泛化能力**。若训练过程中每次询问的schema数量大约是20个,而评估时询问的是10个或30个schema,即使这些schema在内容上与训练阶段相似,模型性能仍可能受到影响。
79
  2. **指令中的schema之间的对比性不足**。语义近似的schema,如“裁员”、“离职”与“解雇”,它们的语义模糊性可能造成模型混淆。这类易混淆的模式应当在指令集中更为频繁地出现。
80
 
81
- 因此,我们提出如下解决方案:1、`轮询式的指令生成`;2、`构造难负样本字典`。
82
 
83
  ![iepile](./assets/iepile.jpg)
84
 
 
85
  <details>
86
  <summary><b>难负样本</b></summary>
87
 
@@ -99,51 +109,29 @@
99
  </details>
100
 
101
 
102
- **指令格式**
103
- `IEPILE` 的**指令**格式采纳了类JSON字符串的结构,实质上是一种字典型字符串,它由以下三个主要部分构成:
104
- (1) **`'instruction'`**,即任务描述,它概述了指令的执行目标;
105
- (2) **`'schema'`**,这是一份需提取的标签列表,明确指出了待抽取信息的关键字段;
106
- (3) **`'input'`**,指的是用于信息抽取的源文本。
107
-
108
-
109
- 以下是一条执行NER任务的指令示例:
110
- ```json
111
- {
112
- "instruction": "You are an expert in named entity recognition. Please extract entities that match the schema definition from the input. Return an empty list if the entity type does not exist. Please respond in the format of a JSON string.",
113
- "schema": ["location", "else", "organization", "person"],
114
- "input": "The objective of the Basic Course on War is to provide for combatants of the EPR basic military knowledge for the armed conflict against the police and military apparatus of the bourgeoisie."
115
- }
116
- ```
117
-
118
- 注意上面的字典应该是json字符串的格式, 这里为了直观展示, 改造成了字典格式。
119
-
120
- <details>
121
- <summary><b>更多任务</b></summary>
122
 
 
123
 
124
- ```json
125
- {
126
- "instruction": "You are an expert in relationship extraction. Please extract relationship triples that match the schema definition from the input. Return an empty list for relationships that do not exist. Please respond in the format of a JSON string.",
127
- "schema": ["children", "country capital", "country of administrative divisions", "company"],
128
- "input": "Born on May 1 , 1927 , in Brichevo , Bessarabia in the present-day Republic of Moldova , Mr. Bertini emigrated to Palestine with his family as a child and pursued musical studies there , in Milan , and in Paris , where he worked with Nadia Boulanger and Arthur Honegger."
129
- }
130
 
131
- {
132
- "instruction": "You are an expert in event extraction. Please extract events from the input that conform to the schema definition. Return an empty list for events that do not exist, and return NAN for arguments that do not exist. If an argument has multiple values, please return a list. Respond in the format of a JSON string.",
133
- "schema": [{"event_type": "pardon", "trigger": true, "arguments": ["defendant"]},{"event_type": "extradite", "trigger": true, "arguments": ["person", "agent", "destination", "origin"]}, {"event_type": "sue", "trigger": true, "arguments": ["place", "plaintiff"]}, {"event_type": "start organization", "trigger": true, "arguments": ["organization", "agent", "place"]}],
134
- "input": "Ethical and legal issues in hiring Marinello"
135
- }
136
- ```
137
 
138
- </details>
139
 
140
- [instruction.py](./ie2instruction/convert/utils/instruction.py) 中提供了各个任务的指令
 
 
 
141
 
142
 
 
143
 
144
- ### 2.2IEPILE的数据统计分析
145
- 我们基于上述方法,形成了一个高质量的信息抽取指令数据集,即 **`IEPILE`**。此数据集大约蕴含**200多万**条指令数据,每一条指令数据均包含`instruction`及`output`两个字段,可直接用于监督式微调模型的训练。就存储量而言,IEPILE占据大约**3GB**的磁盘空间,包含约**3.2亿**个token(使用baichuan2 tokenizer)。
146
 
 
147
 
148
  ```json
149
  {
@@ -154,81 +142,78 @@
154
  }
155
  ```
156
 
157
- <details>
158
- <summary><b>更多任务</b></summary>
159
-
160
 
161
- ```json
162
 
163
 
164
- {
165
- "task": "EE",
166
- "source": "PHEE",
167
- "instruction": "{\"instruction\": \"You are an expert in event extraction. Please extract events from the input that conform to the schema definition. Return an empty list for events that do not exist, and return NAN for arguments that do not exist. If an argument has multiple values, please return a list. Respond in the format of a JSON string.\", \"schema\": [{\"event_type\": \"potential therapeutic event\", \"trigger\": true, \"arguments\": [\"Treatment.Time_elapsed\", \"Treatment.Route\", \"Treatment.Freq\", \"Treatment\", \"Subject.Race\", \"Treatment.Disorder\", \"Effect\", \"Subject.Age\", \"Combination.Drug\", \"Treatment.Duration\", \"Subject.Population\", \"Subject.Disorder\", \"Treatment.Dosage\", \"Treatment.Drug\"]}, {\"event_type\": \"adverse event\", \"trigger\": true, \"arguments\": [\"Subject.Population\", \"Subject.Age\", \"Effect\", \"Treatment.Drug\", \"Treatment.Dosage\", \"Treatment.Freq\", \"Subject.Gender\", \"Treatment.Disorder\", \"Subject\", \"Treatment\", \"Treatment.Time_elapsed\", \"Treatment.Duration\", \"Subject.Disorder\", \"Subject.Race\", \"Combination.Drug\"]}], \"input\": \"Our findings reveal that even in patients without a history of seizures, pregabalin can cause a cortical negative myoclonus.\"}",
168
- "output": "{\"potential therapeutic event\": [], \"adverse event\": [{\"trigger\": \"cause \", \"arguments\": {\"Subject.Population\": \"NAN\", \"Subject.Age\": \"NAN\", \"Effect\": \"cortical negative myoclonus\", \"Treatment.Drug\": \"pregabalin\", \"Treatment.Dosage\": \"NAN\", \"Treatment.Freq\": \"NAN\", \"Subject.Gender\": \"NAN\", \"Treatment.Disorder\": \"NAN\", \"Subject\": \"patients without a history of seizures\", \"Treatment\": \"pregabalin\", \"Treatment.Time_elapsed\": \"NAN\", \"Treatment.Duration\": \"NAN\", \"Subject.Disorder\": \"NAN\", \"Subject.Race\": \"NAN\", \"Combination.Drug\": \"NAN\"}}]}"
169
- }
170
 
 
171
  {
172
  "task": "RE",
173
  "source": "NYT11",
174
  "instruction": "{\"instruction\": \"You are an expert in relationship extraction. Please extract relationship triples that match the schema definition from the input. Return an empty list for relationships that do not exist. Please respond in the format of a JSON string.\", \"schema\": [\"neighborhood of\", \"nationality\", \"children\", \"place of death\"], \"input\": \" In the way New Jersey students know that Thomas Edison 's laboratory is in West Orange , the people of Colma know that Wyatt Earp 's ashes are buried at Hills of Eternity , a Jewish cemetery he was n't ; his wife was , and that Joe DiMaggio is at Holy Cross Cemetery , where visitors often lean bats against his gravestone . \"}",
175
  "output": "{\"neighborhood of\": [], \"nationality\": [], \"children\": [], \"place of death\": [{\"subject\": \"Thomas Edison\", \"object\": \"West Orange\"}]}"
176
  }
 
 
 
 
 
 
 
177
  ```
178
 
179
  </details>
180
 
181
 
182
- 各字段的说明:
183
-
184
- |字段|说明|
185
- |:---------:|:----------------------------------------------------------:|
186
- |task|该实例所示的任务, (NER、RE、EE、EET、EEA) 5种任务之一。|
187
- |source| 该实例所示的数据集|
188
- |instruction|输入模型的指令,经过json.dumps处理成JSON字符串,包括`"instruction"`, `"schema"`, `"input"`三个字段|
189
- |output|模型的输出,采用字典的json字符串的格式,key是schema,value是抽取出的内容|
190
-
191
-
192
 
193
 
194
- ## 🚴3使用IEPILE训练模型
195
 
196
  ### 3.1环境
197
 
198
  在开始之前,请确保按照下面的指导创建适当的**虚拟环境**:
199
 
200
  ```bash
201
- conda create -n IEPILE python=3.9 # 创建虚拟环境
202
- conda activate IEPILE # 激活环境
203
  pip install -r requirements.txt # 安装依赖
204
  ```
205
 
206
- ### 3.2下载数据
207
 
208
- **`IEPILE`** 数据集下载链接:[Google Drive](https://drive.google.com/file/d/1jPdvXOTTxlAmHkn5XkeaaCFXQkYJk5Ng/view?usp=sharing) | [Hugging Face](https://huggingface.co/datasets/zjunlp/IEPILE)
209
 
210
- ```bash
211
- mkdir results
212
- mkdir lora
213
- mkdir data
214
  ```
215
 
216
- 数据放在目录 `./data` 中。
 
217
 
 
218
 
219
- ### 3.3模型
220
 
221
- 以下是本仓库代码支持的一些模型:
222
- ["`llama`", "`alpaca`", "`vicuna`", "`zhixi`", "`falcon`", "`baichuan`", "`chatglm`", "`qwen`", "`moss`", "`openba`"]
223
 
224
- **`LLaMA2-IEPILE`** | **`Baichuan2-IEPILE`** | **`KnowLM-IE-v2`** 模型下载链接:[zjunlp/llama2-13b-iepile-lora](https://huggingface.co/zjunlp/llama2-13b-iepile-lora/tree/main) | [zjunlp/baichuan2-13b-iepile-lora](https://huggingface.co/zjunlp/baichuan2-13b-iepile-lora) | [zjunlp/KnowLM-IE-v2]()
225
 
226
 
227
- ### 3.4LoRA微调训练
 
 
 
 
 
228
 
229
- #### 3.4.1LoRA微调LLaMA2
230
 
231
- > 重要提示:以下的所有命令均应在IEPILE目录下执行。例如,如果您想运行微调脚本,您应该使用如下命令:bash ft_scripts/fine_llama.bash。请确保您的当前工作目录正确。
 
 
232
 
233
 
234
  ```bash
@@ -262,46 +247,43 @@ CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7" torchrun --nproc_per_node=8 --master_port
262
  --lora_r 16 \
263
  --lora_alpha 32 \
264
  --lora_dropout 0.05 \
265
- --bf16
 
266
  ```
267
 
 
 
 
 
 
 
 
 
 
268
 
269
- * `--model_name`: 指定您想要使用的**模型名称**。当前支持的模型列表包括:["`llama`", "`alpaca`", "`vicuna`", "`zhixi`", "`falcon`", "`baichuan`", "`chatglm`", "`qwen`", "`moss`", "`openba`"]。**请注意**,此参数应与 `--model_name_or_path` 区分。
270
- * `--model_name_or_path`: 模型参数路径, 请到[HuggingFace](https://huggingface.co/models)下载相应模型。
271
- * `--template`: 使用的**模板名称**,包括:`alpaca`, `baichuan`, `baichuan2`, `chatglm3`等, 请参考[src/datamodule/template.py](./src/datamodule/template.py)查看所有支持的模版名称,默认使用的是`alpaca`模板。
272
- * `--train_file`, `--valid_file`(可选): 分别指向训练集和验证集的**文件路径**。如果未提供 valid_file,系统将默认从 train_file 指定的文件中划分出 val_set_size 指定数量的样本作为验证集。您也可以通过调整 val_set_size 参数来改变**验证集的样本数量**。注意:目前的训练、验证、测试文件的格式只支持**json格式**。
273
- * `--output_dir``: 设置LoRA微调后的**权重参数保存路径**。
274
- * `--val_set_size`: 定义**验证集的样本数量**,默认为1000。
275
- * `per_device_train_batch_size`, `per_device_eval_batch_size`: 每台GPU设备上的batch_size, RTX3090建议设置2~4。
276
- * `max_source_length`, `max_target_length`, `cutoff_len`: 最大输入长度、最大输出长度、截断长度, 截断长度可以简单地视作最大输入长度 + 最大输出长度, 需根据具体需求和显存大小设置合适值。
277
 
278
  * 要了解更多关于**参数配置**的信息,请参考 [src/utils/args](./src/args) 目录。
279
 
280
 
281
- 微调LLaMA2模型的具体脚本可以在 [ft_scripts/fine_llama.bash](./ft_scripts/fine_llama.bash) 中找到。
282
 
 
283
 
284
- #### 3.4.3LoRA微调Baichuan2
285
 
286
- 微调Baichuan2模型的具体脚本可以在 [ft_scripts/fine_baichuan.bash](./ft_scripts/fine_baichuan.bash) 中找到。
287
 
 
288
 
289
- #### 3.4.3LoRA微调其他模型
290
 
291
- 微调其他模型只需调整`--model_name`, `--template`两个参数, 例如: 对于`alpaca`模型设置`--model_name alpaca`, `--template alpaca`, 对于`chatglm3`模型设置`--model_name chatglm`, `--template chatglm3`。
292
 
293
-
294
- ### 3.5模型继续训练
295
-
296
- 尽管 `Baichuan2-IEPILE` 和 `LLaMA2-IEPILE` 模型已在多个通用数据集上接受了广泛的指令微调,并因此获得了一定的通用信息抽取能力,但它们在特定领域(如`法律`、`教育`、`科学`、`电信`)的数据处理上可能仍显示出一定的局限性。针对这一挑战,建议对这些模型在特定领域的数据集上进行二次训练。这将有助于模型更好地适应特定领域的语义和结构特征,从而显著增强其在该领域内的信息抽取能力。
297
-
298
-
299
- #### 3.5.1训练数据转换
300
 
301
  首先, 需要将**数据格式化**以包含`instruction`、`output`字段。为此,我们提供了一个脚本 [convert_func.py](./ie2instruction/convert_func.py),它可以将数据批量转换成模型可以直接使用的格式。
302
 
303
- > 在使用 [convert_func.py](./ie2instruction/convert_func.py) 脚本之前,请确保参考了 [data](./data) 目录。该目录详细说明了每种任务所需的数据格式要求。请参考 `sample.json` 以了解转换前数据的格式,`schema.json` 则展示了 schema 的组织结构,而 `train.json` 则描述了转换后的数据格式。
304
 
 
305
 
306
 
307
  ```bash
@@ -316,32 +298,71 @@ python ie2instruction/convert_func.py \
316
  --split train
317
  ```
318
 
319
- * `--language`: 支持`zh`, `en`两种语言, 不同语言使用的指令模版不同。
320
- * `--task`: 目前支持['RE', 'NER', 'EE', 'EET', 'EEA']五类任务。
321
- * `--split_num`: 单个指令中最大schema数量。默认为4, -1表示不切分, 各个任务推荐的切分数量不同: NER:6, RE:4, EE:4, EET:4, EEA:4
322
- * `--random_sort`: 是否对指令中的schema随机排序, 默认为False, 即按字母顺序排序。
323
- * `--split`: 表示构造的数据类型, ['train', 'test'], `train`会包含转换后的`output`, `test`则是`label`。
 
 
 
 
324
 
325
- 转换后的训练数据将具有 `task`, `source`, `instruction`, `output` 4个字段, 可参考[2.2IEPILE的数据统计分析](./README.md#22iepile的数据统计分析)查看各字段格式和作用。
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
 
328
- #### 3.5.2继续训练
329
 
330
- * 如果是从微调后的lora权重继续训练则只需要设置 `--checkpoint_dir` 参数为微调后lora权重路径, 例如`'zjunlp/llama2-13b-iepile-lora'`。
331
 
332
- * 如果是从微调后的模型权重继续训练只需要设置 `--model_name_or_path` 参数为微调后模型权重路径, 例如`'zjunlp/KnowLM-IE-v2'`。
333
 
334
 
335
- 从微调后的lora权重继续训练的具体脚本可以在 [ft_scripts/fine_continue.bash](./ft_scripts/fine_continue.bash) 中找到。
336
 
337
 
338
- ## 4.预测
339
 
340
- ### 4.1测试数据转换
341
 
342
- 在对模型进行数据输入之前,需要将**数据格式化**以包含`instruction`字段。为此,我们提供了一个脚本 [kg2instruction/convert_func.py](./kg2instruction/convert_func.py),它可以将数据批量转换成模型可以直接使用的格式。
343
 
344
- > 在使用 [kg2instruction/convert_func.py](./kg2instruction/convert_func.py) 脚本之前,请确保参考了 [data](./data) 目录。该目录详细说明了每种任务所需的数据格式要求。请参考 sample.json 以了解转换前数据的格式,schema.json 则展示了 schema 的组织结构,而 test.json 则描述了转换后的数据格式。
345
 
346
 
347
  ```bash
@@ -355,26 +376,25 @@ python ie2instruction/convert_func.py \
355
  --split test
356
  ```
357
 
358
- * `--language`: 支持`zh`, `en`两种语言, 不同语言使用的指令模版不同。
359
- * `--task`: 目前支持['RE', 'NER', 'EE', 'EET', 'EEA']五类任务。
360
- * `--split_num`: 单个指令中最大schema数量。默认为4, -1表示不切分, 各个任务推荐的切分数量不同: NER:6, RE:4, EE:4, EET:4, EEA:4。
361
- * `--random_sort`: 是否对指令中的schema随机排序, 默认为False, 即按字母顺序排序。
362
- * `--split`: 表示构造的数据类型, ['train', 'test'], `train`会包含转换后的`output`, `test`则是`label`。
363
 
364
- 转换后的测试数据将具有`id`, `instruction`, `label` 3个字段。
365
 
366
 
367
- ### 4.2IE专用模型预测
 
368
 
369
  ```bash
370
  CUDA_VISIBLE_DEVICES=0 python src/inference.py \
371
  --stage sft \
372
- --model_name_or_path 'zjunlp/KnowLM-IE-v2' \
373
- --model_name 'baichuan' \
374
- --template 'baichuan2' \
 
375
  --do_predict \
376
  --input_file 'data/input.json' \
377
- --output_file 'results/KnowLM-IE-v2_output.json' \
 
378
  --output_dir 'lora/test' \
379
  --predict_with_generate \
380
  --max_source_length 512 \
@@ -382,36 +402,39 @@ CUDA_VISIBLE_DEVICES=0 python src/inference.py \
382
  --max_new_tokens 300
383
  ```
384
 
385
- * `--model_name`, `--template`, `--bf16`应该与训练时保持一致。
386
- * `--output_dir`: 无意义随便设置一个路径。
387
- * `--input_file`, `--output_file`: 输入的测试文件路径, 预测输出文件路径。
388
- * `--max_source_length`, `--max_new_tokens`: 最大输入、输出长度, 根据设备条件调整。
 
 
389
 
 
390
 
391
- ### 4.3基础模型+Lora预测
392
 
393
  ```bash
394
  CUDA_VISIBLE_DEVICES=0 python src/inference.py \
395
  --stage sft \
396
- --model_name_or_path 'models/llama2-13B-Chat' \
397
- --checkpoint_dir 'zjunlp/llama2-13b-iepile-lora' \
398
- --model_name 'llama' \
399
- --template 'llama2' \
400
  --do_predict \
401
  --input_file 'data/input.json' \
402
- --output_file 'results/llama2-13b-iepile-lora_output.json' \
403
- --finetuning_type lora \
404
  --output_dir 'lora/test' \
405
  --predict_with_generate \
406
  --max_source_length 512 \
407
  --bf16 \
408
- --max_new_tokens 300
409
  ```
410
 
411
- * `--checkpoint_dir`: 训练后lora权重路径。
 
 
412
 
413
 
414
- ## 5.评估
415
 
416
  我们提供了评估各个任务F1分数的脚本。
417
 
@@ -421,21 +444,29 @@ python ie2instruction/eval_func.py \
421
  --task NER
422
  ```
423
 
424
- * `--task`: 目前支持['RE', 'NER', 'EE', 'EET', 'EEA']五类任务。
 
425
 
426
 
427
- # 6.声明和许可
428
 
429
- 我们认为标注数据蕴含着人类的智慧宝库,它的存在是为了促进全人类的利益,并有助于提升我们的生活质量。我们强烈敦促所有的用户不要将我们的语料库用于任何可能对国家或公共安全造成伤害、违反法律法规的行为。
430
 
 
431
  我们竭尽所能地保证所提供数据的质量与其合法性。但我们也意识到,尽管如此,可能还是存在一些不可预见的问题,诸如数据保护的担忧以及数据被滥用可能引起的风险和问题。对于这些潜在的问题,我们将不承担责任。
 
432
 
433
- 对于那些受限于比[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en)协议更为严格的使用许可的原始数据,IEPILE将恪守那些较为严格的条款。在其他所有情形下,我们的操作将基于[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en)许可协议。
434
 
435
 
436
- # 7.局限
437
 
438
  从数据角度来看,我们的研究主要集中在基于schema的信息提取(IE)上,这限制了我们将研究成果推广至不遵循我们特定格式要求的人类指令的能力。此外,我们没有探索开放信息提取(Open IE)领域;然而,如果我们去除schema约束,我们的数据集将适用于开放信息提取场景。此外,我们的数据集目前仅包含英语和中文数据,在未来,我们希望能够包含更多语言的数据。
439
-
440
  从模型的角度来看,由于计算资源的限制,我们的研究仅评估了两个模型:Baichuan和LLaMA,以及一些基线模型。我们的数据集可以应用于任何其他的大型语言模型(LLMs),如Qwen、ChatGLM。
441
 
 
 
 
 
 
 
 
 
 
 
 
1
  <p align="left">
2
  <b> <a href="https://huggingface.co/datasets/zjunlp/IEPILE/blob/main/README.md">English</a> | 简体中文 </b>
3
  </p>
4
 
5
+ # IEPile:大规模信息提取语料库
6
+
7
+ 这是论文 [IEPile: Unearthing Large-Scale Schema-Based Information Extraction Corpus](https://arxiv.org/abs/2402.14710) 的官方仓库
8
+
9
+
10
+ [**数据集**](https://huggingface.co/datasets/zjunlp/iepie) |
11
+ [**论文**](https://huggingface.co/papers/2402.14710) |
12
+ [**使用方法**](./README_CN.md#🚴3使用IEPile训练模型) |
13
+ [**局限性**](./README_CN.md#7局限) |
14
+ [**声明和许可**](./README_CN.md#6声明和许可) |
15
+ [**引用**](./README_CN.md#)
16
 
17
+ > 请注意,我们的IEPile可能会进行**更新**(一旦发布更新,我们将通知您)。建议使用最新版本。
18
+
19
+
20
+ - [IEPile:大规模信息提取语料库](#iepile大规模信息提取语料库)
21
  - [🎯1.介绍](#1介绍)
22
  - [📊2.数据](#2数据)
23
+ - [2.1IEPile的构造](#21iepile的构造)
24
+ - [2.2IEPile的数据格式](#22iepile的数据格式)
25
+ - [🚴3.使用IEPile训练模型](#3使用iepile训练模型)
26
  - [3.1环境](#31环境)
27
+ - [3.2下载数据和模型](#32下载数据和模型)
28
+ - [3.3LoRA微调](#33lora微调)
29
+ - [🔁4.领域内数据继续训练](#4领域内数据继续训练)
30
+ - [4.1训练数据转换](#41训练数据转换)
31
+ - [4.2继续训练](#42继续训练)
32
+ - [👓5.预测](#5预测)
33
+ - [5.1测试数据转换](#51测试数据转换)
34
+ - [5.2基础模型+Lora预测](#52基础模型lora预测)
35
+ - [5.3IE专用模型预测](#53ie专用模型预测)
36
+ - [6.评估](#6评估)
37
+ - [7.声明和许可](#7声明和许可)
38
+ - [8.局限](#8局限)
39
+ - [9.引用](#9引用)
40
+ - [10. 致谢](#10-致谢)
 
 
41
 
42
 
43
  ## 🎯1.介绍
44
 
45
 
46
+ **`IEPile`** 数据集下载链接:[Google Drive](https://drive.google.com/file/d/1jPdvXOTTxlAmHkn5XkeaaCFXQkYJk5Ng/view?usp=sharing) | [Hugging Face](https://huggingface.co/datasets/zjunlp/iepile)
47
 
48
 
49
  > 请注意,以上提供的数据集链接中所含数据已经排除了与ACE2005数据集相关的部分。若您需要访问未经过滤的完整数据集,并且已成功获取所需的权限,敬请通过电子邮件方式联系 [email protected][email protected]。我们将提供完整数据集资源。
50
 
51
 
52
+ **`LLaMA2-IEPile`** | **`Baichuan2-IEPile`** | **`KnowLM-IE-v2`** 模型下载链接:[zjunlp/llama2-13b-iepile-lora](https://huggingface.co/zjunlp/llama2-13b-iepile-lora/tree/main) | [zjunlp/baichuan2-13b-iepile-lora](https://huggingface.co/zjunlp/baichuan2-13b-iepile-lora) | [zjunlp/KnowLM-IE-v2]()
53
 
54
 
 
 
55
  ![statistic](./assets/statistic.jpg)
56
 
57
+ 我们精心收集并清洗了现有的信息提取(IE)数据,共整合了`26`个英文IE数据集和`7`个中文IE数据集。如图1所示,这些数据集覆盖了包括**通用**、**医学**、**金融**等多个领域。
58
 
59
+ 本研究采用了所提出的“`基于schema的轮询指令构造方法`”,成功创建了一个名为 **IEPile** 的大规模高质量IE微调数据集,包含约`0.32B` tokens。
60
 
61
+ 基于**IEPile**,我们对 `Baichuan2-13B-Chat` 和 `LLaMA2-13B-Chat` 模型应用了 `Lora` 技术进行了微调。实验证明,微调后的 `Baichuan2-IEPile` `LLaMA2-IEPile` 模型在全监督训练集上成绩斐然,并且在**零样本信息提取任务**中取得了显著进步。
62
 
63
 
64
  ![zero_en](./assets/zero_en.jpg)
 
81
  ## 📊2.数据
82
 
83
 
84
+ ### 2.1IEPile的构造
85
 
86
+ 我们专注于**基于指令的信息抽取**,因此指令中的schema的构造至关重要,因为它反映着具体抽取需求,是动态可变的。然而,现有研究在构造指令时往往采取一种**较为粗放的schema处理策略**,即利用标签集内**全部schema**进行指令构建。这种方法潜在地存在2个重要的问题:
87
  1. **训练和评估阶段schema询问的数量不一致,即使这些schema在内容上相似,可能损害模型的泛化能力**。若训练过程中每次询问的schema数量大约是20个,而评估时询问的是10个或30个schema,即使这些schema在内容上与训练阶段相似,模型性能仍可能受到影响。
88
  2. **指令中的schema之间的对比性不足**。语义近似的schema,如“裁员”、“离职”与“解雇”,它们的语义模糊性可能造成模型混淆。这类易混淆的模式应当在指令集中更为频繁地出现。
89
 
90
+ 因此,我们提出如下解决方案:1、`构造难负样本字典`;2、`轮询式的指令生成`。
91
 
92
  ![iepile](./assets/iepile.jpg)
93
 
94
+
95
  <details>
96
  <summary><b>难负样本</b></summary>
97
 
 
109
  </details>
110
 
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ ### 2.2IEPile的数据格式
114
 
115
+ `IEPile` 中的每条数据均包含 `task`, `source`, `instruction`, `output` 4个字段, 以下是各字段的说明
 
 
 
 
 
116
 
117
+ | 字段 | 说明 |
118
+ | :---: | :---: |
119
+ | task | 该实例所属的任务, (`NER`、`RE`、`EE`、`EET`、`EEA`) 5种任务之一。 |
120
+ | source | 该实例所属的数据集 |
121
+ | instruction | 输入模型的指令, 经过json.dumps处理成JSON字符串, 包括`"instruction"`, `"schema"`, `"input"`三个字段 |
122
+ | output | 输出, 采用字典的json字符串的格式, key是schema, value是抽取出的内容 |
123
 
 
124
 
125
+ 在`IEPile`中, **`instruction`** 的格式采纳了类JSON字符串的结构,实质上是一种字典型字符串,它由以下三个主要部分构成:
126
+ (1) **`'instruction'`**: 任务描述, 它概述了指令的执行任务(`NER`、`RE`、`EE`、`EET`、`EEA`之一)。
127
+ (2) **`'schema'`**: 待抽取的schema(`实体类型`, `关系类型`, `事件类型`)列表。
128
+ (3) **`'input'`**: 待抽取的文本。
129
 
130
 
131
+ [instruction.py](./ie2instruction/convert/utils/instruction.py) 中提供了各个任务的指令模版。
132
 
 
 
133
 
134
+ 以下是一条**数据实例**:
135
 
136
  ```json
137
  {
 
142
  }
143
  ```
144
 
145
+ 该数据实例所属任务是 `NER`, 所属数据集是 `CoNLL2003`, 待抽取的schema列表是 ["`person`", "`organization`", "`else`", "`location`"], 待抽取的文本是 "*284 Robert Allenby ( Australia ) 69 71 71 73 , Miguel Angel Martin ( Spain ) 75 70 71 68 ( Allenby won at first play-off hole )*", 输出是 `{"person": ["Robert Allenby", "Allenby", "Miguel Angel Martin"], "organization": [], "else": [], "location": ["Australia", "Spain"]}`
 
 
146
 
147
+ > 注意输出中的 schema 顺序与 instruction 中的 schema 顺序一致
148
 
149
 
150
+ <details>
151
+ <summary><b>更多任务的数据实例</b></summary>
 
 
 
 
152
 
153
+ ```json
154
  {
155
  "task": "RE",
156
  "source": "NYT11",
157
  "instruction": "{\"instruction\": \"You are an expert in relationship extraction. Please extract relationship triples that match the schema definition from the input. Return an empty list for relationships that do not exist. Please respond in the format of a JSON string.\", \"schema\": [\"neighborhood of\", \"nationality\", \"children\", \"place of death\"], \"input\": \" In the way New Jersey students know that Thomas Edison 's laboratory is in West Orange , the people of Colma know that Wyatt Earp 's ashes are buried at Hills of Eternity , a Jewish cemetery he was n't ; his wife was , and that Joe DiMaggio is at Holy Cross Cemetery , where visitors often lean bats against his gravestone . \"}",
158
  "output": "{\"neighborhood of\": [], \"nationality\": [], \"children\": [], \"place of death\": [{\"subject\": \"Thomas Edison\", \"object\": \"West Orange\"}]}"
159
  }
160
+
161
+ {
162
+ "task": "EE",
163
+ "source": "PHEE",
164
+ "instruction": "{\"instruction\": \"You are an expert in event extraction. Please extract events from the input that conform to the schema definition. Return an empty list for events that do not exist, and return NAN for arguments that do not exist. If an argument has multiple values, please return a list. Respond in the format of a JSON string.\", \"schema\": [{\"event_type\": \"potential therapeutic event\", \"trigger\": true, \"arguments\": [\"Treatment.Time_elapsed\", \"Treatment.Route\", \"Treatment.Freq\", \"Treatment\", \"Subject.Race\", \"Treatment.Disorder\", \"Effect\", \"Subject.Age\", \"Combination.Drug\", \"Treatment.Duration\", \"Subject.Population\", \"Subject.Disorder\", \"Treatment.Dosage\", \"Treatment.Drug\"]}, {\"event_type\": \"adverse event\", \"trigger\": true, \"arguments\": [\"Subject.Population\", \"Subject.Age\", \"Effect\", \"Treatment.Drug\", \"Treatment.Dosage\", \"Treatment.Freq\", \"Subject.Gender\", \"Treatment.Disorder\", \"Subject\", \"Treatment\", \"Treatment.Time_elapsed\", \"Treatment.Duration\", \"Subject.Disorder\", \"Subject.Race\", \"Combination.Drug\"]}], \"input\": \"Our findings reveal that even in patients without a history of seizures, pregabalin can cause a cortical negative myoclonus.\"}",
165
+ "output": "{\"potential therapeutic event\": [], \"adverse event\": [{\"trigger\": \"cause \", \"arguments\": {\"Subject.Population\": \"NAN\", \"Subject.Age\": \"NAN\", \"Effect\": \"cortical negative myoclonus\", \"Treatment.Drug\": \"pregabalin\", \"Treatment.Dosage\": \"NAN\", \"Treatment.Freq\": \"NAN\", \"Subject.Gender\": \"NAN\", \"Treatment.Disorder\": \"NAN\", \"Subject\": \"patients without a history of seizures\", \"Treatment\": \"pregabalin\", \"Treatment.Time_elapsed\": \"NAN\", \"Treatment.Duration\": \"NAN\", \"Subject.Disorder\": \"NAN\", \"Subject.Race\": \"NAN\", \"Combination.Drug\": \"NAN\"}}]}"
166
+ }
167
  ```
168
 
169
  </details>
170
 
171
 
 
 
 
 
 
 
 
 
 
 
172
 
173
 
174
+ ## 🚴3.使用IEPile训练模型
175
 
176
  ### 3.1环境
177
 
178
  在开始之前,请确保按照下面的指导创建适当的**虚拟环境**:
179
 
180
  ```bash
181
+ conda create -n IEPile python=3.9 # 创建虚拟环境
182
+ conda activate IEPile # 激活环境
183
  pip install -r requirements.txt # 安装依赖
184
  ```
185
 
186
+ ### 3.2下载数据和模型
187
 
188
+ **`IEPile`** 数据集下载链接:[Google Drive](https://drive.google.com/file/d/1jPdvXOTTxlAmHkn5XkeaaCFXQkYJk5Ng/view?usp=sharing) | [Hugging Face](https://huggingface.co/datasets/zjunlp/IEPile)
189
 
190
+ ```python
191
+ IEPile
192
+ ├── train.json # 训练集
193
+ └── dev.json # 验证集
194
  ```
195
 
196
+ 以下是本仓库代码支持的一些基础模型:[[llama](https://huggingface.co/meta-llama), [alpaca](https://github.com/tloen/alpaca-lora), [vicuna](https://huggingface.co/lmsys), [zhixi](https://github.com/zjunlp/KnowLM), [falcon](https://huggingface.co/tiiuae), [baichuan](https://huggingface.co/baichuan-inc), [chatglm](https://huggingface.co/THUDM), [qwen](https://huggingface.co/Qwen), [moss](https://huggingface.co/fnlp), [openba](https://huggingface.co/OpenBA)]
197
+
198
 
199
+ **`LLaMA2-IEPile`** | **`Baichuan2-IEPile`** | **`KnowLM-IE-v2`** 模型下载链接:[zjunlp/llama2-13b-IEPile-lora](https://huggingface.co/zjunlp/llama2-13b-IEPile-lora/tree/main) | [zjunlp/baichuan2-13b-IEPile-lora](https://huggingface.co/zjunlp/baichuan2-13b-IEPile-lora) | [zjunlp/KnowLM-IE-v2]()
200
 
 
201
 
202
+ **`LLaMA2-IEPile`**, **`Baichuan2-IEPile`** 是IEPILE论文中涉及的在 `LLaMA2-13B-Chat`, `Baichuan2-13B-Chat` 上Lora微调得到的两个模型。
 
203
 
 
204
 
205
 
206
+ ```bash
207
+ mkdir data # 数据放这
208
+ mkdir mdoels # 基础模型放这
209
+ mkdir results # 预测结果放这
210
+ mkdir lora # lora微调结果放这
211
+ ```
212
 
 
213
 
214
+ ### 3.3LoRA微调
215
+
216
+ > 重要提示:以下的所有命令均应在`IEPile`目录下执行。例如,如果您想运行微调脚本,您应该使用如下命令:bash ft_scripts/fine_llama.bash。请确保您的当前工作目录正确。
217
 
218
 
219
  ```bash
 
247
  --lora_r 16 \
248
  --lora_alpha 32 \
249
  --lora_dropout 0.05 \
250
+ --bf16 \
251
+ --deepspeed configs/ds_config_bf16.json
252
  ```
253
 
254
+ * `model_name`: 指定所需的**模型架构名称**(7B、13B、Base、Chat属于同一模型架构)。当前支持的模型包括:["`llama`", "`alpaca`", "`vicuna`", "`zhixi`", "`falcon`", "`baichuan`", "`chatglm`", "`qwen`", "`moss`", "`openba`"]。**请注意**,此参数应与 `--model_name_or_path` 区分。
255
+ * `model_name_or_path`: 模型路径, 请到 [HuggingFace](https://huggingface.co/models) 下载相应模型。
256
+ * `template`: 使用的**模板名称**,包括:`alpaca`, `baichuan`, `baichuan2`, `chatglm3`等, 请参考 [src/datamodule/template.py](./src/datamodule/template.py) 查看所有支持的模版名称, 默认使用的是`alpaca`模板, **`Chat`版本的模型建议使用配套的模版, Base版本模型可默认使用`alpaca`**。
257
+ * `train_file`, `valid_file(可选)`: 训练集和验证集的**文件路径**。注意:目前仅支持json格式的文件。
258
+ * `output_dir`: LoRA微调后的**权重参数保存路径**。
259
+ * `val_set_size`: **验证集的样本数量**, 默认为1000。
260
+ * `per_device_train_batch_size`, `per_device_eval_batch_size`: 每台GPU设备上的`batch_size`, 根据显存大小调整。
261
+ * `max_source_length`, `max_target_length`, `cutoff_len`: 最大输入、输出长度、截断长度, 截断长度可以简单地视作最大输入长度 + 最大输出长度, 需根据具体需求和显存大小设置合适值。
262
+ * `deepspeed`: 设备资源不够可去掉。
263
 
264
+ > 可通过设置 `bits` = 8 4 进行量化。
 
 
 
 
 
 
 
265
 
266
  * 要了解更多关于**参数配置**的信息,请参考 [src/utils/args](./src/args) 目录。
267
 
268
 
269
+ 微调`LLaMA2-13B-Chat`模型的具体脚本可以在 [ft_scripts/fine_llama.bash](./ft_scripts/fine_llama.bash) 中找到。
270
 
271
+ 微调`Baichuan2-13B-Chat`模型的具体脚本可以在 [ft_scripts/fine_baichuan.bash](./ft_scripts/fine_baichuan.bash) 中找到。
272
 
 
273
 
 
274
 
275
+ ## 🔁4.领域内数据继续训练
276
 
277
+ 尽管 `Baichuan2-IEPile` 和 `LLaMA2-IEPile` 模型已在多个通用数据集上接受了广泛的指令微调,并因此获得了一定的**通用信息抽取能力**,但它们在**特定领域**(如`法律`、`教育`、`科学`、`电信`)的数据处理上可能仍显示出一定的局限性。针对这一挑战,建议对这些模型在特定领域的数据集上进行**二次训练**。这将有助于模型更好地适应特定领域的语义和结构特征,从而显著增强其在**该领域内的信息抽取能力**。
278
 
 
279
 
280
+ #### 4.1训练数据转换
 
 
 
 
 
 
281
 
282
  首先, 需要将**数据格式化**以包含`instruction`、`output`字段。为此,我们提供了一个脚本 [convert_func.py](./ie2instruction/convert_func.py),它可以将数据批量转换成模型可以直接使用的格式。
283
 
284
+ > 在使用 [convert_func.py](./ie2instruction/convert_func.py) 脚本之前,请确保参考了 [data](./data) 目录。该目录详细说明了每种任务所需的数据格式要求。 `sample.json` 描述了转换前数据的格式,`schema.json` 展示了 schema 的组织结构, `train.json` 描述了转换后的数据格式。
285
 
286
+ > 此外,可直接使用包含12个主题(如人物、交通工具、艺术作品、自然科学、人造物品、天文对象等)的中英双语信息抽取数据集 [zjunlp/InstructIE](https://huggingface.co/datasets/zjunlp/InstructIE)。
287
 
288
 
289
  ```bash
 
298
  --split train
299
  ```
300
 
301
+ * `language`: 支持`zh`, `en`两种语言, 不同语言使用的指令模版不同。
302
+ * `task`: 目前支持['`RE`', '`NER`', '`EE`', '`EET`', '`EEA`']五类任务。
303
+ * `split_num`: 定义单个指令中可包含的最大schema数目。默认值为4,设置为-1则不进行切分。推荐的任务切分数量依任务而异:**NER建议为6REEEEETEEA均推荐为4**。
304
+ * `random_sort`: 是否对指令中的schema随机排序, 默认为False, 即按字母顺序排序。
305
+ * `split`: 指定数据集类型,可选`train`或`test`。
306
+
307
+ 转换后的训练数据将包含 `task`, `source`, `instruction`, `output` 四个字段。
308
+
309
+
310
 
311
+ #### 4.2继续训练
312
 
313
+ ```bash
314
+ output_dir='lora/llama2-13b-chat-v1-continue'
315
+ mkdir -p ${output_dir}
316
+ CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7" torchrun --nproc_per_node=8 --master_port=1287 src/test_finetune.py \
317
+ --do_train --do_eval \
318
+ --overwrite_output_dir \
319
+ --model_name_or_path 'models/llama2-13B-Chat' \
320
+ --checkpoint_dir 'zjunlp/llama2-13b-iepile-lora' \
321
+ --stage 'sft' \
322
+ --model_name 'llama' \
323
+ --template 'llama2' \
324
+ --train_file 'data/train.json' \
325
+ --valid_file 'data/dev.json' \
326
+ --output_dir=${output_dir} \
327
+ --per_device_train_batch_size 24 \
328
+ --per_device_eval_batch_size 24 \
329
+ --gradient_accumulation_steps 4 \
330
+ --preprocessing_num_workers 16 \
331
+ --num_train_epochs 10 \
332
+ --learning_rate 5e-5 \
333
+ --max_grad_norm 0.5 \
334
+ --optim "adamw_torch" \
335
+ --max_source_length 400 \
336
+ --cutoff_len 700 \
337
+ --max_target_length 300 \
338
+ --report_to tensorboard \
339
+ --evaluation_strategy "epoch" \
340
+ --save_strategy "epoch" \
341
+ --save_total_limit 10 \
342
+ --lora_r 64 \
343
+ --lora_alpha 64 \
344
+ --lora_dropout 0.05 \
345
+ --bf16
346
+ ```
347
+
348
+ * 若要基于微调后的LoRA权重继续训练,仅需将 `checkpoint_dir` 参数指向LoRA权重路径,例如设置为`'zjunlp/llama2-13b-iepile-lora'`。
349
 
350
+ > 可通过设置 `bits` = 8 或 4 进行量化。
351
 
352
+ > 请注意,在使用 **`LLaMA2-IEPile`** **`Baichuan2-IEPile`** 时,保持lora_r和lora_alpha均为64,对于这些参数,我们不提供推荐设置。
353
 
354
+ * 若要基于微调后的模型权重继续训练,只需设定 `model_name_or_path` 参数为权重路径,如`'zjunlp/KnowLM-IE-v2'`,无需设置`checkpoint_dir`。
355
 
356
 
357
+ 脚本可以在 [ft_scripts/fine_continue.bash](./ft_scripts/fine_continue.bash) 中找到。
358
 
359
 
 
360
 
361
+ ## 👓5.预测
362
 
363
+ ### 5.1测试数据转换
364
 
365
+ 在准备测试数据转换之前,请访问 [data](./data) 目录以了解各任务所需的数据结构:1)输入数据格式参见 `sample.json`;2)schema格式请查看 `schema.json`;3)转换后数据格式可参照 `train.json`。**与训练数据不同, 测试数据的输入无需包含标注字段(`entity`, `relation`, `event`)**。
366
 
367
 
368
  ```bash
 
376
  --split test
377
  ```
378
 
379
+ 设置 `split` 为 **test** 时,请根据任务类型选择适当的schema数量:**NER推荐为6,而RE、EE、EET、EEA推荐为4**。转换后的测试数据将含有`id`, `task`, `source`, `instruction`, `label`五个字段。
 
 
 
 
380
 
381
+ `label` 字段将用于后续评估。若输入数据中缺少标注字段(`entity`, `relation`, `event`),则转换后的测试数据将不包含`label`字段,适用于那些无原始标注数据的场景。
382
 
383
 
384
+
385
+ ### 5.2基础模型+Lora预测
386
 
387
  ```bash
388
  CUDA_VISIBLE_DEVICES=0 python src/inference.py \
389
  --stage sft \
390
+ --model_name_or_path 'models/llama2-13B-Chat' \
391
+ --checkpoint_dir 'zjunlp/llama2-13b-IEPile-lora' \
392
+ --model_name 'llama' \
393
+ --template 'llama2' \
394
  --do_predict \
395
  --input_file 'data/input.json' \
396
+ --output_file 'results/llama2-13b-IEPile-lora_output.json' \
397
+ --finetuning_type lora \
398
  --output_dir 'lora/test' \
399
  --predict_with_generate \
400
  --max_source_length 512 \
 
402
  --max_new_tokens 300
403
  ```
404
 
405
+ * 在进行推理时,`model_name`, `template`, 和 `bf16` 必须与训练时的设置相同。
406
+ * `model_name_or_path`: 指定所使用的基础模型路径,必须与相应的LoRA模型匹配。
407
+ * `checkpoint_dir`: LoRA的权重文件路径。
408
+ * `output_dir`: 此参数在推理时不起作用,可以随意指定一个路径。
409
+ * `input_file`, `output_file`: 分别指定输入的测试文件路径和预测结果的输出文件路径。
410
+ * `max_source_length`, `max_new_tokens`: 设置最大的输入长度和生成的新token数量,根据显存大小进行调整。
411
 
412
+ > 可通过设置 `bits` = 8 或 4 进行量化。
413
 
414
+ ### 5.3IE专用模型预测
415
 
416
  ```bash
417
  CUDA_VISIBLE_DEVICES=0 python src/inference.py \
418
  --stage sft \
419
+ --model_name_or_path 'zjunlp/KnowLM-IE-v2' \
420
+ --model_name 'baichuan' \
421
+ --template 'baichuan2' \
 
422
  --do_predict \
423
  --input_file 'data/input.json' \
424
+ --output_file 'results/KnowLM-IE-v2_output.json' \
 
425
  --output_dir 'lora/test' \
426
  --predict_with_generate \
427
  --max_source_length 512 \
428
  --bf16 \
429
+ --max_new_tokens 300
430
  ```
431
 
432
+ `model_name_or_path`: IE专用模型权重路径
433
+
434
+ > 可通过设置 `bits` = 8 或 4 进行量化。
435
 
436
 
437
+ ## 6.评估
438
 
439
  我们提供了评估各个任务F1分数的脚本。
440
 
 
444
  --task NER
445
  ```
446
 
447
+ * `task`: 目前支持['RE', 'NER', 'EE', 'EET', 'EEA']五类任务。
448
+ * 可以设置 `sort_by` 为 `source`, 分别计算每个数据集上的F1分数。
449
 
450
 
 
451
 
452
+ ## 7.声明和许可
453
 
454
+ 我们认为标注数据蕴含着人类的智慧宝库,它的存在是为了促进全人类的利益,并有助于提升我们的生活质量。我们强烈敦促所有的用户不要将我们的语料库用于任何可能对国家或公共安全造成伤害、违反法律法规的行为。
455
  我们竭尽所能地保证所提供数据的质量与其合法性。但我们也意识到,尽管如此,可能还是存在一些不可预见的问题,诸如数据保护的担忧以及数据被滥用可能引起的风险和问题。对于这些潜在的问题,我们将不承担责任。
456
+ 对于那些受限于比[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en)协议更为严格的使用许可的原始数据,IEPile将恪守那些较为严格的条款。在其他所有情形下,我们的操作将基于[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en)许可协议。
457
 
 
458
 
459
 
460
+ ## 8.局限
461
 
462
  从数据角度来看,我们的研究主要集中在基于schema的信息提取(IE)上,这限制了我们将研究成果推广至不遵循我们特定格式要求的人类指令的能力。此外,我们没有探索开放信息提取(Open IE)领域;然而,如果我们去除schema约束,我们的数据集将适用于开放信息提取场景。此外,我们的数据集目前仅包含英语和中文数据,在未来,我们希望能够包含更多语言的数据。
 
463
  从模型的角度来看,由于计算资源的限制,我们的研究仅评估了两个模型:Baichuan和LLaMA,以及一些基线模型。我们的数据集可以应用于任何其他的大型语言模型(LLMs),如Qwen、ChatGLM。
464
 
465
+
466
+ ## 9.引用
467
+ 如果您使用IEPile或代码,请引用以下论文:
468
+
469
+
470
+
471
+ ## 10. 致谢
472
+ 我们非常感谢[MathPile](mathpile)和[KnowledgePile](https://huggingface.co/datasets/Query-of-CC/Knowledge_Pile)项目提供的宝贵灵感。我们对以下数据集构建者和维护者表示特别的谢意:[AnatEM](https://doi.org/10.1093/BIOINFORMATICS/BTT580)、[BC2GM](https://link.springer.com/chapter/10.1007/978-3-030-68763-2_48)、[BC4CHEMD](https://link.springer.com/chapter/10.1007/978-3-030-68763-2_48)、[NCBI-Disease](https://linkinghub.elsevier.com/retrieve/pii/S1532046413001974)、[BC5CDR](https://openreview.net/pdf?id=9EAQVEINuum)、[HarveyNER](https://aclanthology.org/2022.naacl-main.243/)、[CoNLL2003](https://aclanthology.org/W03-0419/)、[GENIA](https://pubmed.ncbi.nlm.nih.gov/12855455/)、[ACE2005](https://catalog.ldc.upenn.edu/LDC2006T06)、[MIT Restaurant](https://ieeexplore.ieee.org/document/6639301)、[MIT Movie](https://ieeexplore.ieee.org/document/6639301)、[FabNER](https://link.springer.com/article/10.1007/s10845-021-01807-x)、[MultiNERD](https://aclanthology.org/2022.findings-naacl.60/)、[Ontonotes](https://aclanthology.org/N09-4006/)、[FindVehicle](https://arxiv.org/abs/2304.10893)、[CrossNER](https://ojs.aaai.org/index.php/AAAI/article/view/17587)、[MSRA NER](https://aclanthology.org/W06-0115/)、[Resume NER](https://aclanthology.org/P18-1144/)、[CLUE NER](https://arxiv.org/abs/2001.04351)、[Weibo NER](https://aclanthology.org/D15-1064/)、[Boson](https://github.com/InsaneLife/ChineseNLPCorpus/tree/master/NER/boson)、[ADE Corpus](https://jbiomedsem.biomedcentral.com/articles/10.1186/2041-1480-3-15)、[GIDS](https://arxiv.org/abs/1804.06987)、[CoNLL2004](https://aclanthology.org/W04-2412/)、[SciERC](https://aclanthology.org/D18-1360/)、[Semeval-RE](https://aclanthology.org/S10-1006/)、[NYT11-HRL](https://ojs.aaai.org/index.php/AAAI/article/view/4688)、[KBP37](https://arxiv.org/abs/1508.01006)、[NYT](https://link.springer.com/chapter/10.1007/978-3-642-15939-8_10)、[Wiki-ZSL](https://aclanthology.org/2021.naacl-main.272/)、[FewRel](https://aclanthology.org/D18-1514/)、[CMeIE](https://link.springer.com/chapter/10.1007/978-3-030-60450-9_22)、[DuIE](https://link.springer.com/chapter/10.1007/978-3-030-32236-6_72)、[COAE2016](https://github.com/Sewens/COAE2016)、[IPRE](https://arxiv.org/abs/1907.12801)、[SKE2020](https://aistudio.baidu.com/datasetdetail/177191)、[CASIE](https://ojs.aaai.org/index.php/AAAI/article/view/6401)、[PHEE](https://aclanthology.org/2022.emnlp-main.376/)、[CrudeOilNews](https://aclanthology.org/2022.lrec-1.49/)、[RAMS](https://aclanthology.org/2020.acl-main.718/)、[WikiEvents](https://aclanthology.org/2021.naacl-main.69/)、[DuEE](https://link.springer.com/chapter/10.1007/978-3-030-60457-8_44)、[DuEE-Fin](https://link.springer.com/chapter/10.1007/978-3-031-17120-8_14)、[FewFC](https://ojs.aaai.org/index.php/AAAI/article/view/17720)、[CCF law](https://aistudio.baidu.com/projectdetail/4201483)等,这些数据集极大地促进了本研究的进展。我们也要对[InstructUIE](http://arxiv.org/abs/2304.08085)与[YAYI-UIE](http://arxiv.org/abs/2312.15548)为数据和模型在信息抽取领域做出的宝贵贡献表示感激。我们的研究成果同样得益于他们的创新和努力。此外,我们要对[hiyouga/LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory)表示衷心的感谢,我们的微调代码实现在很大程度上参考了他们的工作。通过这些学术资源的辅助,我们得以完成本项研究,对此我们深表感激。