Skip to content

Commit

Permalink
Fix issue causing choices to be scored improperly
Browse files Browse the repository at this point in the history
  • Loading branch information
jncraton committed Feb 24, 2024
1 parent 65d761f commit cd77973
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.18.0

### Fixed

- Correct issue causing `choices` to be scored improperly

## 0.17.0 - 2024-02-15

### Added
Expand Down
8 changes: 8 additions & 0 deletions languagemodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def do(prompt, choices=None):
>>> do(["Say red", "Say blue"], choices=["red", "blue"])
['red', 'blue']
>>> do("Classify as positive or negative: LLMs are bad",
... choices=["Positive", "Negative"])
'Negative'
>>> do("Classify as positive or negative: LLMs are great",
... choices=["Positive", "Negative"])
'Positive'
"""

prompts = [prompt] if isinstance(prompt, str) else prompt
Expand Down
4 changes: 2 additions & 2 deletions languagemodels/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ def rank_instruct(inputs, targets):
"""
tokenizer, model = get_model("instruct")

targ_tok = [tokenizer.encode(t, add_special_tokens=False).tokens for t in targets]
targ_tok = [tokenizer.encode(t).tokens for t in targets]
targ_tok *= len(inputs)

in_tok = []
for input in inputs:
toks = [tokenizer.encode(input, add_special_tokens=False).tokens]
toks = [tokenizer.encode(input).tokens]
in_tok += toks * len(targets)

if "Generator" in str(type(model)):
Expand Down

0 comments on commit cd77973

Please sign in to comment.