rank_llm icon indicating copy to clipboard operation
rank_llm copied to clipboard

RankGPT-4o does not work for TREC DL19 and 20 query

Open Mandeep-Rathee opened this issue 4 months ago • 0 comments

Hey, thanks for providing the wonderful library.

I am using the GPT-4o model as a Ranker. I use BM25 as the initial retriever (take top 100 results). My code breaks for only one query from each TREC DL19 and DL20. For TREC DL19, the query ID is "131843" and the query is

definition of a sigmet

For DL20, the query id is "768208" and the query is

what is mamey

The error seems to be from https://github.com/castorini/rank_llm/blob/main/src/rank_llm/rerank/listwise/rank_gpt.py#L162C1-L179C56

def run_llm(
        self,
        prompt: Union[str, List[Dict[str, str]]],
        current_window_size: Optional[int] = None,
    ) -> Tuple[str, int]:
        model_key = "model"
        response = self._call_completion(
            messages=prompt,
            temperature=0,
            completion_mode=SafeOpenai.CompletionMode.CHAT,
            return_text=True,
            **{model_key: self._model},
        )
       
        try:
            encoding = tiktoken.get_encoding(self._model)
        except:
            encoding = tiktoken.get_encoding("cl100k_base")
        return response, len(encoding.encode(response))

I am getting the following error:

lib/python3.11/site-packages/tiktoken/core.py", line 111, in encode                                                                        
    raise TypeError(f"Expected 'text' to be a string, but got {type(text)}")                                                                                                  
TypeError: Expected 'text' to be a string, but got <class 'NoneType'> 
                                                                                     `

The response is None

print(response)
>> None

This is the output from completion

ChatCompletion(id=None, choices=[Choice(finish_reason='stop', index=None, logprobs=None, message=ChatCompletionMessage(content=None, refusal=None, role='assistant'
, function_call=None, tool_calls=None))], created=1728425889.0, model='gpt-4o', object='chat.completion', service_tier=None, system_fingerprint='fp_67802d9a6d', usage=Complet
ionUsage(completion_tokens=None, prompt_tokens=1462, total_tokens=1462), duration={'total': 312499305}, estimated_cost={'prompt': 0.00731, 'total': 0.00731})

Is there any way to fix the issue?

thanks

Mandeep-Rathee avatar Oct 08 '24 23:10 Mandeep-Rathee