Portable ARPA backoff language models, corpus scoring, rescoring and count training
moon add TerryFFF-jenius/moonarpa@0.1.0import { "TerryFFF-jenius/moonarpa" @arpa }fn main raise {
let model = @arpa.count_corpus([
["open", "the", "door"],
["open", "the", "door"],
["close", "the", "window"],
], 3).train_discount()
let score = model.sentence(["open", "the", "door"])
println(score.to_json().stringify())
let text = model.to_arpa()
let restored = @arpa.parse(text)
assert_eq(restored.sentence(["open", "the", "door"]), score)
}| 接口 | 用途 |
|---|---|
| parse / Model::new / to_arpa | 严格解析、构造验证、确定性导出 |
| conditional(history, token) | 返回最长匹配阶数、回退次数、回退权重和 OOV 映射 |
| sentence / score_text / corpus / score_lines | 逐词评分与按预测事件加权的语料指标 |
| scorer / feed_batch / fork / finish | 独立增量状态、失败批次原子回滚、幂等结束 |
| predict / rank_candidates / rescore | 全词表前 k 项、候选集合排序、句子 n-best 重排 |
| Mixture::new | 同词表模型的概率混合,内部稳定 log-sum-exp |
| count_corpus / Counts::merge | 有界计数与分片合并 |
| train_mle / train_discount | MLE 与插值绝对折扣 ARPA 训练 |
| fit_vocabulary / transform | 训练集拟合固定词表与留出集 <unk> 映射 |
| audit_mass / audit_contexts / summary | 概率质量及模型结构诊断 |
| execute / handle | 可移植 JSON 任务引擎与成功/错误信封 |
moon run examples/speech
moon run examples/corpus
moon run examples/train
python scripts/run_request.py fixtures/train-request.json --target wasm-gcmoon info
moon fmt --check
moon check --deny-warn --target wasm-gc
moon test --deny-warn --target wasm-gc
moon build --deny-warn --target wasm-gc
python scripts/check_project.py
python scripts/verify_oracle.py --target wasm-gc
python scripts/verify_reference.py --target wasm-gcpub(all) struct CorpusScore {
sentences : Int
predicted : Int
oov_count : Int
impossible : Int
log_probability : Double
sentence_scores : Array[SentenceScore]
} derive(Eq, Debug)fn FittedVocabulary::transform(self : FittedVocabulary, sentences : Array[Array[String]]) -> MappedCorpus raise ArpaErrorfn Mixture::sentence(self : Mixture, tokens : Array[String], options? : ScoreOptions) -> SentenceScore raise ArpaErrorfn Model::corpus(self : Model, sentences : Array[Array[String]], options? : ScoreOptions) -> CorpusScore raise ArpaErrorfn Model::rescore(self : Model, hypotheses : Array[Hypothesis], options? : RescoreOptions) -> Array[RankedHypothesis] raise ArpaErrorfn Model::score_lines(self : Model, text : String, options? : ScoreOptions) -> CorpusScore raise ArpaErrorfn Model::score_text(self : Model, text : String, options? : ScoreOptions) -> SentenceScore raise ArpaErrorfn Model::sentence(self : Model, tokens : Array[String], options? : ScoreOptions) -> SentenceScore raise ArpaErrorpub(all) struct RankedHypothesis {
id : String
input_index : Int
score : Double
language : SentenceScore
} derive(Eq, Debug)pub(all) struct RescoreOptions {
lm_weight : Double
acoustic_weight : Double
length_weight : Double
scoring : ScoreOptions
} derive(Eq, Debug)pub struct Scorer {
model : Model
options : ScoreOptions
history : Array[String]
results : Array[TokenScore]
total : Double
text_units : Int
oovs : Int
closed : Bool
}pub(all) struct SentenceScore {
log_probability : Double
predicted : Int
oov_count : Int
tokens : Array[TokenScore]
} derive(Eq, Debug)fn fit_vocabulary(sentences : Array[Array[String]], options? : VocabularyOptions, limits? : Limits) -> FittedVocabulary raise ArpaErrorInstall
Download zipPortable ARPA backoff language models, corpus scoring, rescoring and count training