LM Studio で PLaMo 翻訳
Markdown をそのまま読み込めない(Frontmatter が悪さしているか、本文に が含まれているのが原因?)ようなので、実用を考えるとパースして日本語になっているところだけを渡すか、文脈を維持するのであれば Plain Text に変換してから渡すような工夫が必要になりそうだ。また、 が原因で動作しないのであれば PLaMo の解説をしている記事以外では問題にならないがエスケープ処理を組み込まないといけない。
1## PLaMo Translation 2 3On May 27th of this year, Preferred Networks Inc. (PFN) [released PLaMo Translation](https://tech.preferred.jp/ja/blog/plamo-translate/). 4For a detailed introduction to PLaMo Translation, please refer to the official blog, but to briefly summarize, this model is a translation system based on large-scale language models (LLMs), much like the well-known ChatGPT. 5 6The PLaMo Translation model is available on [HuggingFace](https://huggingface.co/pfnet/plamo-2-translate) and comes with a [demo page](https://translate.preferredai.jp/). 7Since the model is publicly available on HuggingFace, it means we can run it on our local PC as well. 8PFN has also announced a [PLaMo Translation CLI tool](https://tech.preferred.jp/ja/blog/plamo-translate-cli/) for command-line use. 9 10While there are multiple methods to run the model, here we'll demonstrate how to execute it using LM Studio. 11 12## LM Studio 13 14[LM Studio](https://lmstudio.ai/) is a graphical user interface (GUI) application that allows you to easily run LLM models in your local environment. 15To install it, simply download the installer from the [downloads page](https://lmstudio.ai/download), 16and execute it to complete the installation process. 17 18### Downloading the Model 19 20After launching LM Studio, proceed to download the model. 21You can access the download screen by clicking on the magnifying glass icon on the left side of the window that appears after launch. 22 23Img src="./images/lm-studio_launch.png" /> 24 25To download the PLaMo Translation model, enter a search term like "plamo translate" in the search field. This will display several matching models; select the one published by the user mmnga and click the "Download" button. In the screenshot above, the text "Use in New Chat" indicates that you have already downloaded this model. 26 27Img src="./images/lm-studio_donwload-model.png" /> 28 29### Model Configuration 30 31After completing the model download, click the folder icon on the left side of the window to open the screen displaying your downloaded models. 32You should find a model with the name `plamo-2-translate` in the list of available models; then click on the gear icon in the "Action" column of that row. 33 34Img src="./images/lm-studio_model-list.png" /> 35 36This will display configuration settings for editing the default parameters of the model. 37To use PLaMo Translation with LM Studio, you need to modify the settings under both the **Prompt** tab's "**Promp Template**" and "**Stop String**" options. 38While writing this article, I noticed that changing the "**Additional Stop String**" instead of "**Stop String**" might also work well. 39 40Img src="./images/lm-studio_model-template.png" /> 41 42#### Prompt Template 43 44Delete all the default template text ("Template (Jinia)"), and replace it with the following template: 45 46```txt 47dataset 48translation 49 50input lang=English 51> 52output lang=Japanese 53 54``` 55 56The current configuration is set up for "English to Japanese translation." 57For "Japanese to English translation," you should configure it as follows: 58 59```txt 60dataset 61translation 62 63input lang=Japanese 64> 65output lang=English 66 67``` 68 69#### Stop String 70 71Next, configure the "Stop String" as follows: 72 73```txt 74 75``` 76 77Img src="./images/lm-studio_termination.png" /> 78 79After entering the text in the textarea and pressing Enter, you'll see tag indicators displayed on the screen as shown below. 80 81### Let's Try It Out 82 83After completing the settings, click the speech bubble icon on the left side of the window to display the chat UI interface for using LLM models. 84 85Img src="./images/lm-studio_chat.png" /> 86 87Next, to load your model, click on "Select a Model" at the top of the window. 88This will display the list of downloaded models; select "Plamo 2 Translate." 89 90Img src="./images/lm-studio_load-model.png" /> 91 92You'll then be prompted with some settings, but here we'll leave everything as default and click "Load Model." 93 94Img src="./images/lm-studio_model-configuration.png" /> 95 96This will display the familiar UI similar to ChatGPT, so simply enter some English text and press Enter. 97PLaMo Translation will then provide you with the Japanese translation. 98In these screenshots, I have provided a [description](https://etc.usf.edu/lit2go/41/the-merchant-of-venice/) of Shakespeare's "The Merchant of Venice." 99 100Img src="./images/lm-studio_translate.png" /> 101 102Img src="./images/google-translate.png" /> 103 104Compared to Google Translate, I feel there are many parts that have been paraphrased rather than directly translated, 105but the translation doesn't lose the original context, so it may prove useful when you need to quickly compile and translate large amounts of English information. 106I'll try using it for machine translation of this blog, and if the results are satisfactory, I think I'll adopt it. 107 108### Important Note 109 110As a note, since the model hasn't been trained for conversational usage, providing translation instructions won't be effective. 111 112Img src="./images/lm-studio_plamo_response.png" /> 113 114While the settings allow you to choose whether to translate from English → Japanese or Japanese → English, 115the system will only function correctly when provided with language combinations matching those specific settings. 116 117### Eject 118 119Finally, be sure to either fully stop LM Studio or eject the model to prevent memory allocation when the model is unused. 120 121Img src="./images/lm-studio_eject.png" />とりあえずブログを英語圏向けに公開するには十分ではないだろうか。 LM Studio の画像にも載っているが、私の環境では 30~40 token/s 出るので待たされる感覚はない。
## おわりに
LM Studio で PLaMo 翻訳を使う方法を紹介した。結構な速度が出るので英語で書かれた文章の概要を理解するためにローカルでプログラム経由に使うには良さそうに感じた。 API として提供されている翻訳サービスではお金がかかってしまうので、その辺のコストをかけずにこの精度で英語から日本語、日本語から英語の翻訳を機械的に行えるのは嬉しい。
Zenn に PLaMo 翻訳を使って Markdown、epub の翻訳をするツールを公開している方がいたので自分も似たようなものを作成しようと思う。
この記事には Amazon アソシエイトのリンクが含まれています。Amazonのアソシエイトとして、SuzumiyaAoba は適格販売により収入を得ています。