Spaces:
Runtime error
Runtime error
Improving sliding window calculation
Browse files
app.py
CHANGED
@@ -325,38 +325,39 @@ def diversity_inter(text):
|
|
325 |
|
326 |
|
327 |
def sliding_window(text):
|
328 |
-
wind_preds = []
|
329 |
-
windows = []
|
330 |
-
new_values = []
|
331 |
-
heat_map = []
|
332 |
words = word_tokenize(text)
|
|
|
|
|
333 |
for idx, text in enumerate(words):
|
334 |
if idx <= len(words) - 26:
|
335 |
x = ' '.join(words[idx: idx + 25])
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
for
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
|
|
|
|
|
|
358 |
while len(inter_scores) <= len(words) - 1:
|
359 |
-
inter_scores.append(
|
360 |
|
361 |
x = list(range(len(inter_scores)))
|
362 |
y = inter_scores
|
|
|
325 |
|
326 |
|
327 |
def sliding_window(text):
|
|
|
|
|
|
|
|
|
328 |
words = word_tokenize(text)
|
329 |
+
improved_window = []
|
330 |
+
improved_wind_preds = []
|
331 |
for idx, text in enumerate(words):
|
332 |
if idx <= len(words) - 26:
|
333 |
x = ' '.join(words[idx: idx + 25])
|
334 |
+
throw_away = []
|
335 |
+
score = 0
|
336 |
+
for idx, i in enumerate(range(idx, idx + 25)):
|
337 |
+
if idx == 0:
|
338 |
+
better_prediction = -(predict(x).item() * 1.786 + 6.4) + 10
|
339 |
+
score = better_prediction
|
340 |
+
throw_away.append((better_prediction, i))
|
341 |
+
else:
|
342 |
+
throw_away.append((score, i))
|
343 |
+
|
344 |
+
improved_window.append(throw_away)
|
345 |
+
average_scores = {k: 0 for k in range(len(words) - 1)}
|
346 |
+
total_windows = {k: 0 for k in range(len(words) - 1)}
|
347 |
+
for idx, i in enumerate(improved_window):
|
348 |
+
for score, idx in i:
|
349 |
+
average_scores[idx] += score
|
350 |
+
total_windows[idx] += 1
|
351 |
+
|
352 |
+
for k, v in total_windows.items():
|
353 |
+
if v != 0:
|
354 |
+
average_scores[k] /= v
|
355 |
+
|
356 |
+
inter_scores = [v for v in average_scores.values()]
|
357 |
+
copy_list = inter_scores.copy()
|
358 |
+
print(inter_scores)
|
359 |
while len(inter_scores) <= len(words) - 1:
|
360 |
+
inter_scores.append(copy_list[-1])
|
361 |
|
362 |
x = list(range(len(inter_scores)))
|
363 |
y = inter_scores
|