How to use logprobs hyperparameters? #1203
Answered
by
mspronesti
FocusLiwen
asked this question in
Q&A
-
Hi, logprobs is one of the sampling parameters. How should we use it exactly? Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
mspronesti
Sep 28, 2023
Replies: 1 comment 1 reply
-
Hi there. By adding the import openai
# Modify OpenAI's API key and API base to use vLLM's API server.
openai.api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1"
# List models API
models = openai.Model.list()
print("Models:", models)
model = models["data"][0]["id"]
# Completion API
stream = False
completion = openai.Completion.create(
model=model,
prompt="A robot may not injure a human being",
echo=False,
stream=stream,
logprobs=5)
print("Completion results:")
if stream:
for c in completion:
print(c)
else:
print(completion) The response should look like something like this
For each token, you can see the top K (5 in this example) most probable tokens and their log probabilities. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
FocusLiwen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there. By adding the
logprobs
parameter you can see the log-probabilities of the most likely tokens, as well as the chosen token.Consider the following example, which uses vLLM's OpenAI-compatible API