MCPcopy Create free account
hub / github.com/alibaba/MNN / encodeSingle

Method encodeSingle

transformers/diffusion/engine/src/tokenizer.cpp:43–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43std::vector<int> MtokTokenizer::encodeSingle(const std::string& sentence, int maxlen) const {
44#if defined(MNN_DIFFUSION_WITH_LLM_TOKENIZER)
45 if (mTokenizer == nullptr) {
46 return {};
47 }
48 std::vector<int> ids = mTokenizer->encode(sentence);
49 if (mBosId >= 0 && (ids.empty() || ids.front() != mBosId)) {
50 ids.insert(ids.begin(), mBosId);
51 }
52 if (mEosId >= 0 && (ids.empty() || ids.back() != mEosId)) {
53 ids.push_back(mEosId);
54 }
55 if (maxlen > 0) {
56 if ((int)ids.size() > maxlen) {
57 ids.resize(maxlen);
58 if (mEosId >= 0) {
59 ids[maxlen - 1] = mEosId;
60 }
61 } else {
62 while ((int)ids.size() < maxlen) {
63 ids.push_back(0);
64 }
65 }
66 }
67 return ids;
68#else
69 (void)sentence;
70 (void)maxlen;
71 return {};
72#endif
73}
74
75std::vector<int> MtokTokenizer::encode(const std::string& sentence, int maxlen) {
76#if defined(MNN_DIFFUSION_WITH_LLM_TOKENIZER)

Callers

nothing calls this directly

Calls 9

backMethod · 0.80
encodeMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected