Commit
·
c0a3a1a
1
Parent(s):
b025097
Refactor handler.py to use relative path for model initialization
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- handler.py +6 -11
__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
@@ -5,10 +5,10 @@ from FlagEmbedding import BGEM3FlagModel
|
|
5 |
|
6 |
|
7 |
class EndpointHandler():
|
8 |
-
def __init__(self, path="
|
9 |
# load the optimized model
|
10 |
# モデルの準備
|
11 |
-
self.model = BGEM3FlagModel(
|
12 |
|
13 |
|
14 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
@@ -24,14 +24,9 @@ class EndpointHandler():
|
|
24 |
inputs = data.pop("inputs", data)
|
25 |
parameters = data.pop("parameters", None)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
# sparse_vectors = result["lexical_weights"]
|
31 |
-
# for sparse_vector in sparse_vectors:
|
32 |
-
# sparse_values = [value for value in sparse_vector.values()]
|
33 |
-
# sparse_dimensions = [int(key) for key in sparse_vector.keys()]
|
34 |
-
# sparse_embs.append((sparse_values, sparse_dimensions))
|
35 |
|
36 |
# pass inputs with all kwargs in data
|
37 |
# if parameters is not None:
|
@@ -41,6 +36,6 @@ class EndpointHandler():
|
|
41 |
# postprocess the prediction
|
42 |
return [
|
43 |
[
|
44 |
-
{
|
45 |
]
|
46 |
]
|
|
|
5 |
|
6 |
|
7 |
class EndpointHandler():
|
8 |
+
def __init__(self, path="."):
|
9 |
# load the optimized model
|
10 |
# モデルの準備
|
11 |
+
self.model = BGEM3FlagModel(path, use_fp16=False)
|
12 |
|
13 |
|
14 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
|
|
24 |
inputs = data.pop("inputs", data)
|
25 |
parameters = data.pop("parameters", None)
|
26 |
|
27 |
+
result = self.model.encode(inputs, return_dense=False, return_sparse=True)
|
28 |
+
sparse_vectors = result["lexical_weights"]
|
29 |
+
# defaultdict(<class 'int'>, {'6': 0.09558245, '192661': 0.33248675})}
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
# pass inputs with all kwargs in data
|
32 |
# if parameters is not None:
|
|
|
36 |
# postprocess the prediction
|
37 |
return [
|
38 |
[
|
39 |
+
{ "outputs": sparse_vectors}
|
40 |
]
|
41 |
]
|