RobPruzan commited on
Commit
7472f09
·
1 Parent(s): c4e0a3d

Improving sliding window calculation

Browse files
Files changed (1) hide show
  1. app.py +28 -27
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
- windows.append(x)
337
-
338
- for text in windows:
339
- prediction = -(predict(text).item() * 1.786 + 6.4) + 10
340
- wind_preds.append(prediction)
341
-
342
- size = 25
343
- for i in wind_preds:
344
- for j in range(size):
345
- new_values.append(i)
346
-
347
- heat_map = []
348
- for idx, i in enumerate(new_values):
349
- window = new_values[idx:idx + size]
350
- heat_map.append(np.mean(window))
351
- compressed_map = []
352
- for idx, i in enumerate(heat_map):
353
- if idx % size == 0:
354
- window = heat_map[idx:idx + size]
355
- compressed_map.append(np.mean(window))
356
-
357
- inter_scores = compressed_map
 
 
 
358
  while len(inter_scores) <= len(words) - 1:
359
- inter_scores.append(compressed_map[-1])
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