Commit
·
ae99f99
1
Parent(s):
9aae34a
Refactor handler.py to remove unnecessary code and return dense vectors as a list
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- handler.py +5 -0
__pycache__/handler.cpython-311.pyc
CHANGED
Binary files a/__pycache__/handler.cpython-311.pyc and b/__pycache__/handler.cpython-311.pyc differ
|
|
handler.py
CHANGED
@@ -27,6 +27,8 @@ class EndpointHandler():
|
|
27 |
result = self.model.encode(inputs, return_dense=True, return_sparse=False)
|
28 |
# print(result)
|
29 |
dense_vectors = result["dense_vecs"]
|
|
|
|
|
30 |
# sparse_vectors = result["lexical_weights"]
|
31 |
# defaultdict(<class 'int'>, {'6': 0.09546, '192661': 0.3323})
|
32 |
|
@@ -40,6 +42,9 @@ class EndpointHandler():
|
|
40 |
# レスポンスをの型をkey=str, value=floatのdictにする。なお、numpy.float16はjsonに変換できないので、floatに変換する。
|
41 |
# sparse_vectors = {str(k): float(v) for k, v in sparse_vectors.items()}
|
42 |
|
|
|
|
|
|
|
43 |
return [
|
44 |
[
|
45 |
{ "outputs": dense_vectors}
|
|
|
27 |
result = self.model.encode(inputs, return_dense=True, return_sparse=False)
|
28 |
# print(result)
|
29 |
dense_vectors = result["dense_vecs"]
|
30 |
+
|
31 |
+
|
32 |
# sparse_vectors = result["lexical_weights"]
|
33 |
# defaultdict(<class 'int'>, {'6': 0.09546, '192661': 0.3323})
|
34 |
|
|
|
42 |
# レスポンスをの型をkey=str, value=floatのdictにする。なお、numpy.float16はjsonに変換できないので、floatに変換する。
|
43 |
# sparse_vectors = {str(k): float(v) for k, v in sparse_vectors.items()}
|
44 |
|
45 |
+
# レスポンスの型をnumpy.ndarrayから、通常のarrayに変更する
|
46 |
+
dense_vectors = dense_vectors.tolist()
|
47 |
+
|
48 |
return [
|
49 |
[
|
50 |
{ "outputs": dense_vectors}
|