Files
cAI/cNLP/Library/c_NlpLanguageModel.h
pchen e6a29bcdfd c_NlpCharGraph: 分析一篇文章,建立字与字的关系
c_NlpNgramGraph: 基于 n 个已经出现的词,预估后续可能出现的词
c_NlpLanguageModel: 如果有的词组合形式没有出现过,找到之前学习过最长类似的词句进行预测
2026-08-10 03:12:45 +08:00

39 lines
1.7 KiB
C

#ifndef INCLUDED_C_NLPLANGUAGEMODEL_H
#define INCLUDED_C_NLPLANGUAGEMODEL_H
#ifndef INCLUDED_C_NLPNGRAMGRAPH_H
#include <c_NlpNgramGraph.h>
#endif /*INCLUDED_C_NLPNGRAMGRAPH_H*/
typedef struct {
c_NlpNgramGraph_t* levels; /* Array of N-gram graphs sorted from highest order down to 2-gram */
c_size_t max_n; /* The maximum configuration order N of the model (e.g., 3 for Trigram) */
double backoff_alpha; /* Proportional smoothing decay factor (typically 0.4) used per back-off step */
} c_NlpLanguageModel_t;
/**
* @brief Initializes a multi-tier cascaded Language Model environment supporting back-off smoothing.
* @param self Pointer to the uninitialized language model structure.
* @param max_n Maximum model order threshold (e.g., 3 creates a Trigram + Bigram cascading mesh).
* @param bucket_count Main hash allocation array size mapped down to sub-graphs.
* @return c_err_t C_ERR_OK on successful initialization, or dynamic memory OOM codes.
*/
c_err_t c_NlpLanguageModel_Init(c_NlpLanguageModel_t* self, c_size_t max_n, c_size_t bucket_count);
/**
* @brief Core Prediction: Evaluates histories and executes automated back-off smoothing cascades.
*/
c_err_t c_NlpLanguageModel_PredictSmooth(c_NlpLanguageModel_t* self, const c_ucs4_t* history_context, c_size_t history_len,
c_ucs4_t* out_next_char, double* out_confidence);
/**
* @brief Destroys and flushes all cascaded hierarchy sub-graphs completely.
*/
void c_NlpLanguageModel_Destroy(c_NlpLanguageModel_t* self);
c_err_t c_NlpLanguageModel_Train(c_NlpLanguageModel_t* self, const c_ucs4_t* unicode_array, c_size_t length);
#endif /*INCLUDED_C_NLPLANGUAGEMODEL_H*/