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

COSMIT Move tokenization in its own function #32

Merged
merged 3 commits into from
Aug 1, 2023
Merged
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
14 changes: 5 additions & 9 deletions bark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,11 @@ bark_vocab::id gpt_sample(
return gpt_multinomial_sample(logits, rng, temp, eos_p);
}

bark_sequence bark_tokenize_input(
const char * text,
const bark_vocab & vocab,
const int32_t block_size) {
bark_sequence bark_tokenize_input(const char * text, const bark_vocab & vocab, int32_t block_size) {
// max bark length: 256
int32_t max_ctx_size = std::min(block_size, 256);

int32_t n_tokens;

bark_sequence tokens(max_ctx_size);

bert_tokenize(vocab, text, tokens.data(), &n_tokens, max_ctx_size);
Expand Down Expand Up @@ -1494,8 +1492,6 @@ bool bark_generate_audio(
const bark_vocab& vocab,
const char * text,
const int n_threads) {
bark_sequence tokens;

// TODO move into params
// const int top_k = 10;
const int seed = 0;
Expand All @@ -1513,8 +1509,8 @@ bool bark_generate_audio(

std::mt19937 rng(seed);

// bert tokenizer
const int32_t block_size = model.text_model.hparams.block_size;
// tokenize input (bert tokenizer)
int32_t block_size = model.text_model.hparams.block_size;
bark_sequence tokens = bark_tokenize_input(text, vocab, block_size);

printf("%s: prompt: '%s'\n", __func__, text);
Expand Down