Spaces:
Sleeping
Sleeping
PPL app
Browse files
app.py
CHANGED
@@ -140,15 +140,21 @@ def greet(X, ny):
|
|
140 |
yip = len(l_o_l_sa[0])
|
141 |
# qw = []
|
142 |
er = ""
|
|
|
143 |
for t in range(num_sub_tokens_label):
|
144 |
sum_state[t] /= yip
|
145 |
idx = torch.topk(sum_state[t], k=5, dim=0)[1]
|
|
|
146 |
wor = [tokenizer.decode(i.item()).strip() for i in idx]
|
|
|
147 |
for kl in wor:
|
148 |
if all(char.isalpha() for char in kl):
|
149 |
# qw.append(kl.lower())
|
150 |
er+=kl
|
151 |
break
|
|
|
|
|
|
|
152 |
# print(er)
|
153 |
# astr = ""
|
154 |
# for j in range(len(qw)):
|
@@ -165,6 +171,7 @@ def greet(X, ny):
|
|
165 |
# astr+=mock
|
166 |
# else:
|
167 |
# astr+=mock.capitalize()
|
|
|
168 |
return er
|
169 |
title = "Rename a variable in a Java class"
|
170 |
description = """This model is a fine-tuned GraphCodeBERT model fine-tuned to output higher-quality variable names for Java classes. Long classes are handled by the
|
|
|
140 |
yip = len(l_o_l_sa[0])
|
141 |
# qw = []
|
142 |
er = ""
|
143 |
+
val = torch.tensor(0.0)
|
144 |
for t in range(num_sub_tokens_label):
|
145 |
sum_state[t] /= yip
|
146 |
idx = torch.topk(sum_state[t], k=5, dim=0)[1]
|
147 |
+
probs = F.softmax(sum_state[t], dim=0)
|
148 |
wor = [tokenizer.decode(i.item()).strip() for i in idx]
|
149 |
+
cnt = 0
|
150 |
for kl in wor:
|
151 |
if all(char.isalpha() for char in kl):
|
152 |
# qw.append(kl.lower())
|
153 |
er+=kl
|
154 |
break
|
155 |
+
cnt+=1
|
156 |
+
val = val - torch.log(probs[idx[cnt]])
|
157 |
+
|
158 |
# print(er)
|
159 |
# astr = ""
|
160 |
# for j in range(len(qw)):
|
|
|
171 |
# astr+=mock
|
172 |
# else:
|
173 |
# astr+=mock.capitalize()
|
174 |
+
er = er+" "+str(val)
|
175 |
return er
|
176 |
title = "Rename a variable in a Java class"
|
177 |
description = """This model is a fine-tuned GraphCodeBERT model fine-tuned to output higher-quality variable names for Java classes. Long classes are handled by the
|