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

Add classification and NER examples to the documentation #471

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix output shape of greedy sampler with batch > 1
  • Loading branch information
rlouf committed Dec 22, 2023
commit 94e18139b9a7a414a481ec21d6b79a1c111add03
2 changes: 1 addition & 1 deletion outlines/generate/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def greedy(logits: torch.DoubleTensor, samples: int, *_) -> torch.DoubleTensor:

"""
if samples == 1:
next_token_ids = torch.argmax(logits, dim=-1, keepdim=True).T
next_token_ids = torch.argmax(logits, dim=-1, keepdim=True)
else:
next_token_ids = torch.topk(
logits, samples, dim=-1, largest=True, sorted=True
Expand Down
2 changes: 1 addition & 1 deletion tests/generate/test_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_greedy():

logits = torch.tensor([[10.0, 0.0, 3.0], [-math.inf, 2.0, 5.0]])
next_token_ids = greedy(logits, samples=1)
assert next_token_ids.equal(torch.tensor([[0, 2]]))
assert next_token_ids.equal(torch.tensor([[0], [2]]))

next_token_ids = greedy(logits, samples=2)
assert next_token_ids.equal(torch.tensor([[0, 2], [2, 1]]))
Expand Down