ZekunXi commited on
Commit
f2ae81e
1 Parent(s): 7e5b684

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +140 -0
  2. constants.py +69 -0
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from constants import *
4
+
5
+ # ... 其他导入 ...
6
+
7
+ # 定义自定义 CSS
8
+ custom_css = """
9
+ h1 { /* 根据需要选择正确的标题标签 */
10
+ background-color: blue; /* 蓝色背景 */
11
+ color: white; /* 白色文字 */
12
+ padding: 10px; /* 内边距 */
13
+ text-align: center; /* 文本居中 */
14
+ }
15
+ h2 { /* 根据需要选择正确的标题标签 */
16
+ color: white; /* 白色文字 */
17
+ padding: 10px; /* 内边距 */
18
+ text-align: center; /* 文本居中 */
19
+ }
20
+
21
+ """
22
+
23
+ def get_preview_data():
24
+ df = pd.read_json(DATA_DIR)
25
+ df=df.head(4)
26
+ return df
27
+ def get_result_data():
28
+ df={
29
+ "DataSet": ["WikiData_recent", "WikiData_recent", "WikiData_recent", "WikiData_recent",
30
+ "ZsRE", "ZsRE", "ZsRE", "ZsRE",
31
+ "WikiBio", "WikiBio", "WikiBio",
32
+ "WikiData_counterfact", "WikiData_counterfact", "WikiData_counterfact", "WikiData_counterfact",
33
+ "ConvSent", "ConvSent", "ConvSent",
34
+ "Sanitation", "Sanitation", "Sanitation"],
35
+ "Metric": ["Edit Succ. ↑", "Portability ↑", "Locality ↑", "Fluency ↑",
36
+ "Edit Succ. ↑", "Portability ↑", "Locality ↑", "Fluency ↑",
37
+ "Edit Succ. ↑", "Locality ↑", "Fluency ↑",
38
+ "Edit Succ. ↑", "Portability ↑", "Locality ↑", "Fluency ↑",
39
+ "Edit Succ. ↑", "Locality ↓", "Fluency ↑",
40
+ "Edit Succ. ↑", "Locality ↑", "Fluency ↑"],
41
+ "SERAC": [98.68, 63.52, 100.00, 553.19,
42
+ 99.67, 56.48, 30.23, 410.89,
43
+ 99.69, 69.79, 606.95,
44
+ 99.99, 76.07, 98.96, 549.91,
45
+ 62.75, 0.26, 458.21,
46
+ 0.00, 100.00, 416.29],
47
+ "ICE": [60.74, 36.93, 33.34, 531.01,
48
+ 66.01, 63.94, 23.14, 541.14,
49
+ 95.53, 47.90, 632.92,
50
+ 69.83, 45.32, 32.38, 547.22,
51
+ 52.78, 49.73, 621.45,
52
+ 72.50, 56.58, 794.15],
53
+ "AdaLoRA": [65.61, 47.22, 55.78, 537.51,
54
+ 69.86, 52.95, 72.21, 532.82,
55
+ 97.02, 57.87, 615.86,
56
+ 72.14, 55.17, 66.78, 553.85,
57
+ 44.89, 0.18, 606.42,
58
+ 2.50, 65.50, 330.44],
59
+ "MEND": [76.88, 50.11, 92.87, 586.34,
60
+ 96.74, 60.41, 92.79, 524.33,
61
+ 93.66, 69.51, 609.39,
62
+ 78.82, 57.53, 94.16, 588.94,
63
+ 50.76, 3.42, 379.43,
64
+ 0.00, 5.29, 407.18],
65
+ "ROME": [85.08, 37.45, 66.2, 574.28,
66
+ 96.57, 52.20, 27.14, 570.47,
67
+ 95.05, 46.96, 617.25,
68
+ 83.21, 38.69, 65.4, 578.84,
69
+ 45.79, 0.00, 606.32,
70
+ 85.00, 50.31, 465.12],
71
+ "MEMIT": [85.32, 37.94, 64.78, 566.66,
72
+ 83.07, 51.43, 25.46, 559.72,
73
+ 94.29, 51.56, 616.65,
74
+ 83.41, 40.09, 63.68, 568.58,
75
+ 44.75, 0.00, 602.62,
76
+ 48.75, 67.47, 466.10],
77
+ "FT-L": [71.18, 48.71, 63.7, 549.35,
78
+ 54.65, 45.02, 71.12, 474.18,
79
+ 83.41, 40.09, 63.68, 568.58,
80
+ 66.27, 60.14, 604.00,
81
+ 51.12, 39.07, 62.51,
82
+ 48.75, 67.47, 466.10]
83
+ }
84
+ df=pd.DataFrame(df)
85
+ return df
86
+
87
+ block = gr.Blocks(css=custom_css) # 应用自定义 CSS
88
+
89
+ with block:
90
+ gr.Markdown(TITLE)
91
+
92
+ gr.Markdown("## BACKGROUND")
93
+ gr.Markdown(
94
+ BACKGROUND
95
+ )
96
+ gr.Image('./img/demo.gif')
97
+
98
+ gr.Markdown("## DATA PREVIEW")
99
+ gr.Markdown(LEADERBORAD_INTRODUCTION)
100
+
101
+ with gr.Tabs(elem_classes="tab-buttons") as tabs:
102
+ with gr.TabItem("🏅 Data preview ", elem_id="ke-benchmark-tab-table", id=0):
103
+ # 创建数据帧组件
104
+ ke_data_component = gr.components.Dataframe(
105
+ value=get_preview_data(),
106
+ headers=DATA_COLUMN_NAMES,
107
+ type="pandas",
108
+ )
109
+ with gr.TabItem("data Structure", elem_id="about-struct-tab-table", id=3):
110
+ gr.Markdown(DATA_STRUCT, elem_classes="markdown-text")
111
+
112
+ with gr.TabItem("📝 data schema", elem_id="about-benchmark-tab-table", id=4):
113
+ gr.Markdown(DATA_SCHEMA, elem_classes="markdown-text")
114
+
115
+
116
+
117
+
118
+ gr.Markdown("## EXPERIMENT RESULTS")
119
+ gr.Markdown("We list the results of current knowledge editing methods on Llama2-7b-chat in Table")
120
+ with gr.Tabs(elem_classes="tab-buttons") as tabs:
121
+ with gr.TabItem("🏅 result", elem_id="ke-benchmark-tab-table", id=0):
122
+ # 创建数据帧组件
123
+ ke_data_component = gr.components.Dataframe(
124
+ value=get_result_data(),
125
+ headers=RESULT_COLUMN_NAMES,
126
+ type="pandas",
127
+ )
128
+ # About tab
129
+ with gr.TabItem("📝 About", elem_id="about-benchmark-tab-table", id=4):
130
+ gr.Markdown("Results of existing knowledge edit methods on the constructed benchmark. The symbol indicates that higher numbers correspond to better performance, while ��� denotes the opposite, with lower numbers indicating better performance. For WikiBio and Convsent, we do not test the portability as they are about specific topics. ", elem_classes="markdown-text")
131
+
132
+ with gr.Row():
133
+ with gr.Accordion("Citation", open=False):
134
+ citation_button = gr.Textbox(
135
+ value=CITATION_BUTTON_TEXT,
136
+ label=CITATION_BUTTON_LABEL,
137
+ elem_id="citation-button",
138
+ ).style(show_copy_button=True)
139
+
140
+ block.launch(share=True)
constants.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # this is .py for store constants
2
+
3
+ DATA_DIR="./data/data.json"
4
+
5
+
6
+
7
+ MODEL_INFO = ["Model Name", "Language Model"]
8
+ AVG_INFO = ["Avg. All"]
9
+ ME_INFO=["Method Name", "Language Model"]
10
+
11
+ # KE 固定信息
12
+ KE_Data_INFO = ["FewNERD", "FewRel", "InstructIE-en", "MAVEN","WikiEvents"]
13
+
14
+ KE_TASK_INFO = ["Avg. All", "FewNERD", "FewRel", "InstructIE-en", "MAVEN","WikiEvents"]
15
+ KE_CSV_DIR = "./ke_files/result-kgc.csv"
16
+ DATA_COLUMN_NAMES =["locality","labels","concept","text"]
17
+ KE_TABLE_INTRODUCTION = """In the table below, we summarize each task performance of all the models. We use F1 score(%) as the primary evaluation metric for each tasks.
18
+ """
19
+ RESULT_COLUMN_NAMES= ["DataSet","Metric","Metric","ICE","AdaLoRA","MEND","ROME","MEMIT","FT-L","FT"]
20
+ DATA_STRUCT="""
21
+ Datasets ZsRE Wikirecent Wikicounterfact WikiBio
22
+ Train 10,000 570 1455 592
23
+ Test 1230 1266 885 1392
24
+ """
25
+ TITLE = """# KnowEdit: a dataset for knowledge editing"""
26
+
27
+ BACKGROUND="""
28
+ Large Language Models (LLMs) have shown extraordinary capabilities in understanding and generating text that closely mirrors human communication. However, a primary limitation lies in the significant computational demands during training, arising from their extensive parameterization.There is an increasing interest in efficient, lightweight methods for onthe-fly model modifications. To this end, recent years have seen a burgeoning in the techniques of knowledge editing for LLMs, which aim to efficiently modify LLMs’ behaviors within specific domains while preserving overall performance across various inputs.
29
+ """
30
+
31
+ LEADERBORAD_INTRODUCTION = """
32
+ This is the dataset for knowledge editing. It contains six tasks: ZsRE, Wiki<sub>recent</sub>, Wiki<sub>counterfact</sub>, WikiBio, ConvSent and Sanitation. This repo shows the former 4 tasks and you can get the data for ConvSent and Sanitation from their original papers.
33
+ """
34
+ DATA_SCHEMA =""" {
35
+ "subject": xxx,
36
+ "target_new": xxx,
37
+ "prompt": xxx,
38
+ "portability":{
39
+ "Logical_Generalization": [],
40
+ ...
41
+ }
42
+ "locality":{
43
+ "Relation_Specificity": [],
44
+ ...
45
+ }
46
+ }"""
47
+
48
+
49
+
50
+ CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
51
+ CITATION_BUTTON_TEXT = r"""@article{tan2023evaluation,
52
+ title={Evaluation of ChatGPT as a question answering system for answering complex questions},
53
+ author={Yiming Tan and Dehai Min and Yu Li and Wenbo Li and Nan Hu and Yongrui Chen and Guilin Qi},
54
+ journal={arXiv preprint arXiv:2303.07992},
55
+ year={2023}
56
+ }
57
+ @article{gui2023InstructIE,
58
+ author = {Honghao Gui and Jintian Zhang and Hongbin Ye and Ningyu Zhang},
59
+ title = {InstructIE: {A} Chinese Instruction-based Information Extraction Dataset},
60
+ journal = {arXiv preprint arXiv:2303.07992},
61
+ year = {2023}
62
+ }
63
+ @article{yao2023edit,
64
+ author = {Yunzhi Yao and Peng Wang and Bozhong Tian and Siyuan Cheng and Zhoubo Li and Shumin Deng and Huajun Chen and Ningyu Zhang},
65
+ title = {Editing Large Language Models: Problems, Methods, and Opportunities},
66
+ journal = {arXiv preprint arXiv:2305.13172},
67
+ year = {2023}
68
+ }
69
+ """