27 lines
709 B
C++
27 lines
709 B
C++
#include "tokenizer.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
int main(void) {
|
|
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: ", tok); // NOLINT
|
|
std::cout << bpe.token_text(tok) << '\n';
|
|
}
|
|
|
|
std::cout << bpe.decode(tokens) << '\n';
|
|
return 0;
|
|
}
|