npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sarmay/kaz-converter-lm

v0.1.1

Published

Node.js LM and ONNX helpers for @sarmay/kaz-converter.

Downloads

403

Readme

@sarmay/kaz-converter-lm

@sarmay/kaz-converter-lm@sarmay/kaz-converter 的 Node.js LM 扩展包。

它负责:

  • ONNX masked language model 打分
  • 歧义词候选句打分选择
  • 直接创建可用的 ArabicToCyrillicConverter

这个包只面向 Node.js,不面向浏览器。

安装

npm install @sarmay/kaz-converter @sarmay/kaz-converter-lm

这个包会自动安装 onnxruntime-node@huggingface/tokenizers,使用者不需要再手动装第三份依赖。

官方模型

推荐直接使用:

在本仓库里也可以直接下载:

npm run download:model:kazbert

如果你是从 npm 安装这个包,而不是在仓库源码里工作,推荐直接用包自带 CLI:

npx sarmay-kaz-download

也可以指定目录:

npx sarmay-kaz-download ./models/KazakhBERTmulti-onnx

这个 CLI 支持:

  • 已完成文件自动跳过
  • 中断后的大文件自动续传
  • 网络错误自动重试

最简单的用法

先把 ONNX 模型目录准备好,例如:

models/KazakhBERTmulti-onnx/
  model.onnx
  tokenizer.json
  tokenizer_config.json
  special_tokens_map.json

然后:

import { createOnnxArabicToCyrillicConverter } from "@sarmay/kaz-converter-lm";

const converter = await createOnnxArabicToCyrillicConverter({
  modelDirectory: "./models/KazakhBERTmulti-onnx"
});

console.log(await converter.convertAsync("الما بار."));
console.log(await converter.convertAsync("بىر كۇنى"));

分步用法

import { ArabicToCyrillicConverter } from "@sarmay/kaz-converter";
import {
  CandidateLanguageModelDisambiguator,
  OnnxMaskedLanguageModelScorer
} from "@sarmay/kaz-converter-lm";

const scorer = await OnnxMaskedLanguageModelScorer.fromDirectory("./models/KazakhBERTmulti-onnx");

const disambiguator = new CandidateLanguageModelDisambiguator({
  scorer
});

const converter = new ArabicToCyrillicConverter({
  useLm: true,
  disambiguator
});

console.log(await converter.convertAsync("اكەم كەلدى."));

模型目录要求

最少需要:

  • model.onnx
  • tokenizer.json
  • tokenizer_config.json

可选但推荐同时提供:

  • special_tokens_map.json
  • config.json
  • vocab.txtvocab.json / merges.txt

模型来源

你可以:

  • 下载作者预导出的模型压缩包并解压到本地目录
  • 自己把 Hugging Face 的 masked LM 导出成 ONNX
  • 使用你自己训练的兼容模型

只要最终目录结构符合上面的要求,这个包就可以直接加载。

自定义候选词

import { createOnnxDisambiguator } from "@sarmay/kaz-converter-lm";

const disambiguator = await createOnnxDisambiguator({
  modelDirectory: "./models/KazakhBERTmulti-onnx",
  homographs: {
    "الما": ["Алма", "Әлме"]
  }
});

自定义打分器

如果你不想用 ONNX,也可以自己提供一个句子打分器:

import { ArabicToCyrillicConverter } from "@sarmay/kaz-converter";
import { CandidateLanguageModelDisambiguator } from "@sarmay/kaz-converter-lm";

const disambiguator = new CandidateLanguageModelDisambiguator({
  scorer: async (sentence) => {
    if (sentence.includes("Алма")) return 0.1;
    if (sentence.includes("Әлме")) return 0.9;
    return 1;
  }
});

const converter = new ArabicToCyrillicConverter({
  useLm: true,
  disambiguator
});

更完整的模型准备和训练说明见仓库根目录 README 与 docs/training-kazakh-lm.md