0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【翻訳モデル】ローカルAI翻訳環境構築 LP2_1_1

0
Last updated at Posted at 2025-07-21
QQQ :bow_tone1:3Q!
📚 【翻訳モデル】200の言語を翻訳できるNLLBモデル体験 LM2_1 :arrow_heading_up:

PDF ファイル処理(pdfplumber)

Word ファイル処理(python-docx)
Excel ファイル処理(openpyxl + pandas)

Python 3.10.0

user ~
? python --version
Python 3.10.0

conda

? conda info --env
# conda environments:
#
base                   F:\Users\user\anaconda3
tts                    F:\Users\user\anaconda3\envs\tts

CUDA環境の準備

? nvidia-smi
Thu Jun 26 23:48:51 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 573.23                 Driver Version: 573.23         CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Quadro P4000                 WDDM  |   00000000:9E:00.0  On |                  N/A |
| 52%   55C    P0             28W /  105W |    1889MiB /   8192MiB |      4%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A           13156    C+G   ...Chrome\Application\chrome.exe      N/A      |
|    0   N/A  N/A           15672    C+G   C:\Windows\explorer.exe               N/A      |
|    0   N/A  N/A           19416    C+G   ...Chrome\Application\chrome.exe      N/A      |
|    0   N/A  N/A           19984    C+G   ...ice\root\Office16\WINWORD.EXE      N/A      |
|    0   N/A  N/A           20280    C+G   ...indows\System32\ShellHost.exe      N/A      |
|    0   N/A  N/A           22624    C+G   ...yb3d8bbwe\WindowsTerminal.exe      N/A      |
|    0   N/A  N/A           24804    C+G   ...App_cw5n1h2txyewy\LockApp.exe      N/A      |
|    0   N/A  N/A           30924    C+G   ....0.3179.73\msedgewebview2.exe      N/A      |
|    0   N/A  N/A           31284    C+G   ...les\Tencent\Weixin\Weixin.exe      N/A      |
|    0   N/A  N/A           34656    C+G   ...y\StartMenuExperienceHost.exe      N/A      |
|    0   N/A  N/A           34848    C+G   ...5n1h2txyewy\TextInputHost.exe      N/A      |
|    0   N/A  N/A           36656    C+G   ...acted\runtime\WeChatAppEx.exe      N/A      |
|    0   N/A  N/A           37184    C+G   ...xyewy\ShellExperienceHost.exe      N/A      |
|    0   N/A  N/A           37272    C+G   ..._cw5n1h2txyewy\SearchHost.exe      N/A      |
|    0   N/A  N/A           37436    C+G   C:\Windows\explorer.exe               N/A      |
|    0   N/A  N/A           38356    C+G   C:\Windows\explorer.exe               N/A      |
|    0   N/A  N/A           38864    C+G   ...m Files\RustDesk\RustDesk.exe      N/A      |
|    0   N/A  N/A           41132    C+G   C:\Windows\explorer.exe               N/A      |
|    0   N/A  N/A           42296    C+G   ...t\Edge\Application\msedge.exe      N/A      |
|    0   N/A  N/A           47356    C+G   ...al\Programs\cursor\Cursor.exe      N/A      |
+-----------------------------------------------------------------------------------------+

GPU:Quadro P4000,8GB RAM,ドライバーバージョンとCUDAは正常らしい(Driver 573.23,CUDA 12.8)

? pip show ctranslate2
Name: ctranslate2
Version: 4.6.0
Summary: Fast inference engine for Transformer models
Home-page: https://opennmt.net
Author: OpenNMT
Author-email:
License: MIT
Location: c:\users\user\appdata\roaming\python\python310\site-packages
Requires: numpy, pyyaml, setuptools
Required-by:

CUDAをリセットアップする。

user I:\DocTranslate\scripts via 🐍 v3.10.0
? pip uninstall ctranslate2
Found existing installation: ctranslate2 4.6.0
Uninstalling ctranslate2-4.6.0:
  Would remove:
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-fairseq-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-marian-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-openai-gpt2-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-opennmt-py-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-opennmt-tf-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-opus-mt-converter.exe
    c:\users\user\appdata\roaming\python\python310\scripts\ct2-transformers-converter.exe
    c:\users\user\appdata\roaming\python\python310\site-packages\ctranslate2-4.6.0.dist-info\*
    c:\users\user\appdata\roaming\python\python310\site-packages\ctranslate2\*
Proceed (Y/n)? y
  Successfully uninstalled ctranslate2-4.6.0

user I:\DocTranslate\scripts via 🐍 v3.10.0 took 16s
? pip install ctranslate2[cuda]
Defaulting to user installation because normal site-packages is not writeable
Collecting ctranslate2[cuda]
  Downloading ctranslate2-4.6.0-cp310-cp310-win_amd64.whl.metadata (10 kB)
WARNING: ctranslate2 4.6.0 does not provide the extra 'cuda'
Requirement already satisfied: setuptools in c:\program files\python310\lib\site-packages (from ctranslate2[cuda]) (57.4.0)
Requirement already satisfied: numpy in c:\program files\python310\lib\site-packages (from ctranslate2[cuda]) (1.22.0)
Requirement already satisfied: pyyaml<7,>=5.3 in c:\program files\python310\lib\site-packages (from ctranslate2[cuda]) (6.0.2)
Downloading ctranslate2-4.6.0-cp310-cp310-win_amd64.whl (19.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.5/19.5 MB 11.3 MB/s eta 0:00:00
Installing collected packages: ctranslate2
Successfully installed ctranslate2-4.6.0

環境確認

user I:\DocTranslate\scripts via 🐍 v3.10.0
? python .\test.py
CTranslate2 CUDA 初期化成功!
? conda create -n doctrans python=3.10
Retrieving notices: done
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\user\.conda\envs\doctrans

  added / updated specs:
    - python=3.10

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    expat-2.7.1                |       h8ddb27b_0         259 KB
    python-3.10.18             |       h981015d_0        16.2 MB
    tk-8.6.14                  |       h5e9d12e_1         3.5 MB
    ------------------------------------------------------------
                                           Total:        20.0 MB
done
#
# To activate this environment, use
#
#     $ conda activate doctrans
#
# To deactivate an active environment, use
#
#     $ conda deactivate

# Python環境をアクティブする。
user ~ took 58s
? conda activate doctrans
user ~ took 6s
? conda install openpyxl pandas -y
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done

# Condaがpdfplumber,python-docx 二つライブラリを見つかりませんでした。だから、pipで手動的にセットアップすること。
user ~ took 6s
? pip install pdfplumber python-docx
Defaulting to user installation because normal site-packages is not writeable
Collecting pdfplumber
  Downloading pdfplumber-0.11.7-py3-none-any.whl.metadata (42 kB)
Collecting python-docx
  Downloading python_docx-1.2.0-py3-none-any.whl.metadata (2.0 kB)
Collecting pdfminer.six==20250506 (from pdfplumber)
  Downloading pdfminer_six-20250506-py3-none-any.whl.metadata (4.2 kB)
Requirement already satisfied: Pillow>=9.1 in c:\program files\python310\lib\site-packages (from pdfplumber) (11.0.0)
Collecting pypdfium2>=4.18.0 (from pdfplumber)
  Downloading pypdfium2-4.30.1-py3-none-win_amd64.whl.metadata (48 kB)
Requirement already satisfied: charset-normalizer>=2.0.0 in c:\program files\python310\lib\site-packages (from pdfminer.six==20250506->pdfplumber) (3.4.2)
Collecting cryptography>=36.0.0 (from pdfminer.six==20250506->pdfplumber)
  Downloading cryptography-45.0.4-cp37-abi3-win_amd64.whl.metadata (5.7 kB)
Requirement already satisfied: lxml>=3.1.0 in c:\program files\python310\lib\site-packages (from python-docx) (5.3.2)
Requirement already satisfied: typing_extensions>=4.9.0 in c:\program files\python310\lib\site-packages (from python-docx) (4.13.2)
Requirement already satisfied: cffi>=1.14 in c:\program files\python310\lib\site-packages (from cryptography>=36.0.0->pdfminer.six==20250506->pdfplumber) (1.17.1)
Requirement already satisfied: pycparser in c:\program files\python310\lib\site-packages (from cffi>=1.14->cryptography>=36.0.0->pdfminer.six==20250506->pdfplumber) (2.22)
Downloading pdfplumber-0.11.7-py3-none-any.whl (60 kB)
Downloading pdfminer_six-20250506-py3-none-any.whl (5.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.6/5.6 MB 11.4 MB/s eta 0:00:00
Downloading python_docx-1.2.0-py3-none-any.whl (252 kB)
Downloading cryptography-45.0.4-cp37-abi3-win_amd64.whl (3.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 11.2 MB/s eta 0:00:00
Downloading pypdfium2-4.30.1-py3-none-win_amd64.whl (3.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 10.8 MB/s eta 0:00:00
Installing collected packages: python-docx, pypdfium2, cryptography, pdfminer.six, pdfplumber
   ━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/5 [pypdfium2]  WARNING: The script pypdfium2.exe is installed in 'C:\Users\user\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━ 4/5 [pdfplumber]  WARNING: The script pdfplumber.exe is installed in 'C:\Users\user\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed cryptography-45.0.4 pdfminer.six-20250506 pdfplumber-0.11.7 pypdfium2-4.30.1 python-docx-1.2.0

🔍 セットアップ説明:
ライブラリ名 説明
pdfplumber PDFファイル内容取得(pdfminer.sixにより)
python-docx .docx Wordファイルの読み取り、書込み
openpyxl .xlsx Excelファイルの読み取り、書込み
pandas データ処理、Excel内容を補助する。

最後チェック!

**user ~
? python -c "import pdfplumber; import docx; print('OK')"
OK

user ~ took 6s
? conda list | findstr openpyxl
openpyxl                  3.1.5           py312h827c3e9_0

user ~ took 6s
? conda list | findstr pandas
pandas                    2.2.2           py312h0158946_0**

次は、翻訳をしよう!

📚 【翻訳モデル】200の言語を翻訳できるNLLBモデル体験 LM2_1 :arrow_heading_up:
QQQ :bow_tone1:3Q!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?