ghh001 commited on
Commit
0bea106
1 Parent(s): 1aba642

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +259 -75
README.md CHANGED
@@ -1,99 +1,222 @@
1
- ---
2
- license: apache-2.0
3
- ----
 
 
 
 
4
 
5
 
6
- - [1.Differences from knowlm-13b-zhixi](#1differences-from-knowlm-13b-zhixi)
7
- - [2.IE template](#2ie-template)
8
- - [3.Common relationship types](#3common-relationship-types)
9
- - [4.Convert script](#4convert-script)
10
- - [5.Datasets](#5datasets)
11
- - [6.Usage](#6usage)
12
- - [7.Evaluate](#7evaluate)
13
 
 
14
 
 
15
 
16
- # 1.Differences from knowlm-13b-zhixi
17
- Compared to zjunlp/knowlm-13b-zhixi, zjunlp/knowlm-13b-ie exhibits slightly stronger practicality in information extraction but with a decrease in its general applicability.
18
 
19
- zjunlp/knowlm-13b-ie samples around 10% of the data from Chinese-English information extraction datasets, which then undergo negative sampling. For instance, if dataset A contains labels [a, b, c, d, e, f], we first sample 10% of the data from A. For a given sample 's', it might only contain labels a and b. We randomly add relationships that it doesn't originally have, such as c and d, from the specified list of relation candidates. When encountering these additional relationships, the model might output text similar to 'NAN'.This method equips the model with the ability to generate 'NAN' outputs to a certain extent, enhancing its information extraction capability while weakening its generalization ability.
20
 
 
 
 
 
 
21
 
22
 
23
- # 2.IE template
24
- RE supports the following templates:
25
- ```python
26
- relation_template_zh = {
27
- 0:'已知候选的关系列表:{s_schema},请你根据关系列表,从以下输入中抽取出可能存在的头实体与尾实体,并给出对应的关系三元组。请按照{s_format}的格式回答。',
28
- 1:'我将给你个输入,请根据关系列表:{s_schema},从输入中抽取出可能包含的关系三元组,并以{s_format}的形式回答。',
29
- 2:'我希望你根据关系列表从给定的输入中抽取可能的关系三元组,并以{s_format}的格式回答,关系列表={s_schema}。',
30
- 3:'给定的关系列表是{s_schema}\n根据关系列表抽取关系三元组,在这个句子中可能包含哪些关系三元组?请以{s_format}的格式回答。',
31
- }
32
-
33
- relation_int_out_format_zh = {
34
- 0:['"(头实体,关系,尾实体)"', relation_convert_target0],
35
- 1:['"头实体是\n关系是\n尾实体是\n\n"', relation_convert_target1],
36
- 2:['"关系:头实体,尾实体\n"', relation_convert_target2],
37
- 3:["JSON字符串[{'head':'', 'relation':'', 'tail':''}, ]", relation_convert_target3],
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- relation_template_en = {
41
- 0:'Identify the head entities (subjects) and tail entities (objects) in the following text and provide the corresponding relation triples from relation list {s_schema}. Please provide your answer as a list of relation triples in the form of {s_format}.',
42
- 1:'From the given text, extract the possible head entities (subjects) and tail entities (objects) and give the corresponding relation triples. The relations are {s_schema}. Please format your answer as a list of relation triples in the form of {s_format}.',
43
- }
44
 
45
- relation_int_out_format_en = {
46
- 0:['(Subject, Relation, Object)', relation_convert_target0_en],
47
- 1:["{'head':'', 'relation':'', 'tail':''}", relation_convert_target1_en],
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
49
  ```
50
 
51
- Both the schema and format placeholders ({s_schema} and {s_format}) are embedded within the templates and must be specified by users.
52
 
53
- For a more comprehensive understanding of the templates, please refer to the files [ner_template.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/ner_template.py)、[re_template.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/re_template.py)、[ee_template.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/ee_template.py) .
54
 
55
 
56
- # 3.Common relationship types
57
 
58
 
59
- ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  {
61
- '组织': ['别名', '位于', '类型', '成立时间', '解散时间', '成员', '创始人', '事件', '子组织', '产品', '成就', '运营'],
62
- '医学': ['别名', '病因', '症状', '可能后果', '包含', '发病部位'],
63
- '事件': ['别名', '类型', '发生时间', '发生地点', '参与者', '主办方', '提名者', '获奖者', '赞助者', '获奖作品', '获胜者', '奖项'],
64
- '运输': ['别名', '位于', '类型', '属于', '途径', '开通时间', '创建时间', '车站等级', '长度', '面积'],
65
- '人造物件': ['别名', '类型', '受众', '成就', '品牌', '产地', '长度', '宽度', '高度', '重量', '价值', '制造商', '型号', '生产时间', '材料', '用途', '发现者或发明者'],
66
- '生物': ['别名', '学名', '类型', '分布', '父级分类单元', '主要食物来源', '用途', '长度', '宽度', '高度', '重量', '特征'],
67
- '建筑': ['别名', '类型', '位于', '临近', '名称由来', '长度', '宽度', '高度', '面积', '创建时间', '创建者', '成就', '事件'],
68
- '自然科学': ['别名', '类型', '性质', '生成物', '用途', '组成', '产地', '发现者或发明者'],
69
- '地理地区': ['别名', '类型', '所在行政领土', '接壤', '事件', '面积', '人口', '行政中心', '产业', '气候'],
70
- '作品': ['别名', '类型', '受众', '产地', '成就', '导演', '编剧', '演员', '平台', '制作者', '改编自', '包含', '票房', '角色', '作曲者', '作词者', '表演者', '出版时间', '出版商', '作者'],
71
- '人物': ['别名', '籍贯', '国籍', '民族', '朝代', '出生时间', '出生地点', '死亡时间', '死亡地点', '专业', '学历', '作品', '职业', '职务', '成就', '所属组织', '父母', '配偶', '兄弟姊妹', '亲属', '同事', '参与'],
72
- '天文对象': ['别名', '类型', '坐标', '发现者', '发现时间', '名称由来', '属于', '直径', '质量', '公转周期', '绝对星等', '临近']
73
  }
74
  ```
75
 
76
- Here [schema](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/schema.py) provides 12 text topics and common relationship types under the topic.
77
 
78
 
79
 
80
- # 4.Convert script
81
 
82
- A script named [convert.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert.py)、[convert_test.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert_test.py) is provided to facilitate the uniform conversion of data into KnowLM instructions. The [data](https://github.com/zjunlp/DeepKE/tree/main/example/llm/InstructKGC/data) directory contains the expected data format for each task before executing convert.py.
83
 
 
84
 
85
  ```bash
86
  python kg2instruction/convert.py \
87
  --src_path data/NER/sample.json \
88
  --tgt_path data/NER/processed.json \
89
  --schema_path data/NER/schema.json \
90
- --language zh \
91
- --task NER \
92
- --sample 0 \
93
- --all
 
 
94
  ```
95
 
96
- [convert_test.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert_test.py) does not require data to have label (`entity`, `relation`, `event`) fields, only needs to have an `input` field and provide a `schema_path` is suitable for processing test data.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  ```bash
99
  python kg2instruction/convert_test.py \
@@ -106,26 +229,89 @@ python kg2instruction/convert_test.py \
106
  ```
107
 
108
 
109
- # 5.Datasets
110
 
 
 
 
 
 
 
111
 
112
- Below are some readily processed datasets:
 
 
 
 
 
 
 
113
 
114
- | Name | Download Links | Quantity | Description |
115
- | ------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
116
- | KnowLM-IE.json | [Google Drive](https://drive.google.com/file/d/1hY_R6aFgW4Ga7zo41VpOVOShbTgBqBbL/view?usp=sharing) <br/> [HuggingFace](https://huggingface.co/datasets/zjunlp/KnowLM-IE) | 281860 | Dataset mentioned in [InstructIE](https://arxiv.org/abs/2305.11527) |
117
- | KnowLM-ke | [HuggingFace](https://huggingface.co/datasets/zjunlp/knowlm-ke) | XXXX | Contains all instruction data (General, IE, Code, COT, etc.) used for training [zjunlp/knowlm-13b-zhixi](https://huggingface.co/zjunlp/knowlm-13b-zhixi) |
118
 
 
119
 
120
- `KnowLM-IE.json`: Contains fields such as `'id'` (unique identifier), `'cate'` (text category), `'instruction'` (extraction instruction), `'input'` (input text), `'output'` (output text), and `'relation'` (triples). The `'relation'` field can be used to construct extraction instructions and outputs freely. `'instruction'` has 16 formats (4 prompts * 4 output formats), and `'output'` is generated in the specified format from `'instruction'`.
121
 
122
- `KnowLM-ke`: Contains fields `'instruction'`, `'input'`, and `'output'` only. The files `ee-en.json`, `ee_train.json`, `ner-en.json`, `ner_train.json`, `re-en.json`, and `re_train.json` under its directory contain Chinese-English IE instruction data.
123
 
124
 
 
 
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
- # 6.Usage
128
- We provide a script, [inference.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/src/inference.py), for direct inference using the `zjunlp/knowlm-13b-ie model`. Please refer to the [README.md](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/README.md) for environment configuration and other details.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  ```bash
131
  CUDA_VISIBLE_DEVICES="0" python src/inference.py \
@@ -136,13 +322,12 @@ CUDA_VISIBLE_DEVICES="0" python src/inference.py \
136
  --fp16
137
  ```
138
 
139
- If GPU memory is not enough, you can use `--bits 8` or `--bits 4`.
140
 
141
 
142
 
143
- # 7.Evaluate
144
-
145
- We provide a script at [evaluate.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/evaluate.py) to convert the string output of the model into a list and calculate F1
146
 
147
  ```bash
148
  python kg2instruction/evaluate.py \
@@ -152,4 +337,3 @@ python kg2instruction/evaluate.py \
152
  --language zh
153
  ```
154
 
155
-
 
1
+ - [1.与 knowlm-13b-zhixi 的区别](#1与-knowlm-13b-zhixi-的区别)
2
+ - [📏 2.信息抽取模板](#-2信息抽取模板)
3
+ - [3.常见的主题关系类型](#3常见的主题关系类型)
4
+ - [4.现成数据集](#4现成数据集)
5
+ - [5.转换脚本](#5转换脚本)
6
+ - [6.使用](#6使用)
7
+ - [7.评估](#7评估)
8
 
9
 
10
+ # 1.与 knowlm-13b-zhixi 的区别
 
 
 
 
 
 
11
 
12
+ 与 zjunlp/knowlm-13b-zhixi 相比,zjunlp/knowlm-13b-ie 在信息抽取方面表现出略强的实用性,但其一般适用性下降。
13
 
14
+ zjunlp/knowlm-13b-ie 从中英文信息抽取数据集中采样约 10% 的数据,然后进行负采样。例如,如果数据集 A 包含标签 [a,b,c,d,e,f],我们首先从 A 中采样出 10% 的数据。对于给定的样本 s,它可能只包含标签 a 和 b。我们随机地添加原本没有的关系,比如来自指定关系候选列表的 c 和 d。当遇到这些额外的关系时,模型可能会输出类似 'NAN' 的文本。这种方法使模型在一定程度上具备生成 'NAN' 输出的能力,增强了其信息抽取能力,但削弱了其泛化能力。
15
 
 
 
16
 
 
17
 
18
+ # 📏 2.信息抽取模板
19
+ 模版`template`用于构造输入模型的指令`instruction`, 由三部分组成:
20
+ 1. 任务描述
21
+ 2. 候选标签列表{s_schema}(可选)
22
+ 3. 结构输出格式{s_format}
23
 
24
 
25
+ 指定候选标签列表的模版:
26
+ ```json
27
+ NER: "你是专门进行实体抽取的专家。已知候选的实体类型列表:{s_schema},请你根据实体类型列表,从以下输入中抽取出可能存在的实体,如果不存在某实体就输出NAN。请按照{s_format}的格式回答。"
28
+ RE: "你在这里扮演关系三元组识别师的角色。我将给你个输入,请根据关系列表:{s_schema},从输入中抽取出可能包含的关系三元组,,如果不存在某关系就输出NAN,并以{s_format}的形式回答。"
29
+ EE: "你是专门进行事件提取的专家。已知候选的事件字典:{s_schema},请你根据事件字典,从以下输入中抽取出可能存在的事件,如果不存在某事件就输出NAN。请按照{s_format}的格式回答。"
30
+ EET: "作为事件分析专员,你需要查看输入并根据事件类型名录:{s_schema},来确定可能发生的事件。所有回答都应该基于{s_format}格式。如果事件类型不匹配,请用NAN标记。"
31
+ EEA: "你是专门进行事件论元提取的专家。已知事件字典:{s_schema1},事件类型及触发词:{s_schema2},请你从以下输入中抽取出可能存在的论元,如果不存在某事件论元就输出NAN。请按照{s_format}的格式回答。"
32
+ ```
33
+
34
+ 不指定候选标签列表的模���:
35
+ ```json
36
+ NER: "分析文本内容,并提取明显的实体。将您的发现以{s_format}格式提出,跳过任何不明显或不确定的部分。"
37
+ RE: "请从文本中抽取出所有关系三元组,并根据{s_format}的格式呈现结果。忽略那些不符合标准关系模板的实体。"
38
+ EE: "请分析下文,从中抽取所有可识别的事件,并按照指定的格式{s_format}呈现。如果某些信息不构成事件,请简单跳过。"
39
+ EET: "审视下列文本内容,并抽取出任何你认为显著的事件。将你的发现整理成{s_format}格式提供。"
40
+ EEA: "请您根据事件类型及触发词{s_schema2}从以下输入中抽取可能的论元。请按照{s_format}的格式回答。"
41
+ ```
42
+
43
+ <details>
44
+ <summary><b>候选标签列表{s_schema}</b></summary>
45
+
46
+
47
+ ```json
48
+ NER(CLUE): ["书名", "地址", "电影", "公司", "姓名", "组织机构", "职位", "游戏", "景点", "政府"]
49
+ RE(DuIE): ["创始人", "号", "注册资本", "出版社", "出品公司", "作词", "出生地", "连载网站", "祖籍", "制片人", "出生日期", "主演", "改编自", ...]
50
+ EE(DuEE-fin): {"质押": ["披露时间", "质押物占总股比", "质押物所属公司", "质押股票/股份数量", "质押物", "质押方", "质押物占持股比", "质权方", "事件时间"], "股份回购": ["回购方", "回购完成时间", "披露时间", "每股交易价格", "交易金额", "回购股份数量", "占公司总股本比例"], ...}
51
+ EET(DuEE): ["交往-感谢", "组织行为-开幕", "竞赛行为-退赛", "组织关系-加盟", "组织关系-辞/离职", "财经/交易-涨价", "人生-产子/女", "灾害/意外-起火", "组织关系-裁员", ...]
52
+ EEA(DuEE-fin): {"质押": ["披露时间", "质押物占总股比", "质押物所属公司", "质押股票/股份数量", "质押物", "质押方", "质押物占持股比", "质权方", "事件时间"], "股份回购": ["回购方", "回购完成时间", "披露时间", "每股交易价格", "交易金额", "回购股份数量", "占公司总股本比例"], ...}
53
+ ```
54
+
55
+ </details>
56
+
57
+
58
+ <details>
59
+ <summary><b>结构输出格式{s_format}</b></summary>
60
+
61
+
62
+ ```json
63
+ NER: (实体,实体类型)
64
+ RE: (头实体,关系,尾实体)
65
+ EE: (事件触发词,事件类型,事件论元1#论元角色1;事件论元2#论元角色2)
66
+ EET: (事件触发词,事件类型)
67
+ EEA: (Event Trigger,Event Type,Argument1#Argument Role1;Argument2#Argument Role2)
68
+ ```
69
+
70
+ </details>
71
+
72
+
73
+
74
+ 这些模板中的schema({s_schema})和结构输出格式({s_format})占位符被嵌入在模板中,用户必须指定。
75
+ 有关模板的更全面理解,请参阅配置目录[configs](https://github.com/zjunlp/DeepKE/tree/main/example/llm/InstructKGC/configs) 和 文件[ner_converter.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert/converter/ner_converter.py)、[re_converter.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert/converter/re_converter.py)、[ee_converter.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert/converter/ee_converter.py)、[eet_converter.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert/converter/eet_converter.py)、[eea_converter.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert/converter/eea_converter.py) .
76
 
 
 
 
 
77
 
78
+ # 3.常见的主题关系类型
79
+
80
+ ```python
81
+ wiki_cate_schema_zh = {
82
+ '人物': ['出生地点', '出生日期', '国籍', '职业', '作品', '成就', '籍贯', '职务', '配偶', '父母', '别名', '所属组织', '死亡日期', '兄弟姊妹', '墓地'],
83
+ '地理地区': ['位于', '别名', '人口', '行政中心', '面积', '成就', '长度', '宽度', '海拔'],
84
+ '建筑': ['位于', '别名', '成就', '事件', '创建时间', '宽度', '长度', '创建者', '高度', '面积', '名称由来'],
85
+ '作品': ['作者', '出版时间', '别名', '产地', '改编自', '演员', '出版商', '成就', '表演者', '导演', '制片人', '编剧', '曲目', '作曲者', '作词者', '制作商', '票房', '出版平台'],
86
+ '生物': ['分布', '父级分类单元', '长度', '主要食物来源', '别名', '学名', '重量', '宽度', '高度'],
87
+ '人造物件': ['别名', '品牌', '生产时间', '材料', '产地', '用途', '制造商', '发现者或发明者'],
88
+ '自然科学': ['别名', '性质', '组成', '生成物', '用途', '产地', '发现者或发明者'],
89
+ '组织': ['位于', '别名', '子组织', '成立时间', '产品', '成就', '成员', '创始人', '解散时间', '事件'],
90
+ '运输': ['位于', '创建时间', '线路', '开通时间', '途经', '面积', '别名', '长度', '宽度', '成就', '车站等级'],
91
+ '事件': ['参与者', '发生地点', '发生时间', '别名', '赞助者', '伤亡人数', '起因', '导致', '主办方', '所获奖项', '获胜者'],
92
+ '天文对象': ['别名', '属于', '发现或发明时间', '发现者或发明者', '名称由来', '绝对星等', '直径', '质量'],
93
+ '医学': ['症状', '别名', '发病部位', '可能后果', '病因']
94
  }
95
  ```
96
 
97
+ 此处 [schema](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/schema.py) 提供了12种文本主题, 以及该主题下常见的关系类型。
98
 
 
99
 
100
 
101
+ # 4.现成数据集
102
 
103
 
104
+ | 名称 | 下载 | 数量 | 描述 |
105
+ | ------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
106
+ | InstructIE-train | [Google drive](https://drive.google.com/file/d/1VX5buWC9qVeVuudh_mhc_nC7IPPpGchQ/view?usp=drive_link) <br/> [HuggingFace](https://huggingface.co/datasets/zjunlp/KnowLM-IE) <br/> [百度云盘](https://pan.baidu.com/s/1xXVrjkinw4cyKKFBR8BwQw?pwd=x4s7) | 30w+ | InstructIE训练集 |
107
+ | InstructIE-valid | [Google drive](https://drive.google.com/file/d/1EMvqYnnniKCGEYMLoENE1VD6DrcQ1Hhj/view?usp=drive_link) <br/> [HuggingFace](https://huggingface.co/datasets/zjunlp/KnowLM-IE) <br/> [百度云盘](https://pan.baidu.com/s/11u_f_JT30W6B5xmUPC3enw?pwd=71ie) | 2000+ | InstructIE验证集 |
108
+ | InstructIE-test | [Google drive](https://drive.google.com/file/d/1WdG6_ouS-dBjWUXLuROx03hP-1_QY5n4/view?usp=drive_link) <br/> [HuggingFace](https://huggingface.co/datasets/zjunlp/KnowLM-IE) <br/> [百度云盘](https://pan.baidu.com/s/1JiRiOoyBVOold58zY482TA?pwd=cyr9) | 2000+ | InstructIE测试集 |
109
+ | train.json, valid.json | [Google drive](https://drive.google.com/file/d/1vfD4xgToVbCrFP2q-SD7iuRT2KWubIv9/view?usp=sharing) | 5000 | [CCKS2023 开放环境下的知识图谱构建与补全评测任务一:指令驱动的自适应知识图谱构建](https://tianchi.aliyun.com/competition/entrance/532080/introduction) 中的初赛训练集及测试集 |
110
+
111
+
112
+ - `InstructIE-train`包含`InstructIE-zh.json`、`InstructIE-en.json`两个文件, 每个文件均包含以下字段:`'id'`(唯一标识符)、`'cate'`(文本主题)、`'entity'`、`'relation'`(三元组)字段,可以通过`'entity'`、`'relation'`自由构建抽取的指令和输出。
113
+ - `InstructIE-valid`、`InstructIE-test`分别是验证集和测试集, 包含`zh`和`en`双语。
114
+ - `train.json`:字段含义同`train.json`,`'instruction'`、`'output'`都只有1种格式,也可以通过`'relation'`自由构建抽取的指令和输出。
115
+ - `valid.json`:字段含义同`train.json`,但是经过众包标注,更加准确。
116
+
117
+
118
+ <details>
119
+ <summary><b>各字段的说明</b></summary>
120
+
121
+
122
+
123
+ | 字段 | 说明 |
124
+ | :---------: | :----------------------------------------------------: |
125
+ | id | 唯一标识符 |
126
+ | cate | 文本input对应的主题(共12种) |
127
+ | input | 模型输入文本(需要抽取其中涉及的所���关系三元组) |
128
+ | instruction | 模型进行抽取任务的指令 |
129
+ | output | 模型期望输出 |
130
+ | entity | 实体(entity, entity_type) |
131
+ | relation | input中涉及的关系三元组(head, relation, tail) |
132
+
133
+ </details>
134
+
135
+
136
+
137
+ <details>
138
+ <summary><b>一条数据的示例</b></summary>
139
+
140
+
141
+ ```json
142
  {
143
+ "id": "四乙基锗_0",
144
+ "cate": "自然科学",
145
+ "input": "四乙基锗,简称TEG,是一种有机锗化合物,化学式4Ge。四乙基锗是锗的气相沉积法中一种重要的化合物。",
146
+ "entity": [
147
+ {"entity": "四乙基锗", "entity_type": "产品"},
148
+ {"entity": "TEG", "entity_type": "产品"},
149
+ {"entity": "有机锗化合物", "entity_type": "产品"},
150
+ {"entity": "Ge", "entity_type": "产品"}
151
+ ],
152
+ "relation": [
153
+ {"head": "四乙基锗", "relation": "别名", "tail": "TEG"}
154
+ ]
155
  }
156
  ```
157
 
158
+ </details>
159
 
160
 
161
 
 
162
 
163
+ # 5.转换脚本
164
 
165
+ 我们提供了一个名为 [convert.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert.py) 的脚本,用于将数据统一转换为可以直接输入 KnowLM 的指令。在执行 convert.py 之前,请参考 [data](https://github.com/zjunlp/DeepKE/tree/main/example/llm/InstructKGC/data) 目录中包含了每个任务的预期数据格式。
166
 
167
  ```bash
168
  python kg2instruction/convert.py \
169
  --src_path data/NER/sample.json \
170
  --tgt_path data/NER/processed.json \
171
  --schema_path data/NER/schema.json \
172
+ --language zh \ # 不同语言使用的template及转换脚本不同
173
+ --task NER \ # ['RE', 'NER', 'EE', 'EET', 'EEA'] 5种任务
174
+ --sample -1 \ # 若为-1, 则从20种指令和4种输出格式中随机采样其中一种, 否则即为指定的指令格式, -1<=sample<20
175
+ --neg_ratio 1 \ # 表示所有样本的负采样比例
176
+ --neg_schema 1 \ # 表示从schema中负采样的比例
177
+ --random_sort # 是否对指令中的schema列表进行随机排序
178
  ```
179
 
180
+
181
+ `schema_path`指定schema文件(json文件)路径, schema文件共包含3行json字符串, 以固定的格式组织schema信息。这里以NER任务为例, 每行的含义如下:
182
+
183
+ ```
184
+ ["书名", "地址", "电影", ...] # 实体类型列表
185
+ [] # 空列表
186
+ {} # 空字典
187
+ ```
188
+
189
+ <details>
190
+ <summary><b>更多</b></summary>
191
+
192
+
193
+ ```
194
+ 对于RE任务
195
+ [] # 空列表
196
+ ["创始人", "号", "注册资本",...] # 关系类型列表
197
+ {} # 空字典
198
+
199
+ 对于EE任务
200
+ ["交往-感谢", "组织行为-开幕", "竞赛行为-退赛", ...] # 事件类型列表
201
+ ["解雇方", "解约方", "举报发起方", "被拘捕者"] # 论元角色列表
202
+ {"组织关系-裁员": ["裁员方", "裁员人数", "时间"], "司法行为-起诉": ["原告", "被告", "时间"], ...} # 事件类型字典
203
+
204
+ 对于EET任务
205
+ ["交往-感谢", "组织行为-开幕", "竞赛行为-退赛", ...] # 事件类型列表
206
+ [] # 空列表
207
+ {} # 空字典
208
+
209
+ 对于EEA任务
210
+ ["交往-感谢", "组织行为-开幕", "竞赛行为-退赛", ...] # 事件类型列表
211
+ ["解雇方", "解约方", "举报发起方", "被拘捕者"] # 论元角色列表
212
+ {"组织关系-裁员": ["裁员方", "裁员人数", "时间"], "司法行为-起诉": ["原告", "被告", "时间"], ...} # 事件类型字典
213
+ ```
214
+
215
+ </details>
216
+
217
+
218
+
219
+ [convert_test.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/convert_test.py) 不要求数据具有标签(`entity`、`relation`、`event`)字段, 只需要具有 `input` 字段, 以及提供 `schema_path`, 适合用来处理测试数据。
220
 
221
  ```bash
222
  python kg2instruction/convert_test.py \
 
229
  ```
230
 
231
 
232
+ 以下是一个实体识别(NER)任务数据转换的示例:
233
 
234
+ ```json
235
+ 转换前:
236
+ {
237
+ "input": "相比之下,青岛海牛队和广州松日队的雨中之战虽然也是0∶0,但乏善可陈。",
238
+ "entity": [{"entity": "广州松日队", "entity_type": "组织机构"}, {"entity": "青岛海牛队", "entity_type": "组织机构"}]
239
+ }
240
 
241
+ 转换后:
242
+ {
243
+ "id": "e88d2b42f8ca14af1b77474fcb18671ed3cacc0c75cf91f63375e966574bd187",
244
+ "instruction": "请在所给文本中找出并列举['组织机构', '人物', '地理位置']提及的实体类型,不存在的类型请注明为NAN。回答应按(实体,实体类型)\n格式进行。",
245
+ "input": "相比之下,青岛海牛队和广州松日队的雨中之战虽然也是0∶0,但乏善可陈。",
246
+ "output": "(青岛海牛队,组织机构)\n(广州松日队,组织机构)\nNAN\nNAN"
247
+ }
248
+ ```
249
 
 
 
 
 
250
 
251
+ 转换前: 数据的格式需要符合 `DeepKE/example/llm/InstructKGC/data` 目录下为各项任务(如NER、RE、EE等)规定的结构。以NER任务为例,输入文本应标记为`input`字段,而标注数据则应标记为`entity`字段,它是一个包含多个`entity`和`entity_type`键值对的字典列表。
252
 
253
+ 转换后: 将得到包含`input`文本、`instruction`指令(详细说明了候选标签列表['组织机构', '人物', '地理位置']和期望的输出格式(实体,实体类型)���,以及`output`(以(实体,实体类型)形式列出在`input`中识别到的所有实体信息)的结构化数据。
254
 
 
255
 
256
 
257
+ <details>
258
+ <summary><b>更多</b></summary>
259
 
260
+ - 转换前
261
+ ```json
262
+ RE: {
263
+ "input": "如何演好自己的角色,请读《演员自我修养》《喜剧之王》周星驰崛起于穷困潦倒之中的独门秘笈",
264
+ "relation": [{"head": "喜剧之王", "relation": "主演", "tail": "周星驰"}]
265
+ }
266
+ EE: {
267
+ "input": "消失的“外企光环”,5月份在华裁员900余人,香饽饽变“臭”了",
268
+ "event": [{"event_trigger": "裁员", "event_type": "组织关系-裁员", "arguments": [{"argument": "900余人", "role": "裁员人数"}, {"argument": "5月份", "role": "时间"}]}]
269
+ }
270
+ EET: {
271
+ "input": "前两天,被称为 “ 仅次于苹果的软件服务商 ” 的 Oracle( 甲骨文 )公司突然宣布在中国裁员。。",
272
+ "event": [{"event_trigger": "裁员", "event_type": "组织关系-裁员", "arguments": [{"argument": "前两天", "role": "时间"}, {"argument": "被称为 “ 仅次于苹果的软件服务商 ” 的 Oracle( 甲骨文 )公司", "role": "裁员方"}]}]
273
+ }
274
+ EEA: {
275
+ "input": "不仅仅是中国IT企业在裁员,为何500强的甲骨文也发生了全球裁员",
276
+ "event": [{"event_trigger": "裁员", "event_type": "组织关系-裁员", "arguments": [{"argument": "中国IT企业", "role": "裁员方"}]}, {"event_trigger": "裁员", "event_type": "组织关系-裁员", "arguments": [{"argument": "500强的甲骨文", "role": "裁员方"}]}]
277
+ }
278
+ ```
279
 
280
+ - 转换后
281
+ ```json
282
+ RE: {
283
+ "id": "5526d8aa9520a0feaa045ae41d347cf7ca48bd84385743ed453ea57dbe743c7c",
284
+ "instruction": "你是专门进行关系三元组提取的专家。已知候选的关系列表:['丈夫', '出版社', '导演', '主演', '注册资本', '编剧', '人口数量', '成立日期', '作曲', '嘉宾', '海拔', '作词', '身高', '出品公司', '占地面积', '母亲'],请你根据关系列表,从以下输入中抽取出可能存在的头实体与尾实体,并给出对应的关系三元组,如果不存在某关系就输出NAN。请按照(头实体,关系,尾实体)\n的格式回答。",
285
+ "input": "如何演好自己的角色,请读《演员自我修养》《喜剧之王》周星驰崛起于穷困潦倒之中的独门秘笈",
286
+ "output": "NAN\nNAN\nNAN\n(喜剧之王,主演,周星驰)\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN"
287
+ }
288
+ EE: {
289
+ "id": "f4dcda5576849c77df664c9318d136c36a663f11ad8af98e2794b113884fa69c",
290
+ "instruction": "你是专门进行事件提取的专家。已知候选的事件字典:{'人生-婚礼': ['时间', '参礼人员', '地点', '结婚双方'], '组织关系-停职': ['所属组织', '停职人员', '时间'], '交往-会见': ['时间', '会见主体', '地点', '会见对象'], '组织关系-解约': ['时间', '被解约方', '解约方'], '组织行为-开幕': ['时间', '地点', '活动名称'], '人生-求婚': ['时间', '求婚对象', '求婚者'], '人生-失联': ['失联者', '时间', '地点'], '产品行为-发布': ['时间', '发布方', '发布产品'], '灾害/意外-洪灾': ['时间', '受伤人数', '地点', '死亡人数'], '产品行为-上映': ['时间', '上映方', '上映影视'], '组织行为-罢工': ['所属组织', '罢工人数', '时间', '罢工人员'], '人生-怀孕': ['时间', '怀孕者'], '灾害/意外-起火': ['时间', '受伤人数', '地点', '死亡人数'], '灾害/意外-车祸': ['时间', '受伤人数', '地点', '死亡人数'], '司法行为-开庭': ['时间', '开庭法院', '开庭案件'], '交往-探班': ['探班主体', '时间', '探班对象'], '竞赛行为-退役': ['时间', '退役者'], '组织关系-裁员': ['时间', '裁员人数'], '财经/交易-出售/收购': ['时间', '收购方', '交易物', '出售价格', '出售方'], '组织关系-退出': ['退出方', '时间', '原所属组织'], '竞赛行为-禁赛': ['时间', '被禁赛人员', '禁赛机构', '禁赛时长']},请你根据事件字典,从以下输入中抽取出可能存在的事件,如果不存在某事件就输出NAN。请按照(事件触发词,事件类型,事件论元1#论元角色1;事件论元2#论元角色2)\n的格式回答。",
291
+ "input": "消失的“外企光环”,5月份在华裁员900余人,香饽饽变“臭”了",
292
+ "output": "NAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\n(裁员,组织关系-裁员,时间#5月份;裁员人数#900余人)\nNAN\nNAN\nNAN"
293
+ }
294
+ EET: {
295
+ "id": "17aae856c45d7c75f1850d358dc81268a2a9604dce3b98865b3896d0f37a49ef",
296
+ "instruction": "作为事件分析专员,你需要查看输入并根据事件类型名录:['人生-订婚', '灾害/意外-坍/垮塌', '财经/交易-涨价', '组织行为-游行', '组织关系-辞/离职', '交往-会见', '人生-结婚', '竞赛行为-禁赛', '组织关系-裁员', '灾害/意外-袭击', '司法行为-约谈', '人生-婚礼', '竞赛行为-退役', '人生-离婚', '灾害/意外-地震', '财经/交易-跌停', '产品行为-发布', '人生-求婚', '人生-怀孕', '组织关系-解约', '财经/交易-降价'],来确定可能发生的事件。所有回答都应该基于(事件触发词,事件类型)\n格式。如果事件类型不匹配,请用NAN标记。",
297
+ "input": "前两天,被称为 “ 仅次于苹果的软件服务商 ” 的 Oracle( 甲骨文 )公司突然宣布在中国裁员。。",
298
+ "output": "NAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\n(裁员,组织关系-裁员)\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN\nNAN"
299
+ }
300
+ EEA: {
301
+ "id": "5079d3cb44e94ca9b0749e687b1b19edc94b60fc2c1eb97b2154bbeb93ad3955", "instruction": "你是专门进行事件论元提取的专家。已知事件字典:{'组织关系-裁员': ['裁员方']},事件类型及触发词:[{'event_type': '组织关系-裁员', 'event_trigger': '裁员'}],请你从以下输入中抽取出可能存在的论元,如果不存在某事件论元就输出NAN。请按照(事件触发词,事件类型,事件论元1#论元角色1;事件论元2#论元角色2)\n的格式回答。",
302
+ "input": "不仅仅是中国IT企业在裁员,为何500强的甲骨文也发生了全球裁员",
303
+ "output": "(裁员,组织关系-裁员,裁员方#中国IT企业)\n(裁员,组织关系-裁员,裁员方#500强的甲骨文)"
304
+ }
305
+ ```
306
+
307
+ </details>
308
+
309
+
310
+
311
+
312
+ # 6.使用
313
+
314
+ 我们提供了可直接使用 `zjunlp/knowlm-13b-ie` 模型进行推理的脚本[inference.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/src/inference.py), 请参考 [README.md](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/README.md) 配置环境等。
315
 
316
  ```bash
317
  CUDA_VISIBLE_DEVICES="0" python src/inference.py \
 
322
  --fp16
323
  ```
324
 
325
+ 如果GPU显存不足够, 可以采用 `--bits 8` `--bits 4`
326
 
327
 
328
 
329
+ # 7.评估
330
+ 我们提供一个位于 [evaluate.py](https://github.com/zjunlp/DeepKE/blob/main/example/llm/InstructKGC/kg2instruction/evaluate.py) 的脚本,用于将模型的字符串输出转换为列表并计算 F1 分数。
 
331
 
332
  ```bash
333
  python kg2instruction/evaluate.py \
 
337
  --language zh
338
  ```
339