diff options
Diffstat (limited to 'libffwd/sentencepiece.c')
| -rw-r--r-- | libffwd/sentencepiece.c | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/libffwd/sentencepiece.c b/libffwd/sentencepiece.c index e5e8393..6c30ba1 100644 --- a/libffwd/sentencepiece.c +++ b/libffwd/sentencepiece.c @@ -472,23 +472,6 @@ static int raw_to_model_id(const tok_spm_t *tok, int raw_id) { return raw_id; } -static int model_to_raw_id(const tok_spm_t *tok, int id) { - if (!tok || id < 0) - return -1; - if (tok->id_map == TOK_SPM_XLM_ROBERTA) { - if (id == 0) - return 1; - if (id == 2) - return 2; - if (id == 3) - return 0; - if (id >= 4 && id <= tok->piece_count) - return id - 1; - return -1; - } - return id < tok->piece_count ? id : -1; -} - static int file_contains_xlm_roberta(const char *model_dir, const char *name) { char path[1024]; int n = snprintf(path, sizeof(path), "%s/%s", model_dir, name); @@ -825,19 +808,6 @@ tok_spm_t *tok_spm_load(const char *model_dir) { return tok; } -const char *tok_spm_decode(const tok_spm_t *tok, int id) { - if (!tok || id < 0) - return NULL; - if (tok->id_map == TOK_SPM_XLM_ROBERTA) { - if (id == 1) - return "<pad>"; - if (id == tok->piece_count + 1) - return "<mask>"; - } - int raw = model_to_raw_id(tok, id); - return raw >= 0 ? tok->id_to_piece[raw] : NULL; -} - int tok_spm_token_id(const tok_spm_t *tok, const char *token) { if (!tok || !token) return -1; @@ -856,7 +826,7 @@ int tok_spm_token_id(const tok_spm_t *tok, const char *token) { return raw_to_model_id(tok, raw_piece_id(tok, token)); } -int tok_spm_encode_into(const tok_spm_t *tok, +static int tok_spm_encode_into(const tok_spm_t *tok, tok_spm_workspace_t *ws, const char *text, int *out_ids, @@ -904,18 +874,6 @@ int *tok_spm_encode_with_workspace(const tok_spm_t *tok, return ids; } -int *tok_spm_encode(const tok_spm_t *tok, const char *text, int *out_n_tokens) { - tok_spm_workspace_t *ws = tok_spm_workspace_new(); - if (!ws) { - if (out_n_tokens) - *out_n_tokens = 0; - return NULL; - } - int *ids = tok_spm_encode_with_workspace(tok, ws, text, out_n_tokens); - tok_spm_workspace_free(ws); - return ids; -} - tok_spm_workspace_t *tok_spm_workspace_new(void) { return (tok_spm_workspace_t *)calloc(1, sizeof(tok_spm_workspace_t)); } |
