Spaces:
Runtime error
Runtime error
Commit
·
5fcbca3
1
Parent(s):
1c31ce3
Update app.py
Browse files
app.py
CHANGED
@@ -63,29 +63,38 @@ for output in outputs:
|
|
63 |
search_query = sorted(query2outputs)[0]
|
64 |
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
def aggregate(list_of_hits):
|
67 |
import numpy as np
|
68 |
from permsc import KemenyOptimalAggregator, sum_kendall_tau, ranks_from_preferences
|
69 |
from permsc import BordaRankAggregator
|
70 |
|
71 |
-
preferences =
|
72 |
-
for result in list_of_hits:
|
73 |
-
preferences.append([doc["rank"] - 1 for doc in result])
|
74 |
-
print([doc["docid"] for doc in result])
|
75 |
-
|
76 |
-
preferences = np.array(preferences)
|
77 |
y_optimal = KemenyOptimalAggregator().aggregate(preferences)
|
78 |
# y_optimal = BordaRankAggregator().aggregate(preferences)
|
79 |
|
80 |
-
rank2doc = {}
|
81 |
-
for doc in list_of_hits[0]:
|
82 |
-
rank2doc[doc["rank"] - 1] = doc
|
83 |
-
|
84 |
print("preference:")
|
85 |
print(preferences)
|
86 |
print("preferences shape: ", preferences.shape)
|
87 |
print("y_optimal: ", y_optimal)
|
88 |
-
|
|
|
89 |
|
90 |
aggregated_ranking = aggregate(query2outputs[search_query])
|
91 |
|
|
|
63 |
search_query = sorted(query2outputs)[0]
|
64 |
|
65 |
|
66 |
+
def preferences_from_hits(list_of_hits):
|
67 |
+
docid2id = {}
|
68 |
+
id2doc = {}
|
69 |
+
preferences = []
|
70 |
+
|
71 |
+
for result in list_of_hits:
|
72 |
+
for doc in result:
|
73 |
+
if doc["docid"] not in docid2id:
|
74 |
+
id = len(doc["docid"])
|
75 |
+
docid2id[doc["docid"]] = id
|
76 |
+
id2doc[id] = doc
|
77 |
+
preferences.append([docid2id[doc["rank"]] for doc in result])
|
78 |
+
|
79 |
+
# = {v: k for k, v in docid2id.items()}
|
80 |
+
return np.array(preferences), id2doc
|
81 |
+
|
82 |
+
|
83 |
def aggregate(list_of_hits):
|
84 |
import numpy as np
|
85 |
from permsc import KemenyOptimalAggregator, sum_kendall_tau, ranks_from_preferences
|
86 |
from permsc import BordaRankAggregator
|
87 |
|
88 |
+
preferences, id2doc = preferences_from_hits(list_of_hits)
|
|
|
|
|
|
|
|
|
|
|
89 |
y_optimal = KemenyOptimalAggregator().aggregate(preferences)
|
90 |
# y_optimal = BordaRankAggregator().aggregate(preferences)
|
91 |
|
|
|
|
|
|
|
|
|
92 |
print("preference:")
|
93 |
print(preferences)
|
94 |
print("preferences shape: ", preferences.shape)
|
95 |
print("y_optimal: ", y_optimal)
|
96 |
+
|
97 |
+
return [id2doc[id] for id in y_optimal]
|
98 |
|
99 |
aggregated_ranking = aggregate(query2outputs[search_query])
|
100 |
|