Downloads · 30 days
9
6% of all-time downloads
WariHima/hourai2-pl-2m-32dim-gguf
hourai2-pl-2m-32dim-gguf is a machine learning model from WariHima. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
for aquestalk like japanese phoneme (like) text style Style-TTS2のPL BERTのように動作することを期待した、 アクエストーク記法によるテキストスタイルエンコーダ用モデルです。 ttsモデル用のため。単体では動作しません。
Downloads · 30 days
9
6% of all-time downloads
All-time downloads
159
Public
Repo size
4.6 MB
Likes
0
Public
Click a slice to open those files.
.gguf4.6 MB · 100%
From the Hugging Face model README
for aquestalk like japanese phoneme (like) text style
Style-TTS2のPL BERTのように動作することを期待した、
アクエストーク記法によるテキストスタイルエンコーダ用モデルです。
ttsモデル用のため。単体では動作しません。
$ pip install llama-cpp-python
$ pip install tokenizers
import llama_cpp
from tokenizers import Tokenizer
# 1. モデルロード (embedding=True)
llm = llama_cpp.Llama(
model_path="./hourai2-pl-2m-32dim.gguf",
embedding=True,
verbose=False
)
# 2. tokenizers ライブラリで ID 化
tokenizer = Tokenizer.from_file("./tokenizer.json")
text = "コンニチハ"
token_ids = tokenizer.encode(text).ids # [10, 41, 22, 17, 26]
print("Token IDs:", token_ids)
# --- ここから embed() メソッド内部処理の再現 ---
n_embd = llm.n_embd()
n_batch = llm.n_batch
pooling_type = llm.pooling_type()
# トークン数のチェック
n_tokens = len(token_ids)
if n_tokens > n_batch:
raise ValueError(f"Requested tokens ({n_tokens}) exceed batch size of {n_batch}")
# バッチのリセットとシーケンス追加
llm._batch.reset()
# embed() 内の仕様に従い logits_all = True でシーケンス登録
# (配列, seq_id, logits_all)
llm._batch.add_sequence(token_ids, 0, True)
# KVキャッシュのクリアとモデルデコード(C++層の計算実行)
llm._ctx.kv_cache_clear()
llm._ctx.decode(llm._batch)
# 埋め込みベクトルの抽出 (pooling_type の判定処理)
if pooling_type == llama_cpp.LLAMA_POOLING_TYPE_NONE:
# トークンごとの埋め込み (shape: [n_tokens, n_embd])
ptr = llama_cpp.llama_get_embeddings(llm._ctx.ctx)
embedding = [
ptr[j * n_embd : (j + 1) * n_embd]
for j in range(n_tokens)
]
else:
# 文全体のプーリング埋め込み (shape: [n_embd])
ptr = llama_cpp.llama_get_embeddings_seq(llm._ctx.ctx, 0)
embedding = ptr[:n_embd]
# クリーンアップ
llm._batch.reset()
llm._ctx.kv_cache_clear()
llm.reset()
# --- 取得結果 ---
print("\nEmbedding 取得成功!")
if pooling_type == llama_cpp.LLAMA_POOLING_TYPE_NONE:
print(f"トークン数: {len(embedding)}, 次元数: {len(embedding[0])}")
else:
print(f"ベクトル次元数: {len(embedding)}")
print("先頭 5 要素:", embedding[:5])