aboutsummaryrefslogtreecommitdiff
path: root/langdetect.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
commit37cbaef9ceb828c667da8f398027ba5415ee7475 (patch)
tree6103e92a9030766e78a35df00f7a1155d0d0ecf5 /langdetect.c
parentcf7d8169ec12cb3adf90d4ff78b3257e74985302 (diff)
downloadlangdet-37cbaef9ceb828c667da8f398027ba5415ee7475.tar.gz
langdet-37cbaef9ceb828c667da8f398027ba5415ee7475.zip
Rename CPU library API and sources to langdet
Diffstat (limited to 'langdetect.c')
-rw-r--r--langdetect.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/langdetect.c b/langdetect.c
index 003692d..6418d2d 100644
--- a/langdetect.c
+++ b/langdetect.c
@@ -17,9 +17,9 @@
#define MAX_TOKENS 512
typedef struct {
- ffwd_model_t *model;
- ffwd_workspace_t *workspace;
- ffwd_tok_t *tokenizer;
+ langdet_model_t *model;
+ langdet_workspace_t *workspace;
+ langdet_tok_t *tokenizer;
yyjson_doc *config;
const char *labels[NUM_LABELS];
const float *dense_weight, *dense_bias;
@@ -46,9 +46,9 @@ static const float *load_tensor(detector_t *d, const char *name, const int64_t *
}
static void detector_free(detector_t *d) {
- ffwd_tok_free(d->tokenizer);
- ffwd_workspace_free(d->workspace);
- ffwd_model_free(d->model);
+ langdet_tok_free(d->tokenizer);
+ langdet_workspace_free(d->workspace);
+ langdet_model_free(d->model);
yyjson_doc_free(d->config);
}
@@ -87,10 +87,10 @@ static int detector_load(detector_t *d, const char *directory) {
}
}
- d->model = ffwd_model_load(directory);
+ d->model = langdet_model_load(directory);
if (!d->model)
return -1;
- const ffwd_config_t *cfg = ffwd_model_config(d->model);
+ const langdet_config_t *cfg = langdet_model_config(d->model);
if (cfg->hidden_size != HIDDEN_SIZE ||
cfg->max_position_embeddings - cfg->position_id_offset < MAX_TOKENS) {
fprintf(stderr, "Expected a 768-dimensional XLM-R encoder with 512-token capacity\n");
@@ -106,12 +106,12 @@ static int detector_load(detector_t *d, const char *directory) {
return -1;
char message[256] = {0};
- d->tokenizer = ffwd_tok_open(directory, message, sizeof(message));
+ d->tokenizer = langdet_tok_open(directory, message, sizeof(message));
if (!d->tokenizer) {
fprintf(stderr, "Tokenizer: %s\n", message);
return -1;
}
- d->workspace = ffwd_workspace_new(d->model);
+ d->workspace = langdet_workspace_new(d->model);
if (!d->workspace) {
fprintf(stderr, "Cannot allocate inference workspace\n");
return -1;
@@ -122,7 +122,7 @@ static int detector_load(detector_t *d, const char *directory) {
static int classify(detector_t *d, const char *text, int all_scores) {
double start = now_ms();
int count = 0;
- int *ids = ffwd_tokenize(d->tokenizer, text, &count);
+ int *ids = langdet_tokenize(d->tokenizer, text, &count);
if (!ids || count < 2) {
fprintf(stderr, "Tokenization failed\n");
free(ids);
@@ -134,7 +134,7 @@ static int classify(detector_t *d, const char *text, int all_scores) {
count = MAX_TOKENS;
}
float hidden[HIDDEN_SIZE], dense[HIDDEN_SIZE], scores[NUM_LABELS];
- int result = ffwd_model_encode_into(d->model, d->workspace, ids, count, hidden);
+ int result = langdet_model_encode_into(d->model, d->workspace, ids, count, hidden);
free(ids);
if (result != 0) {
fprintf(stderr, "Encoder inference failed\n");