feat: add dump and load to tokenizer
This commit is contained in:
+17
-5
@@ -1,14 +1,26 @@
|
||||
#include "tokenizer.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
int main(void) {
|
||||
// static constexpr const char* filepath = "./gpt-training.txt";
|
||||
tokenizer<259> bpe;
|
||||
bpe.train("abcabcd");
|
||||
auto tokens = bpe.encode("abc");
|
||||
static constexpr const char* filepath = "./gpt/shakespeare.txt";
|
||||
|
||||
std::ifstream file(filepath, std::ios::binary);
|
||||
if (!file.is_open()) return 1;
|
||||
std::string contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
|
||||
tokenizer<2256> bpe;
|
||||
bpe.train(contents);
|
||||
bpe.dump("./gpt/shakespeare.bpe");
|
||||
auto tokens = bpe.encode("Hello, World!");
|
||||
for (auto tok : tokens) {
|
||||
std::printf("0x%08X\n", tok); // NOLINT
|
||||
std::printf("0x%08X: ", tok); // NOLINT
|
||||
std::cout << bpe.token_text(tok) << '\n';
|
||||
}
|
||||
|
||||
std::cout << bpe.decode(tokens) << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user