Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -12,10 +12,10 @@ loraModel = AutoPeftModelForSequenceClassification.from_pretrained("Intradiction
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
13 |
|
14 |
tokenizer2 = AutoTokenizer.from_pretrained("microsoft/deberta-v3-xsmall")
|
15 |
-
base_model = AutoModel.from_pretrained("microsoft/deberta-v3-xsmall")
|
16 |
-
peft_model_id = "rajevan123/STS-Lora-Fine-Tuning-Capstone-Deberta-small"
|
17 |
-
model = PeftModel.from_pretrained(base_model, peft_model_id)
|
18 |
-
#merged_model = model.merge_and_unload()
|
19 |
|
20 |
|
21 |
# Handle calls to DistilBERT------------------------------------------
|
@@ -53,15 +53,15 @@ def AlbertUntrained_fn(text1, text2):
|
|
53 |
# Handle calls to Deberta--------------------------------------------
|
54 |
DebertaUntrained_pipe = pipeline("text-classification", model="microsoft/deberta-v3-xsmall")
|
55 |
DebertanoLORA_pipe = pipeline("text-classification", model="rajevan123/STS-Conventional-Fine-Tuning")
|
56 |
-
DebertawithLORA_pipe = pipeline("text-classification",model=model, tokenizer=tokenizer2)
|
57 |
|
58 |
#STS models
|
59 |
def DebertanoLORA_fn(text1, text2):
|
60 |
return DebertanoLORA_pipe({'text': text1, 'text_pair': text2})
|
61 |
|
62 |
def DebertawithLORA_fn(text1, text2):
|
63 |
-
return DebertawithLORA_pipe({'text': text1, 'text_pair': text2})
|
64 |
-
|
65 |
|
66 |
def DebertaUntrained_fn(text1, text2):
|
67 |
return DebertaUntrained_pipe({'text': text1, 'text_pair': text2})
|
@@ -73,6 +73,50 @@ def displayMetricStatsUntrained():
|
|
73 |
return "No statistics to display for untrained models"
|
74 |
|
75 |
def displayMetricStatsText():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
file_name = 'events.out.tfevents.1701212945.784ae33ab242.985.0'
|
77 |
event_acc = event_accumulator.EventAccumulator(file_name,
|
78 |
size_guidance={
|
@@ -94,6 +138,71 @@ def displayMetricStatsText():
|
|
94 |
|
95 |
return metrics
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
def displayMetricStatsGraph():
|
98 |
file_name = 'events.out.tfevents.1701212945.784ae33ab242.985.0'
|
99 |
event_acc = event_accumulator.EventAccumulator(file_name,
|
@@ -199,7 +308,7 @@ with gr.Blocks(
|
|
199 |
btn.click(fn=distilBERTwithLORA_fn, inputs=inp, outputs=TextClassOut2)
|
200 |
btnTextClassStats.click(fn=displayMetricStatsUntrained, outputs=TextClassUntrained)
|
201 |
btnTextClassStats.click(fn=displayMetricStatsText, outputs=TextClassNoLoraStats)
|
202 |
-
btnTextClassStats.click(fn=
|
203 |
|
204 |
with gr.Tab("Natural Language Inferencing"):
|
205 |
with gr.Row():
|
@@ -313,8 +422,8 @@ with gr.Blocks(
|
|
313 |
sts_btn.click(fn=DebertanoLORA_fn, inputs=[sts_p1,sts_p2], outputs=sts_out1)
|
314 |
sts_btn.click(fn=DebertawithLORA_fn, inputs=[sts_p1,sts_p2], outputs=sts_out2)
|
315 |
btnSTSStats.click(fn=displayMetricStatsUntrained, outputs=STSUntrained)
|
316 |
-
|
317 |
-
|
318 |
|
319 |
with gr.Tab("More informatioen"):
|
320 |
gr.Markdown("stuff to add")
|
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
13 |
|
14 |
tokenizer2 = AutoTokenizer.from_pretrained("microsoft/deberta-v3-xsmall")
|
15 |
+
# base_model = AutoModel.from_pretrained("microsoft/deberta-v3-xsmall")
|
16 |
+
# peft_model_id = "rajevan123/STS-Lora-Fine-Tuning-Capstone-Deberta-small"
|
17 |
+
# model = PeftModel.from_pretrained(base_model, peft_model_id)
|
18 |
+
# #merged_model = model.merge_and_unload()
|
19 |
|
20 |
|
21 |
# Handle calls to DistilBERT------------------------------------------
|
|
|
53 |
# Handle calls to Deberta--------------------------------------------
|
54 |
DebertaUntrained_pipe = pipeline("text-classification", model="microsoft/deberta-v3-xsmall")
|
55 |
DebertanoLORA_pipe = pipeline("text-classification", model="rajevan123/STS-Conventional-Fine-Tuning")
|
56 |
+
#DebertawithLORA_pipe = pipeline("text-classification",model=model, tokenizer=tokenizer2)
|
57 |
|
58 |
#STS models
|
59 |
def DebertanoLORA_fn(text1, text2):
|
60 |
return DebertanoLORA_pipe({'text': text1, 'text_pair': text2})
|
61 |
|
62 |
def DebertawithLORA_fn(text1, text2):
|
63 |
+
#return DebertawithLORA_pipe({'text': text1, 'text_pair': text2})
|
64 |
+
return ("working2")
|
65 |
|
66 |
def DebertaUntrained_fn(text1, text2):
|
67 |
return DebertaUntrained_pipe({'text': text1, 'text_pair': text2})
|
|
|
73 |
return "No statistics to display for untrained models"
|
74 |
|
75 |
def displayMetricStatsText():
|
76 |
+
file_name = 'events.out.tfevents.distilbertSA-conventional.0'
|
77 |
+
event_acc = event_accumulator.EventAccumulator(file_name,
|
78 |
+
size_guidance={
|
79 |
+
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
80 |
+
event_accumulator.IMAGES: 4,
|
81 |
+
event_accumulator.AUDIO: 4,
|
82 |
+
event_accumulator.SCALARS: 0,
|
83 |
+
event_accumulator.HISTOGRAMS: 1,
|
84 |
+
})
|
85 |
+
|
86 |
+
event_acc.Reload()
|
87 |
+
accuracy_data = event_acc.Scalars('eval/accuracy')
|
88 |
+
loss_data = event_acc.Scalars('eval/loss')
|
89 |
+
metrics = ''
|
90 |
+
for i in range(0, len(loss_data)):
|
91 |
+
metrics = metrics + 'Epoch Number: ' + str(i) + '\n'
|
92 |
+
metrics = metrics + 'Accuracy (%): ' + str(round(accuracy_data[i].value * 100, 3)) + '\n'
|
93 |
+
metrics = metrics + 'Loss (%): ' + str(round(loss_data[i].value * 100, 3)) + '\n\n'
|
94 |
+
|
95 |
+
return metrics
|
96 |
+
|
97 |
+
def displayMetricStatsTextTCLora():
|
98 |
+
file_name = 'events.out.tfevents.distilbertSA-LORA.0'
|
99 |
+
event_acc = event_accumulator.EventAccumulator(file_name,
|
100 |
+
size_guidance={
|
101 |
+
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
102 |
+
event_accumulator.IMAGES: 4,
|
103 |
+
event_accumulator.AUDIO: 4,
|
104 |
+
event_accumulator.SCALARS: 0,
|
105 |
+
event_accumulator.HISTOGRAMS: 1,
|
106 |
+
})
|
107 |
+
|
108 |
+
event_acc.Reload()
|
109 |
+
accuracy_data = event_acc.Scalars('eval/accuracy')
|
110 |
+
loss_data = event_acc.Scalars('eval/loss')
|
111 |
+
metrics = ''
|
112 |
+
for i in range(0, len(loss_data)):
|
113 |
+
metrics = metrics + 'Epoch Number: ' + str(i) + '\n'
|
114 |
+
metrics = metrics + 'Accuracy (%): ' + str(round(accuracy_data[i].value * 100, 3)) + '\n'
|
115 |
+
metrics = metrics + 'Loss (%): ' + str(round(loss_data[i].value * 100, 3)) + '\n\n'
|
116 |
+
|
117 |
+
return metrics
|
118 |
+
|
119 |
+
def displayMetricStatsTextNLINoLora():
|
120 |
file_name = 'events.out.tfevents.1701212945.784ae33ab242.985.0'
|
121 |
event_acc = event_accumulator.EventAccumulator(file_name,
|
122 |
size_guidance={
|
|
|
138 |
|
139 |
return metrics
|
140 |
|
141 |
+
def displayMetricStatsTextNLILora():
|
142 |
+
file_name = 'events.out.tfevents.1701212945.784ae33ab242.985.0'
|
143 |
+
event_acc = event_accumulator.EventAccumulator(file_name,
|
144 |
+
size_guidance={
|
145 |
+
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
146 |
+
event_accumulator.IMAGES: 4,
|
147 |
+
event_accumulator.AUDIO: 4,
|
148 |
+
event_accumulator.SCALARS: 0,
|
149 |
+
event_accumulator.HISTOGRAMS: 1,
|
150 |
+
})
|
151 |
+
|
152 |
+
event_acc.Reload()
|
153 |
+
accuracy_data = event_acc.Scalars('eval/accuracy')
|
154 |
+
loss_data = event_acc.Scalars('eval/loss')
|
155 |
+
metrics = ''
|
156 |
+
for i in range(0, len(loss_data)):
|
157 |
+
metrics = metrics + 'Epoch Number: ' + str(i) + '\n'
|
158 |
+
metrics = metrics + 'Accuracy (%): ' + str(round(accuracy_data[i].value * 100, 3)) + '\n'
|
159 |
+
metrics = metrics + 'Loss (%): ' + str(round(loss_data[i].value * 100, 3)) + '\n\n'
|
160 |
+
|
161 |
+
return metrics
|
162 |
+
|
163 |
+
def displayMetricStatsTextSTSLora():
|
164 |
+
file_name = 'events.out.tfevents.STS-Lora.2'
|
165 |
+
event_acc = event_accumulator.EventAccumulator(file_name,
|
166 |
+
size_guidance={
|
167 |
+
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
168 |
+
event_accumulator.IMAGES: 4,
|
169 |
+
event_accumulator.AUDIO: 4,
|
170 |
+
event_accumulator.SCALARS: 0,
|
171 |
+
event_accumulator.HISTOGRAMS: 1,
|
172 |
+
})
|
173 |
+
|
174 |
+
event_acc.Reload()
|
175 |
+
accuracy_data = event_acc.Scalars('eval/accuracy')
|
176 |
+
loss_data = event_acc.Scalars('eval/loss')
|
177 |
+
metrics = ''
|
178 |
+
for i in range(0, len(loss_data)):
|
179 |
+
metrics = metrics + 'Epoch Number: ' + str(i) + '\n'
|
180 |
+
metrics = metrics + 'Accuracy (%): ' + str(round(accuracy_data[i].value * 100, 3)) + '\n'
|
181 |
+
metrics = metrics + 'Loss (%): ' + str(round(loss_data[i].value * 100, 3)) + '\n\n'
|
182 |
+
|
183 |
+
return metrics
|
184 |
+
def displayMetricStatsTextSTSNoLora():
|
185 |
+
file_name = 'events.out.tfevents.STS-Conventional.0'
|
186 |
+
event_acc = event_accumulator.EventAccumulator(file_name,
|
187 |
+
size_guidance={
|
188 |
+
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
189 |
+
event_accumulator.IMAGES: 4,
|
190 |
+
event_accumulator.AUDIO: 4,
|
191 |
+
event_accumulator.SCALARS: 0,
|
192 |
+
event_accumulator.HISTOGRAMS: 1,
|
193 |
+
})
|
194 |
+
|
195 |
+
event_acc.Reload()
|
196 |
+
accuracy_data = event_acc.Scalars('eval/accuracy')
|
197 |
+
loss_data = event_acc.Scalars('eval/loss')
|
198 |
+
metrics = ''
|
199 |
+
for i in range(0, len(loss_data)):
|
200 |
+
metrics = metrics + 'Epoch Number: ' + str(i) + '\n'
|
201 |
+
metrics = metrics + 'Accuracy (%): ' + str(round(accuracy_data[i].value * 100, 3)) + '\n'
|
202 |
+
metrics = metrics + 'Loss (%): ' + str(round(loss_data[i].value * 100, 3)) + '\n\n'
|
203 |
+
|
204 |
+
return metrics
|
205 |
+
|
206 |
def displayMetricStatsGraph():
|
207 |
file_name = 'events.out.tfevents.1701212945.784ae33ab242.985.0'
|
208 |
event_acc = event_accumulator.EventAccumulator(file_name,
|
|
|
308 |
btn.click(fn=distilBERTwithLORA_fn, inputs=inp, outputs=TextClassOut2)
|
309 |
btnTextClassStats.click(fn=displayMetricStatsUntrained, outputs=TextClassUntrained)
|
310 |
btnTextClassStats.click(fn=displayMetricStatsText, outputs=TextClassNoLoraStats)
|
311 |
+
btnTextClassStats.click(fn=displayMetricStatsTextTCLora, outputs=TextClassLoraStats) #to be changed
|
312 |
|
313 |
with gr.Tab("Natural Language Inferencing"):
|
314 |
with gr.Row():
|
|
|
422 |
sts_btn.click(fn=DebertanoLORA_fn, inputs=[sts_p1,sts_p2], outputs=sts_out1)
|
423 |
sts_btn.click(fn=DebertawithLORA_fn, inputs=[sts_p1,sts_p2], outputs=sts_out2)
|
424 |
btnSTSStats.click(fn=displayMetricStatsUntrained, outputs=STSUntrained)
|
425 |
+
btnSTSStats.click(fn=displayMetricStatsTextSTSNoLora, outputs=STSNoLoraStats)
|
426 |
+
btnSTSStats.click(fn=displayMetricStatsTextSTSLora, outputs=STSLoraStats)
|
427 |
|
428 |
with gr.Tab("More informatioen"):
|
429 |
gr.Markdown("stuff to add")
|