#How do I use logprob?
1 messages · Page 1 of 1 (latest)
Hi @ripe token. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The logprobs parameter is available in the Chat Completions API and Legacy Completions API of OpenAI. When enabled, it returns the log probabilities of each output token, along with a limited number of the most likely tokens at each token position and their log probabilities. This can be useful to assess the confidence of the model in its output, or to examine alternative responses the model might have given source (https://platform.openai.com/docs/advanced-usage/advanced-usage).
However, it's important to note that the logprobs option is currently not available on the gpt-4-vision-preview model source (https://cookbook.openai.com/examples/using_logprobs).
In terms of usage, logprobs can be used in a variety of ways:
-
Classification tasks:
logprobsprovide a probability associated with each class prediction, enabling users to set their own classification or confidence thresholds source (https://cookbook.openai.com/examples/using_logprobs). -
Retrieval (Q&A) evaluation:
logprobscan assist with self-evaluation in retrieval applications. In the Q&A example, the model outputs a contrivedhas_sufficient_context_for_answerboolean, which can serve as a confidence score of whether the answer is contained in the retrieved content source (https://cookbook.openai.com/examples/using_logprobs). -
Autocomplete:
logprobscould help us decide how to suggest words as a user is typing source (https://cookbook.openai.com/examples/using_logprobs).
-
Token highlighting and outputting bytes: Users can easily create a token highlighter using the built-in tokenization that comes with enabling
logprobs. Additionally, the bytes parameter includes the ASCII encoding of each output character, which is particularly useful for reproducing emojis and special characters source (https://cookbook.openai.com/examples/using_logprobs). -
Calculating perplexity:
logprobscan be used to help us assess the model's overall confidence in a result and help us compare the confidence of results from different prompts source (https://cookbook.openai.com/examples/using_logprobs).
There are many other use cases for logprobs that are not covered in this cookbook. We can use logprobs for moderation, keyword selection, improving prompts and interpretability of outputs, token healing, and more source (https://cookbook.openai.com/examples/using_logprobs).
To access logprobs, you would need to set the logprobs parameter to True when making a request to the API. For example:
API_RESPONSE = get_completion(
[
{
"role": "user",
"content": PROMPT.format(
article=ada_lovelace_article, question=question
),
}
],
model="gpt-4",
logprobs=True,
top_logprobs=3,
)