Update handler.py
Browse files- handler.py +15 -12
handler.py
CHANGED
@@ -8,18 +8,21 @@ import time
|
|
8 |
import os
|
9 |
import torch
|
10 |
|
11 |
-
def max_pooling(model_output):
|
12 |
-
# Get dimensions
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
return output_array
|
24 |
|
25 |
#Mean Pooling - Take attention mask into account for correct averaging
|
|
|
8 |
import os
|
9 |
import torch
|
10 |
|
11 |
+
def max_pooling(model_output):
|
12 |
+
# Get dimensions
|
13 |
+
Z, Y = len(model_output[0]), len(model_output[0][0])
|
14 |
+
|
15 |
+
# Initialize an empty list with length Y (384 in your case)
|
16 |
+
output_array = [0] * Y
|
17 |
+
|
18 |
+
# Loop over secondary arrays (Z)
|
19 |
+
for i in range(Z):
|
20 |
+
# Loop over values in innermost arrays (Y)
|
21 |
+
for j in range(Y):
|
22 |
+
# If value is greater than current max, update max
|
23 |
+
if model_output[0][i][j] > output_array[j]:
|
24 |
+
output_array[j] = model_output[0][i][j]
|
25 |
+
|
26 |
return output_array
|
27 |
|
28 |
#Mean Pooling - Take attention mask into account for correct averaging
|