research14 commited on
Commit
b286b3f
·
1 Parent(s): a04a444
Files changed (1) hide show
  1. app.py +72 -87
app.py CHANGED
@@ -7,112 +7,97 @@ model_name = "lmsys/vicuna-7b-v1.3"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
- ## Task 1
11
- # msg = template_all.format(text)
12
- template_all = "Output the <Noun, Verb, Adjective, Adverb, Preposition/Subord, Coordinating Conjunction, Cardinal Number, Determiner, Noun Phrase, Verb Phrase, Adjective Phrase, Adverb Phrase, Preposition Phrase, Conjunction Phrase, Coordinate Phrase, Quantitave Phrase, Complex Nominal, Clause, Dependent Clause, Fragment Clause, T-unit, Complex T-unit, Fragment T-unit> in the following sentence without additional text in json format: "
13
- # msg = template_single.format(ents_prompt[eid], text)
14
- # template_single = "Output any <{}> in the following sentence one per line without additional text: "
15
 
16
- ## Task 2
17
- task2_pos = "POS tag the following sentence using Universal POS tag set without generating additional text: "
18
- task2_chunk = "Do sentence chunking for the following sentence as in CoNLL 2000 shared task without generating addtional text: "
19
-
20
- ## Task 3
 
 
 
21
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
24
 
25
- with gr.Tab("POS"):
26
- gr.Markdown(" Description ")
27
-
28
- prompt_POS = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
29
-
30
- gr.Markdown("Strategy 1 QA-Based Prompting")
31
- with gr.Row():
32
- vicuna_S1_chatbot_POS = gr.Chatbot(label="vicuna-7b")
33
- llama_S1_chatbot_POS = gr.Chatbot(label="llama-7b")
34
- gpt_S1_chatbot_POS = gr.Chatbot(label="gpt-3.5")
35
- clear = gr.ClearButton([prompt_POS, vicuna_S1_chatbot_POS])
36
- gr.Markdown("Strategy 2 Instruction-Based Prompting")
37
- with gr.Row():
38
- vicuna_S2_chatbot_POS = gr.Chatbot(label="vicuna-7b")
39
- llama_S2_chatbot_POS = gr.Chatbot(label="llama-7b")
40
- gpt_S2_chatbot_POS = gr.Chatbot(label="gpt-3.5")
41
- clear = gr.ClearButton([prompt_POS, vicuna_S2_chatbot_POS])
42
- gr.Markdown("Strategy 3 Structured Prompting")
43
- with gr.Row():
44
- vicuna_S3_chatbot_POS = gr.Chatbot(label="vicuna-7b")
45
- llama_S3_chatbot_POS = gr.Chatbot(label="llama-7b")
46
- gpt_S3_chatbot_POS = gr.Chatbot(label="gpt-3.5")
47
- clear = gr.ClearButton([prompt_POS, vicuna_S3_chatbot_POS])
48
 
49
- with gr.Tab("Chunk"):
50
- gr.Markdown(" Description ")
51
 
52
- prompt_CHUNK = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
 
53
 
54
- gr.Markdown("Strategy 1 QA")
55
- with gr.Row():
56
- vicuna_S1_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
57
- llama_S1_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
58
- gpt_S1_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
59
- clear = gr.ClearButton([prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
60
- gr.Markdown("Strategy 2 Instruction")
61
- with gr.Row():
62
- vicuna_S2_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
63
- llama_S2_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
64
- gpt_S2_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
65
- clear = gr.ClearButton([prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
66
- gr.Markdown("Strategy 3 Structured Prompting")
67
- with gr.Row():
68
- vicuna_S3_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
69
- llama_S3_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
70
- gpt_S3_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
71
- clear = gr.ClearButton([prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
72
 
73
- def respond(message, chat_history):
74
- input_ids = tokenizer.encode(message, return_tensors="pt")
75
- output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
76
- bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
77
-
78
- chat_history.append((message, bot_message))
79
- time.sleep(2)
80
- return "", chat_history
 
 
 
 
 
 
 
 
 
 
81
 
82
- def strategy1(message, chat_history):
83
- input_ids = tokenizer.encode(template_all + message, return_tensors="pt")
84
- output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
85
- bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
86
-
87
- chat_history.append((template_all + message, bot_message))
88
- time.sleep(2)
89
- return "", chat_history
90
 
91
- def strategy2_POS(message, chat_history):
92
- input_ids = tokenizer.encode(task2_pos + message, return_tensors="pt")
93
- output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
94
- bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- chat_history.append((task2_pos + message, bot_message))
97
- time.sleep(2)
98
- return "", chat_history
99
 
100
- def strategy2_CHUNK(message, chat_history):
101
- input_ids = tokenizer.encode(task2_chunk + message, return_tensors="pt")
 
 
102
  output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
103
  bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
104
 
105
- chat_history.append((task2_chunk + message, bot_message))
106
  time.sleep(2)
107
  return "", chat_history
108
-
109
 
110
- prompt_POS.submit(strategy1, [prompt_POS, vicuna_S1_chatbot_POS], [prompt_POS, vicuna_S1_chatbot_POS])
111
- prompt_POS.submit(strategy2_POS, [prompt_POS, vicuna_S2_chatbot_POS], [prompt_POS, vicuna_S2_chatbot_POS])
112
- prompt_POS.submit(respond, [prompt_POS, vicuna_S3_chatbot_POS], [prompt_POS, vicuna_S3_chatbot_POS])
113
 
114
- prompt_CHUNK.submit(strategy1, [prompt_CHUNK, vicuna_S1_chatbot_CHUNK], [prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
115
- prompt_CHUNK.submit(strategy2_CHUNK, [prompt_CHUNK, vicuna_S2_chatbot_CHUNK], [prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
116
- prompt_CHUNK.submit(respond, [prompt_CHUNK, vicuna_S3_chatbot_CHUNK], [prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
117
 
118
  demo.launch()
 
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
+ template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
 
 
 
 
11
 
12
+ linguistic_entities = [
13
+ "Noun",
14
+ "Determiner",
15
+ "Noun phrase",
16
+ "Verb phrase",
17
+ "Dependent Clause",
18
+ "T-units"
19
+ ]
20
 
21
  with gr.Blocks() as demo:
22
  gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ gr.Markdown(" Description ")
 
26
 
27
+ # Dropdown for linguistic entities
28
+ entity_dropdown = gr.Dropdown(linguistic_entities, label="Select Linguistic Entity")
29
 
30
+ prompt_POS = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ gr.Markdown("Strategy 1 QA-Based Prompting")
33
+ with gr.Row():
34
+ vicuna_S1_chatbot_POS = gr.Chatbot(label="vicuna-7b")
35
+ llama_S1_chatbot_POS = gr.Chatbot(label="llama-7b")
36
+ gpt_S1_chatbot_POS = gr.Chatbot(label="gpt-3.5")
37
+ clear = gr.ClearButton([prompt_POS, vicuna_S1_chatbot_POS])
38
+ gr.Markdown("Strategy 2 Instruction-Based Prompting")
39
+ with gr.Row():
40
+ vicuna_S2_chatbot_POS = gr.Chatbot(label="vicuna-7b")
41
+ llama_S2_chatbot_POS = gr.Chatbot(label="llama-7b")
42
+ gpt_S2_chatbot_POS = gr.Chatbot(label="gpt-3.5")
43
+ clear = gr.ClearButton([prompt_POS, vicuna_S2_chatbot_POS])
44
+ gr.Markdown("Strategy 3 Structured Prompting")
45
+ with gr.Row():
46
+ vicuna_S3_chatbot_POS = gr.Chatbot(label="vicuna-7b")
47
+ llama_S3_chatbot_POS = gr.Chatbot(label="llama-7b")
48
+ gpt_S3_chatbot_POS = gr.Chatbot(label="gpt-3.5")
49
+ clear = gr.ClearButton([prompt_POS, vicuna_S3_chatbot_POS])
50
 
 
 
 
 
 
 
 
 
51
 
52
+ gr.Markdown(" Description ")
53
+
54
+ prompt_CHUNK = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
55
+
56
+ gr.Markdown("Strategy 1 QA")
57
+ with gr.Row():
58
+ vicuna_S1_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
59
+ llama_S1_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
60
+ gpt_S1_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
61
+ clear = gr.ClearButton([prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
62
+ gr.Markdown("Strategy 2 Instruction")
63
+ with gr.Row():
64
+ vicuna_S2_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
65
+ llama_S2_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
66
+ gpt_S2_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
67
+ clear = gr.ClearButton([prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
68
+ gr.Markdown("Strategy 3 Structured Prompting")
69
+ with gr.Row():
70
+ vicuna_S3_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
71
+ llama_S3_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
72
+ gpt_S3_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
73
+ clear = gr.ClearButton([prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
74
+
75
+ # def respond(message, chat_history):
76
+ # input_ids = tokenizer.encode(message, return_tensors="pt")
77
+ # output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
78
+ # bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
79
 
80
+ # chat_history.append((message, bot_message))
81
+ # time.sleep(2)
82
+ # return "", chat_history
83
 
84
+ def respond_entities(message, chat_history):
85
+ entity = entity_dropdown.value
86
+ prompt = template_single.format(entity, message)
87
+ input_ids = tokenizer.encode(prompt, return_tensors="pt")
88
  output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
89
  bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
90
 
91
+ chat_history.append((message, bot_message))
92
  time.sleep(2)
93
  return "", chat_history
 
94
 
95
+ prompt_POS.submit(respond_entities, [prompt_POS, vicuna_S1_chatbot_POS], [prompt_POS, vicuna_S1_chatbot_POS])
96
+ prompt_POS.submit(respond_entities, [prompt_POS, vicuna_S2_chatbot_POS], [prompt_POS, vicuna_S2_chatbot_POS])
97
+ prompt_POS.submit(respond_entities, [prompt_POS, vicuna_S3_chatbot_POS], [prompt_POS, vicuna_S3_chatbot_POS])
98
 
99
+ prompt_CHUNK.submit(respond_entities, [prompt_CHUNK, vicuna_S1_chatbot_CHUNK], [prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
100
+ prompt_CHUNK.submit(respond_entities, [prompt_CHUNK, vicuna_S2_chatbot_CHUNK], [prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
101
+ prompt_CHUNK.submit(respond_entities, [prompt_CHUNK, vicuna_S3_chatbot_CHUNK], [prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
102
 
103
  demo.launch()