Spaces:
Sleeping
Sleeping
Update resource/functions.py
Browse files- resource/functions.py +22 -9
resource/functions.py
CHANGED
|
@@ -73,13 +73,17 @@ class FAISS_inference:
|
|
| 73 |
|
| 74 |
vec = df["vec"].to_numpy()
|
| 75 |
self.d = vec[0].shape[0]
|
| 76 |
-
for i, e in enumerate(vec):
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# self.index = faiss.IndexFlatIP(self.d)
|
| 85 |
# self.index = faiss.IndexFlatL2(self.d)
|
|
@@ -91,6 +95,15 @@ class FAISS_inference:
|
|
| 91 |
|
| 92 |
d, i = self.index.search(self.emb, self.k)
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
return faiss_table
|
|
|
|
| 73 |
|
| 74 |
vec = df["vec"].to_numpy()
|
| 75 |
self.d = vec[0].shape[0]
|
| 76 |
+
# for i, e in enumerate(vec):
|
| 77 |
+
# if i == 0:
|
| 78 |
+
# vex = e.T
|
| 79 |
+
# else:
|
| 80 |
+
# temp = e.T
|
| 81 |
+
# vex = np.append(vex, temp)
|
| 82 |
+
vex = np.vstack(vec) # Используем vstack для объединения массивов
|
| 83 |
+
|
| 84 |
+
# self.vex = np.reshape(vex, (-1, 384))
|
| 85 |
+
|
| 86 |
+
self.vex = vex
|
| 87 |
|
| 88 |
# self.index = faiss.IndexFlatIP(self.d)
|
| 89 |
# self.index = faiss.IndexFlatL2(self.d)
|
|
|
|
| 95 |
|
| 96 |
d, i = self.index.search(self.emb, self.k)
|
| 97 |
|
| 98 |
+
unique_indices = np.unique(
|
| 99 |
+
i[0]
|
| 100 |
+
) # Получаем уникальные индексы для исключения дубликатов
|
| 101 |
+
|
| 102 |
+
# faiss_table = self.df.iloc[i[0]]
|
| 103 |
+
# faiss_table.loc[:, "score"] = d[0]
|
| 104 |
+
|
| 105 |
+
faiss_table = self.df.iloc[unique_indices]
|
| 106 |
+
faiss_table["score"] = d[0][
|
| 107 |
+
: len(unique_indices)
|
| 108 |
+
] # Присваиваем скоры, учитывая уникальность
|
| 109 |
return faiss_table
|