-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtokenizer.cpp
More file actions
33 lines (28 loc) · 867 Bytes
/
Copy pathtokenizer.cpp
File metadata and controls
33 lines (28 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "tokenizer.h"
#include <iostream>
#include <vector>
Tokenizer::Tokenizer() {}
Tokenizer::~Tokenizer() {}
bool Tokenizer::load(const std::string& path) {
auto status = sp.Load(path);
if (!status.ok()) {
std::cerr << "[SentencePiece] Erro: " << status.ToString() << std::endl;
return false;
}
std::cout << "[Tokenizer] Loaded via SentencePiece (.model)" << std::endl;
return true;
}
std::vector<int> Tokenizer::encode(const std::string& text) const {
std::vector<int> ids;
sp.Encode(text, &ids);
return ids;
}
std::string Tokenizer::decode(int prev_token, int token) const {
std::string s;
// Criamos o vetor de inteiros de forma explícita
std::vector<int> ids;
ids.push_back(token);
// Agora o compilador sabe exatamente qual função chamar
sp.Decode(ids, &s);
return s;
}