見出し画像

Google Colab で FuguMT による翻訳を試す

「Google Colab」で「FuguMT」による翻訳を試したのでまとめました。

1. FuguMT

「FuguMT」は、Marian-NMT を使用した日本語-英語の翻訳モデルです。

2. 英語から日本語への翻訳

英語から日本語への翻訳の実行手順は次のとおりです。

(1) Colabの新規ノートブックを開き、メニュー「編集→ノートブックの設定」の「ハードウェアアクセラレータ」で「GPU」を選択。

(2) パッケージのインストール。

# パッケージのインストール
!pip install transformers sentencepiece

(3) パイプラインの準備。

from transformers import pipeline

# パイプラインの準備
ej_translator = pipeline("translation", model="staka/fugumt-en-ja")

(4) 動作確認。

# 翻訳するテキスト
text = """Hitori Gotoh, also known as Bocchi-chan, 
is one of the main characters in the manga and anime series, 
Bocchi the Rock!. She is in the first year of Shuka High School and 
is in charge of the guitar and lyrics of the band, Kessoku Band."""

# 翻訳
ej_translator(text)
[{'translation_text': '漫画・アニメシリーズ「Bocchi the Rock!」の主人公のひとりで、修歌高校1年生の時、バンド「けっそくバンド」のギターと歌詞を担当。'}]

2. 日本語から英語への翻訳

英語から日本語への翻訳の実行手順は次のとおりです。

(1) Colabの新規ノートブックを開き、メニュー「編集→ノートブックの設定」の「ハードウェアアクセラレータ」で「GPU」を選択。

(2) パッケージのインストール。

# パッケージのインストール
!pip install transformers sentencepiece

(3) パイプラインの準備。

from transformers import pipeline

# パイプラインの準備
je_translator = pipeline("translation", model="staka/fugumt-ja-en")

(4) 動作確認。

# 翻訳するテキスト
text = """漫画・アニメシリーズ「ぼっち・ざ・ろっく!」の主人公のひとりで、
秀華高校1年生の時、バンド「結束バンド」のギターと歌詞を担当。"""

# 翻訳
je_translator(text)
[{'translation_text': 'He is one of the protagonists of the manga and anime series "Bocchi Za Rokku!", and in charge of the guitar and lyrics of the band "Kyuzoku Band" when he was a first year student of Hideka High School.'}]

参考



この記事が気に入ったらサポートをしてみませんか?