Downloads · 30 days
144
100% of all-time downloads
m4sak1/MA
MA is a token classification model from m4sak1. Use it when you need labels on individual words, such as names. It is set up for transformers.js. The card lists the license as cc-by-sa-4.0.
このモデルは、日本語の文章に対して適切な位置に自動で「読点(、)」を挿入するための軽量な自然言語処理モデルです。 ブラウザ上で高速に動作する Transformers.js (ONNX Runtime Web) 向けに最適化されています。
Downloads · 30 days
144
100% of all-time downloads
All-time downloads
144
Public
Parameters
5.8M
509 MB on disk
Likes
0
Public
Click a slice to open those files.
.onnx23.3 MB · 50%
From the Hugging Face model README
このモデルは、日本語の文章に対して適切な位置に自動で「読点(、)」を挿入するための軽量な自然言語処理モデルです。
ブラウザ上で高速に動作する Transformers.js (ONNX Runtime Web) 向けに最適化されています。
WebサイトやJavaScript/TypeScriptのアプリケーションに直接組み込むことができます。
【重要】 WebAssembly環境特有の精度低下を補正するため、標準の pipeline は使用せず、生の出力値(Logits)から確率を算出して閾値調整を行う実装を強く推奨します。
import { AutoTokenizer, AutoModelForTokenClassification } from '@xenova/transformers';
// モデルのロード
const tokenizer = await AutoTokenizer.from_pretrained('m4sak1/MA');
const model = await AutoModelForTokenClassification.from_pretrained('m4sak1/MA', {
quantized: false
});
// 推論
const text = "明日は雨が降るそうなので傘を持っていこうと思います";
const inputs = await tokenizer(text);
const outputs = await model(inputs);
const logits = outputs.logits.data;
const seqLen = outputs.logits.dims[1];
let predictedStr = '';
const chars = Array.from(text);
const PROB_THRESHOLD = 0.37; // WASM用の調整閾値(数値を下げるとAIが敏感になります)
for (let i = 0; i < seqLen; i++) {
const l0 = logits[i * 2];
const l1 = logits[i * 2 + 1];
// Softmaxで確率を計算
const max = Math.max(l0, l1);
const e0 = Math.exp(l0 - max);
const e1 = Math.exp(l1 - max);
const prob1 = e1 / (e0 + e1);
if (i > 0 && i <= chars.length) {
predictedStr += chars[i - 1];
if (prob1 > PROB_THRESHOLD) predictedStr += '、';
}
}
console.log(predictedStr);
// 予想出力: "明日は、雨が降るそうなので、傘を持っていこうと、思います"
Wikipediaの日本語ダンプデータを使用し、自然な読点の位置を学習しています。 v2アップデートにおいて、約240万文(Phase 2)の大規模コーパスへとデータセットを拡張しファインチューニングを行いました。
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
詳しくはこちら → https://ai.m4sak1.me/MA