aboutsummaryrefslogtreecommitdiff
path: root/liblangdet/sentencepiece.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 14:38:02 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 14:38:02 +0200
commit91c6aa07597462705a7f30ee5b97e2c7943b5616 (patch)
treeb16f686279a1f1b0691a6c0d65a544084fcc1c1e /liblangdet/sentencepiece.h
parent6f98fc8cf3f7cc4b9d523d16492a07d3e2aea8c9 (diff)
downloadlangdet-91c6aa07597462705a7f30ee5b97e2c7943b5616.tar.gz
langdet-91c6aa07597462705a7f30ee5b97e2c7943b5616.zip
Remove unused checkpoint, tokenizer, and attention compatibility paths
Diffstat (limited to 'liblangdet/sentencepiece.h')
-rw-r--r--liblangdet/sentencepiece.h39
1 files changed, 11 insertions, 28 deletions
diff --git a/liblangdet/sentencepiece.h b/liblangdet/sentencepiece.h
index 2230538..0d8cf44 100644
--- a/liblangdet/sentencepiece.h
+++ b/liblangdet/sentencepiece.h
@@ -1,10 +1,7 @@
/*
- * SentencePiece tokenizer for XLM-R style models.
- *
- * Loads a SentencePiece ModelProto (sentencepiece.bpe.model, tokenizer.model,
- * or spiece.model) and implements the Unigram Viterbi encoder used by XLM-R
- * and multilingual E5. It encodes text only; frontends add the model's special
- * token layout, e.g. <s> ... </s> for XLM-R.
+ * XLM-R SentencePiece Unigram tokenizer.
+ * Encodes text using the checkpoint's precompiled normalization table.
+ * The caller adds the leading <s> and trailing </s> tokens.
*/
#ifndef TOK_SPM_H
@@ -13,29 +10,19 @@
#include <stddef.h>
#include <stdint.h>
-typedef enum {
- TOK_SPM_IDENTITY = 0,
- TOK_SPM_XLM_ROBERTA = 1,
-} tok_spm_id_map_t;
+enum {
+ TOK_XLMR_BOS_ID = 0,
+ TOK_XLMR_EOS_ID = 2,
+ TOK_XLMR_UNK_ID = 3,
+};
typedef struct {
char **id_to_piece; /* [piece_count] raw SentencePiece ids */
uint16_t *piece_lens; /* byte length for id_to_piece entries */
float *scores; /* SentencePiece score per raw id */
- uint8_t *types; /* SentencePiece piece type per raw id */
int piece_count; /* raw SentencePiece vocabulary size */
- int vocab_size; /* model embedding vocab size after id mapping */
- int unk_id; /* model-space unknown-token id */
- int bos_id; /* model-space beginning-token id, or -1 */
- int eos_id; /* model-space end-token id, or -1 */
- int pad_id; /* model-space pad-token id, or -1 */
- int mask_id; /* model-space mask-token id, or -1 */
- int max_piece_len; /* max normal/user/unused piece byte length */
+ int max_piece_len; /* longest normal piece in bytes */
double unknown_score; /* score assigned to an unmatched UTF-8 codepoint */
- int add_dummy_prefix;
- int remove_extra_whitespaces;
- int escape_whitespaces;
- tok_spm_id_map_t id_map;
void *piece_map; /* piece bytes -> raw SentencePiece id */
int piece_map_cap;
@@ -48,14 +35,10 @@ typedef struct {
typedef struct tok_spm_workspace tok_spm_workspace_t;
-/* Load the first supported SentencePiece model found in model_dir. Returns NULL
- * on missing model file, unsupported model type, malformed protobuf, or OOM. */
+/* Load model_dir/sentencepiece.bpe.model with XLM-R vocabulary and normalization.
+ * Return NULL on missing or unsupported model, malformed protobuf, or OOM. */
tok_spm_t *tok_spm_load(const char *model_dir);
-/* Resolve a named token (e.g. "<s>", "</s>", "<pad>", "<mask>") to a
- * model-space id, or -1 when absent. */
-int tok_spm_token_id(const tok_spm_t *tok, const char *token);
-
tok_spm_workspace_t *tok_spm_workspace_new(void);
void tok_spm_workspace_free(tok_spm_workspace_t *ws);