From d5f47b424dbf556e56468b936ce6d5b1ac65f898 Mon Sep 17 00:00:00 2001 From: Takayuki Enomoto <4161768+tkykenmt@users.noreply.github.com> Date: Sat, 4 Jan 2025 07:46:48 +0900 Subject: [PATCH] fix post_process_function on rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md (#3296) * fix post_process_function bug on sort results for rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md (#3247) Signed-off-by: tkykenmt * fix typo Signed-off-by: Yaliang Wu --------- Signed-off-by: tkykenmt Signed-off-by: Yaliang Wu Co-authored-by: Yaliang Wu --- ...erank-m3-v2_model_deployed_on_Sagemaker.md | 141 ++++++++++++++++-- 1 file changed, 127 insertions(+), 14 deletions(-) diff --git a/docs/tutorials/rerank/rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md b/docs/tutorials/rerank/rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md index 238f62300e..10b317da4a 100644 --- a/docs/tutorials/rerank/rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md +++ b/docs/tutorials/rerank/rerank_pipeline_with_bge-rerank-m3-v2_model_deployed_on_Sagemaker.md @@ -59,10 +59,39 @@ result = predictor.predict(data={ ] }) -print(json.dumps(sorted(result, key=lambda x: x['index']), indent=2)) +print(json.dumps(result, indent=2)) ``` -The reranking results are as follows: +The reranking result is ordering by the highest score first: +``` +[ + { + "index": 2, + "score": 0.92879725 + }, + { + "index": 0, + "score": 0.013636836 + }, + { + "index": 1, + "score": 0.000593021 + }, + { + "index": 3, + "score": 0.00012148176 + } +] +``` + +You can sort the result by index number. + +```python +print(json.dumps(sorted(result, key=lambda x: x['index']),indent=2)) + +``` + +The results are as follows: ``` [ @@ -121,9 +150,51 @@ POST /_plugins/_ml/connectors/_create "headers": { "content-type": "application/json" }, - "request_body": "{ \"query\": \"${parameters.query}\", \"texts\": ${parameters.texts} }", - "pre_process_function": "\n def query_text = params.query_text;\n def text_docs = params.text_docs;\n def textDocsBuilder = new StringBuilder('[');\n for (int i=0; i