Skip to content

Commit

Permalink
strip leading whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
karpathy committed Jul 27, 2023
1 parent 25b50ee commit e5752e1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion run.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ int main(int argc, char *argv[]) {
// we now want to sample from this distribution to get the next token
next = sample(state.logits, config.vocab_size);
}
printf("%s", vocab[next]);
// following BOS token (1), sentencepiece decoder strips any leading whitespace (see PR #89)
char *token_str = (token == 1 && vocab[next][0] == ' ') ? vocab[next]+1 : vocab[next];
printf("%s", token_str);
fflush(stdout);

// advance forward
Expand Down

0 comments on commit e5752e1

Please sign in to comment.