research14 commited on
Commit
03c4742
·
1 Parent(s): b308128

test optimization

Browse files
Files changed (1) hide show
  1. app.py +29 -46
app.py CHANGED
@@ -93,7 +93,27 @@ with open('demonstration_3_42_parse.txt', 'r') as f:
93
  # Your existing code
94
  theme = gr.themes.Soft()
95
 
96
- pipeline = pipeline(task="text-generation", model="lmsys/vicuna-7b-v1.3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  # Dropdown options for model and task
99
  model_options = list(model_mapping.keys())
@@ -105,48 +125,13 @@ def process_text(model_name, task, text):
105
 
106
  for gid in tqdm(gid_list, desc='Query'):
107
  text = ptb[gid]['text']
108
-
109
- #if model_name is 'gpt3.5': 'gpt-3.5-turbo-0613',
110
- #elif model_name is 'vicuna-7b': 'lmsys/vicuna-7b-v1.3',
111
- #elif model_name is 'vicuna-13b': 'lmsys/vicuna-13b-v1.3',
112
- #elif model_name is 'vicuna-33b': 'lmsys/vicuna-33b-v1.3',
113
- #elif model_name is 'fastchat-t5': 'lmsys/fastchat-t5-3b-v1.0',
114
- #elif model_name is 'llama-7b': './llama/hf/7B',
115
- #elif model_name is 'llama-13b': './llama/hf/13B',
116
- #elif model_name is 'llama-30b': './llama/hf/30B',
117
- #elif model_name is 'alpaca': './alpaca-7B',
118
-
119
- if task == 'POS':
120
- strategy1 = pipeline(template_all.format(text))
121
- strategy2 = pipeline(prompt2_pos.format(text))
122
- strategy3 = pipeline(demon_pos)
123
- return (strategy1, strategy2, strategy3)
124
- elif task == 'Chunking':
125
- strategy1 = pipeline(template_all.format(text))
126
- strategy2 = pipeline(prompt2_chunk.format(text))
127
- strategy3 = pipeline(demon_chunk)
128
- return (strategy1, strategy2, strategy3)
129
- elif task == 'Parsing':
130
- strategy1 = pipeline(template_all.format(text))
131
- strategy2 = pipeline(prompt2_parse.format(text))
132
- strategy3 = pipeline(demon_parse)
133
- return (strategy1, strategy2, strategy3)
134
-
135
- # Define prompts for each strategy based on the task
136
- #strategy_prompts = {
137
- # 'Strategy 1': template_all.format(text),
138
- # 'Strategy 2': {
139
- # 'POS': prompt2_pos.format(text),
140
- # 'Chunking': prompt2_chunk.format(text),
141
- # 'Parsing': prompt2_parse.format(text),
142
- # }.get(task, "Invalid Task Selection for Strategy 2"),
143
- # 'Strategy 3': {
144
- # 'POS': demon_pos,
145
- # 'Chunking': demon_chunk,
146
- # 'Parsing': demon_parse,
147
- # }.get(task, "Invalid Task Selection for Strategy 3"),
148
- #}
149
 
 
 
 
 
 
 
150
 
151
  # Gradio interface
152
  iface = gr.Interface(
@@ -161,11 +146,9 @@ iface = gr.Interface(
161
  gr.Textbox(label="Strategy 2 Instruction Result"),
162
  gr.Textbox(label="Strategy 3 Structured Prompting Result"),
163
  ],
164
- title = "LLM Evaluator For Linguistic Scrutiny",
165
- theme = theme,
166
  live=False,
167
  )
168
 
169
  iface.launch()
170
-
171
-
 
93
  # Your existing code
94
  theme = gr.themes.Soft()
95
 
96
+ # Pipeline Initialization
97
+ pipelines = {model: pipeline(task="text2text-generation", model=model_mapping[model]) for model in model_mapping}
98
+
99
+ # Task-specific Prompts
100
+ task_prompts = {
101
+ 'POS': {
102
+ 'strategy1': 'template_all',
103
+ 'strategy2': 'prompt2_pos',
104
+ 'strategy3': 'demon_pos',
105
+ },
106
+ 'Chunking': {
107
+ 'strategy1': 'template_all',
108
+ 'strategy2': 'prompt2_chunk',
109
+ 'strategy3': 'demon_chunk',
110
+ },
111
+ 'Parsing': {
112
+ 'strategy1': 'template_all',
113
+ 'strategy2': 'prompt2_parse',
114
+ 'strategy3': 'demon_parse',
115
+ },
116
+ }
117
 
118
  # Dropdown options for model and task
119
  model_options = list(model_mapping.keys())
 
125
 
126
  for gid in tqdm(gid_list, desc='Query'):
127
  text = ptb[gid]['text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ if model_name in pipelines:
130
+ strategy1 = task_prompts[task]['strategy1'].format(text)
131
+ strategy2 = task_prompts[task]['strategy2'].format(text)
132
+ strategy3 = task_prompts[task]['strategy3'].format(text)
133
+
134
+ return tuple(pipelines[model_name](strategy) for strategy in [strategy1, strategy2, strategy3])
135
 
136
  # Gradio interface
137
  iface = gr.Interface(
 
146
  gr.Textbox(label="Strategy 2 Instruction Result"),
147
  gr.Textbox(label="Strategy 3 Structured Prompting Result"),
148
  ],
149
+ title="LLM Evaluator For Linguistic Scrutiny",
150
+ theme=theme,
151
  live=False,
152
  )
153
 
154
  iface.launch()