@@ -49,24 +49,24 @@ def _post_process_onnx_output(
4949 if not is_doc :
5050 for embedding in output .model_output :
5151 yield embedding
52-
53- if output .input_ids is None or output .attention_mask is None :
54- raise ValueError (
55- "input_ids and attention_mask must be provided for document post-processing"
56- )
57-
58- for i , token_sequence in enumerate (output .input_ids ):
59- for j , token_id in enumerate (token_sequence ): # type: ignore
60- if token_id in self .skip_list or token_id == self .pad_token_id :
61- output .attention_mask [i , j ] = 0
62-
63- output .model_output *= np .expand_dims (output .attention_mask , 2 )
64- norm = np .linalg .norm (output .model_output , ord = 2 , axis = 2 , keepdims = True )
65- norm_clamped = np .maximum (norm , 1e-12 )
66- output .model_output /= norm_clamped
67-
68- for embedding , attention_mask in zip (output .model_output , output .attention_mask ):
69- yield embedding [attention_mask == 1 ]
52+ else :
53+ if output .input_ids is None or output .attention_mask is None :
54+ raise ValueError (
55+ "input_ids and attention_mask must be provided for document post-processing"
56+ )
57+
58+ for i , token_sequence in enumerate (output .input_ids ):
59+ for j , token_id in enumerate (token_sequence ): # type: ignore
60+ if token_id in self .skip_list or token_id == self .pad_token_id :
61+ output .attention_mask [i , j ] = 0
62+
63+ output .model_output *= np .expand_dims (output .attention_mask , 2 )
64+ norm = np .linalg .norm (output .model_output , ord = 2 , axis = 2 , keepdims = True )
65+ norm_clamped = np .maximum (norm , 1e-12 )
66+ output .model_output /= norm_clamped
67+
68+ for embedding , attention_mask in zip (output .model_output , output .attention_mask ):
69+ yield embedding [attention_mask == 1 ]
7070
7171 def _preprocess_onnx_input (
7272 self , onnx_input : dict [str , NumpyArray ], is_doc : bool = True , ** kwargs : Any
0 commit comments