Skip to content

Tokenizer clang format #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/hf_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Error HFTokenizer::load(const std::string& path) {
[](const auto& it) -> std::uint64_t { return it.at("id"); }));

// Create special token regex to help later with encoding.
special_token_regex_ = TK_UNWRAP(detail::build_special_token_regex(special_token_map));
special_token_regex_ =
TK_UNWRAP(detail::build_special_token_regex(special_token_map));

// Store for future use.
special_token_map_.emplace(std::move(special_token_map));
Expand Down Expand Up @@ -147,15 +148,15 @@ Error HFTokenizer::load(const std::string& path) {

// Pull out the token strings
try {
const std::string bos_token =
parsed_config_json.contains("bos_token") && !parsed_config_json["bos_token"].is_null()
? parsed_config_json["bos_token"].get<std::string>()
: "";
const std::string bos_token = parsed_config_json.contains("bos_token") &&
!parsed_config_json["bos_token"].is_null()
? parsed_config_json["bos_token"].get<std::string>()
: "";

const std::string eos_token =
parsed_config_json.contains("eos_token") && !parsed_config_json["eos_token"].is_null()
? parsed_config_json["eos_token"].get<std::string>()
: "";
const std::string eos_token = parsed_config_json.contains("eos_token") &&
!parsed_config_json["eos_token"].is_null()
? parsed_config_json["eos_token"].get<std::string>()
: "";
const auto bos_res = special_token_map_->tryGetInteger(bos_token);
const auto eos_res = special_token_map_->tryGetInteger(eos_token);
if (!bos_res) {
Expand Down
3 changes: 1 addition & 2 deletions src/tiktoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static Result<std::unique_ptr<IRegex>> _create_regex(
return create_regex(pattern);
}


static Result<std::pair<std::string, uint64_t>> _parse(
const std::string& line) {
// Tiktoken format
Expand Down Expand Up @@ -138,7 +137,7 @@ Error Tiktoken::load(const std::string& path) {

_regex = TK_UNWRAP(_create_regex(_pattern));
special_token_regex_ =
TK_UNWRAP(detail::build_special_token_regex(TokenMap(special_token_map)));
TK_UNWRAP(detail::build_special_token_regex(TokenMap(special_token_map)));

// initialize vocab_size, bos_tok, eos_tok
vocab_size_ = token_map_->size() + special_token_map_->size();
Expand Down