MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / bark_tokenize_input

Function bark_tokenize_input

bark.cpp:629–669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

627}
628
629static void bark_tokenize_input(struct bark_context* bctx, const std::string& text) {
630 auto& model = bctx->text_model.semantic_model;
631 bark_vocab* vocab = &bctx->text_model.vocab;
632
633 auto& params = bctx->params;
634
635 int32_t block_size = model.hparams.block_size;
636 int32_t max_ctx_size = std::min(block_size, 256);
637 int32_t n_tokens;
638
639 bark_sequence tokens(max_ctx_size);
640 bert_tokenize(vocab, text.data(), tokens.data(), &n_tokens, max_ctx_size);
641
642 for (int i = 0; i < (int)tokens.size(); i++)
643 tokens[i] += params.text_encoding_offset;
644
645 if (n_tokens < max_ctx_size) {
646 for (int i = n_tokens; i < max_ctx_size; i++)
647 tokens[i] = params.text_pad_token;
648 } else if (n_tokens > max_ctx_size) {
649 fprintf(stderr, "%s: input sequence is too long (%d > 256), truncating sequence", __func__, n_tokens);
650 }
651
652 tokens.resize(max_ctx_size);
653
654 // semantic history
655 for (int i = 0; i < 256; i++)
656 tokens.push_back(params.semantic_pad_token);
657 tokens.push_back(params.semantic_infer_token);
658
659 assert(tokens.size() == 256 + 256 + 1);
660
661 bctx->tokens = tokens;
662
663 printf("%s: prompt: '%s'\n", __func__, text.c_str());
664 printf("%s: number of tokens in prompt = %zu, first 8 tokens: ", __func__, bctx->tokens.size());
665 for (int i = 0; i < std::min(8, (int)bctx->tokens.size()); i++) {
666 printf("%d ", bctx->tokens[i]);
667 }
668 printf("\n\n");
669}
670
671static bool bark_vocab_load(std::ifstream& fin, bark_vocab* vocab) {
672 int32_t n_vocab;

Callers 1

bark_generate_audioFunction · 0.70

Calls 3

dataMethod · 0.80
bert_tokenizeFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected