MCPcopy Create free account
hub / github.com/aarnphm/whispercpp / tokenize

Method tokenize

src/whispercpp/context.cc:221–235  ·  view source on GitHub ↗

Run the Whisper decoder to obtain the logits and probabilities for the next token. Make sure to call whisper_encode() first. tokens + n_tokens is the provided context for the decoder. n_past is the number of tokens to use from previous decoder calls. Returns vec on success.

Source from the content-addressed store, hash-verified

219// provided context for the decoder. n_past is the number of tokens to use
220// from previous decoder calls. Returns vec<whisper_token> on success.
221std::vector<whisper_token> Context::tokenize(std::string *text,
222 size_t max_tokens) {
223 std::vector<whisper_token> tokens;
224 tokens.reserve(max_tokens);
225
226 int ret = whisper_tokenize(wctx, text->c_str(), tokens.data(), max_tokens);
227
228 if (ret == -1) {
229 RAISE_RUNTIME_ERROR("Too many results tokens.");
230 } else {
231 // ret != -1 then length of the vector is at least ret tokens
232 tokens.reserve(ret);
233 }
234 return tokens;
235};
236
237// Returns id of a given language, raise exception if not found
238int Context::lang_str_to_id(const char *lang) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected