はじめに
plamoの翻訳モデルに関する情報がでていたので、早々使って見た。
【注意】無償利用の範囲内か、商用利用の範疇かは、利用前に必ず確認して下さい。
学術利用関連で、ちょっとした機密情報を含むテキストのローカルLLMでの翻訳を求めていたので、丁度良かった。(※無償利用の範囲内)
今までローカル駆動するQuen等を使っていたのだが、生成しようとするハルシネーションの圧力が強く、不安定だったこともあり、良い機会であった。Chat-GPTにシステム構成を投げて、最適なモデルを聞くとplamo-3-translate-8bが良いとのことだった(※)。
※Chat-GPT無料版(6 instant)での結果。今回、提示されたサンプルソフトを改変した。
対象モデルのサイト
※標準のインストール手順が記載されているが、今回はuv利用するのと、GPUを利用するため参考するに留めた。
システム構成
GPU: Nvidia RTX-3090
CPU: IntelCore-i9-10900X
memory: 64GB
python: ver. 3.12
※既にuvがインストールされており、マルウェア対策済みとする。
uvのマルウェア対策については下記の記事を参照して下さい。
インストールとサンプルソフトでの動作確認
-
インストール手順
-
uvで仮想環境の構築、対象ディレクトリ:
plamo_transとするpowershelluv init -p 3.12 plamo_trans -
構築した仮想環境ディレクトリに入り、
huggingface_hubをインストールpowershellcd plamo_trans uv add huggingface_hub -
.venvの仮想環境を起動し
powershell.\.venv\Scripts\activate -
hfコマンドでplamo-3-translate-8bをダウンロード
(plamo_trans)hf download pfnet/plamo-3-translate-8b --local-dir model_8b -
.venv仮想環境から離脱
(plamo_trans)deactivate -
CUDA用のPyTorchをインストールし、pyproject.tomlファイルを編集
powershelluv pip install torch torchvision --torch-backend=auto --link-mode=copy※ハードリンク関連のアラートが出たため、
--link-mode=copyを入れているがアラート出ないなら無くても良い。 -
PyTorchがGPUを認識するかテスト
powershell.\.venv\Scripts\activate(plamo_trans)python -c “import torch; print(torch.cuda.is_available())“ここで「True」が返ってくることを確認し仮想環境抜ける。
※エラー出る場合、CUDA周りの設定やPyTorchのバージョンなどを確認して再トライ。(plamo_trans)deactivate -
下記を参考に
pyproject.tomlを編集した
uv pip install torch --torch-backend=autoで互換性の高いPyTorchをインストールする流れ -
最終的に
pyproject.tomlに下記を追加した
※インストールされたtorchやcudaのバージョン番号は、上記記事内部を参考にチェックし、適切な値に変えてください。pyproject.toml... dependencies = [ ... "torch>=2.15.0", "torchvision>=0.29.2", ... ] [tool.uv.sources] torch = [ { index = "torch-cu132" }, ] torchvision = [ { index = "torchvision-cu132" }, ] [[tool.uv.index]] name = "torch-cu132" url = "https://download.pytorch.org/whl/cu132" explicit = true [[tool.uv.index]] name = "torchvision-cu132" url = "https://download.pytorch.org/whl/cu132" ... -
念のため、
uv syncを実行し、エラーが出ないことを確認すること。
※ここでエラー出た場合、pyproject.tomlの設定ミスなどをチェック。 -
torch以外の必要ライブラリをインストール
powershelluv add transformers accelerate numba -
vs-codeで動作確認するためipykernelをインストール
powershelluv add ipykernel
-
-
GPT-6 instantが提示したサンプルプログラムとその改良
GPT-6 instantが提示した和英変換のサンプルプログラム
モデルを
C:\AI\plamo-translate\modelにダウンロードした場合を想定しており、ループはexitの入力で終了する仕組みとなっている。改行を含む文書(複数の文書)には未対応。sample by GPT-6 instantimport torch from transformers import AutoModelForCausalLM, AutoTokenizer MODEL_DIR = r"C:\AI\plamo-translate\model" print("Loading tokenizer...") tokenizer = AutoTokenizer.from_pretrained( MODEL_DIR, trust_remote_code=True, ) print("Loading model...") model = AutoModelForCausalLM.from_pretrained( MODEL_DIR, trust_remote_code=True, dtype=torch.bfloat16, device_map="auto", ) print("Model loaded.") print("Enter text to translate. Type 'exit' to quit.") while True: source_text = input("\nInput: ") if source_text.lower() == "exit": break inputs = tokenizer.apply_chat_template( [{"role": "user", "content": source_text}], source_lang="ja", target_lang="en", add_generation_prompt=True, return_dict=True, return_tensors="pt", ).to(model.device) with torch.inference_mode(): output = model.generate( **inputs, do_sample=False, max_new_tokens=1024, ) translated = tokenizer.decode( output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True, ) print("\nTranslation:") print(translated)サンプルプログラムを改訂した版
ループは
exitの入力で終了する仕組みとなっている。改行を含む文書(複数の文書)には未対応。
サンプルプログラムに英和変換と和英変換をトグルするコマンドcngを追加。
また入力プロンプト部分に現在入力可能な言語を表示。EJ_JE_test.py### EJ_JE_test.py # by H.Nishiyama (aujinen) with GPT-6 instant # 2026-11-06 ### model # plamo-3-translate-8b ### URL # https://huggingface.co/pfnet # https://huggingface.co/pfnet/plamo-3-translate-8b ### import torch from transformers import AutoModelForCausalLM, AutoTokenizer MODEL_DIR = r".\model_8b" maxTokens=1024 print("Loading tokenizer...") tokenizer = AutoTokenizer.from_pretrained( MODEL_DIR, trust_remote_code=True, ) print("Loading model...") model = AutoModelForCausalLM.from_pretrained( MODEL_DIR, trust_remote_code=True, dtype=torch.bfloat16, device_map="auto", ) print("Model loaded.") print("Enter text to translate. Type 'cng' to change languages, type 'exit' to quit.") sourceLang="en" targetLang="ja" while True: inputPrompt="\nInput[{}]: ".format(sourceLang) source_text = input(inputPrompt) if source_text.lower() == "exit": break if source_text.lower() == "cng": lang_buf = sourceLang sourceLang = targetLang targetLang = lang_buf else: inputs = tokenizer.apply_chat_template( [{"role": "user", "content": source_text}], source_lang=sourceLang, target_lang=targetLang, add_generation_prompt=True, return_dict=True, return_tensors="pt", ).to(model.device) with torch.inference_mode(): output = model.generate( **inputs, do_sample=False, max_new_tokens=maxTokens, ) translated = tokenizer.decode( output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True, ) print("\nTranslation:") print(translated) -
改良したサンプルプログラムの起動と動作画面
powershell.\.venv\Scripts\activate python .\EJ_JE_test.py※起動までに数十秒かかる。

講義資料からの専門用語を含むテキストを用い、和英翻訳後、翻訳文を英和翻訳へ投入した例サンプルテキストの翻訳結果Input[en]: cng Input[ja]: 顎骨とその周囲の炎症の多くは歯性感染(odontogenic infection)が原因である。歯性感染の場合、原因となる歯ないし歯周組織の同定、および炎症の拡大方向の情報が画像内にある。これらを読み取るためには、解剖構造や組織についての基礎知識も必要不可欠である。 Translation: Much of the inflammation of the jawbone and its surrounding areas is caused by odontogenic infection. In cases of odontogenic infection, the imaging data provide information on the identification of the causative tooth or periodontal tissue, as well as the direction of inflammation's spread. Basic knowledge of anatomical structures and tissues is also indispensable for interpreting these findings. Input[ja]: cng Input[en]: Much of the inflammation of the jawbone and its surrounding areas is caused by odontogenic infection. In cases of odontogenic infection, the imaging data provide information on the identification of the causative tooth or periodontal tissue, as well as the direction of inflammation's spread. Basic knowledge of anatomical structures and tissues is also indispensable for interpreting these findings. Translation: 顎骨およびその周辺領域の炎症の多くは、歯原性感染によって引き起こされる。歯原性感染の場合、画像データからは原因歯や歯周組織の同定、および炎症の波及方向に関する情報が得られる。これらの所見を解釈するには、解剖学的構造や組織に関する基礎知識も不可欠である。 Input[en]: exit
まとめ・感想
取りあえずの動作確認だったが、比較的良い感じに利用できた。
動作確認とはいえ、早々学術関連の実務にて利用している(英和・和英の往復操作させたことで、少しの手直しで使えるレベルになっている。専門用語が特殊な範疇のようなので、出力結果には、どうしても手を入れる必要はある)
uvにてCUDA対応のPyTorchのインストールとpyproject.tomlファイルの編集回りで手間取ったが、無事に動作した。
Hugging Faceのダウンロードサイトには各種のサンプルが提示されているので、時間があれば取り入れていく予定。
最後に動作時のGPU関連の負荷状態を貼り付けておく。

