Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TogetherAI Multiple Choice Logprobs #99

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions concordia/language_model/together_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def sample_choice(
) -> tuple[int, str, dict[str, float]]:

def _sample_choice(response: str) -> float:
augmented_prompt = prompt + response
augmented_prompt = prompt
original_augmented_prompt = augmented_prompt
augmented_prompt = _ensure_prompt_not_too_long(augmented_prompt, 1)
messages = [
Expand Down Expand Up @@ -282,7 +282,14 @@ def _sample_choice(response: str) -> float:
break

if result:
lp = sum(result.choices[0].logprobs.token_logprobs)
token_logprob_pairs = [
(token, logprob)
for token, logprob in zip(result.choices[0].logprobs.tokens, result.choices[0].logprobs.token_logprobs)
]
response_logprob = [
logprob for token, logprob in token_logprob_pairs if token.startswith(response)
]
lp = response_logprob[0] if len(response_logprob) > 0 else float('-inf')
else:
raise ValueError(
f'Failed to get logprobs.\nException prompt: {augmented_prompt}')
Expand Down