takanezawa commited on
Commit
0d6d4f8
·
1 Parent(s): 90973f8

chore: Update handler.py to return sparse vectors as a dictionary

Browse files
__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
@@ -26,7 +26,7 @@ class EndpointHandler():
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:
@@ -34,6 +34,10 @@ class EndpointHandler():
34
  # else:
35
  # prediction = self.pipeline(inputs)
36
  # postprocess the prediction
 
 
 
 
37
  return [
38
  [
39
  { "outputs": sparse_vectors}
 
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.09546, '192661': 0.3323})
30
 
31
  # pass inputs with all kwargs in data
32
  # if parameters is not None:
 
34
  # else:
35
  # prediction = self.pipeline(inputs)
36
  # postprocess the prediction
37
+
38
+ # レスポンスをの型をkey=str, value=floatのdictにする。なお、numpy.float16はjsonに変換できないので、floatに変換する。
39
+ sparse_vectors = {str(k): float(v) for k, v in sparse_vectors.items()}
40
+
41
  return [
42
  [
43
  { "outputs": sparse_vectors}