MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / rank

Method rank

plugins/wasi_nn/MLX/model/whisper/decoding.cpp:376–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374 : LengthPenalty(LengthPenalty) {}
375
376std::vector<int> MaximumLikelihoodRanker::rank(
377 const std::vector<std::vector<std::vector<int>>> &Tokens,
378 const std::vector<std::vector<float>> &SumLogprobs) {
379
380 std::vector<int> Selected;
381
382 for (size_t I = 0; I < Tokens.size(); ++I) {
383 std::vector<float> Scores;
384
385 for (size_t J = 0; J < Tokens[I].size(); ++J) {
386 int Length = Tokens[I][J].size();
387 float Logprob = SumLogprobs[I][J];
388
389 float Penalty;
390 if (LengthPenalty) {
391 Penalty = std::pow(Length, *LengthPenalty);
392 } else {
393 Penalty = Length;
394 }
395
396 Scores.push_back(Logprob / Penalty);
397 }
398
399 auto MaxIterator = std::max_element(Scores.begin(), Scores.end());
400 Selected.push_back(std::distance(Scores.begin(), MaxIterator));
401 }
402
403 return Selected;
404}
405
406// DecodingTask implementation - Constructor and helper methods
407DecodingTask::DecodingTask(std::shared_ptr<Whisper> Model,

Callers 1

runMethod · 0.80

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected