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?

More than 1 year has passed since last update.

MetaのSeamlessM4Tを試してみる on Databricks

Posted at

Metaが面白そうなものを出したので、Databricksで試してみました。

SeamlessM4Tとは

Gigazineさんの記事でも紹介されています。詳しくはこちらを見ていただくのがいいと思います。

記事から抜粋:

Metaが音声を入力するだけで「文字起こし」「別言語への翻訳」「別言語への吹き替え」を実行できるAI「SeamlessM4T」を2023年8月22日(火)に公開しました。

(中略)

文字起こしAIや翻訳AIは複数存在していますが、既存のAIの多くは「文字起こしだけ」「翻訳だけ」といったように単一の機能しか備えていません。Metaが新たに開発したSeamlessM4TはマルチモーダルなAIで、単一のAIだけで「文字起こし」「別言語への翻訳」「別言語への吹き替え」といった複数の操作を実行できます。

というわけで、音声・テキストのマルチモーダルモデルです。

Metaの公式ブログ上では、下図のようにWhisper V2よりも英語でのBLUEのスコアが優れていると伝えいます。

パフォーマンス

なお、モデルは公開されていますが、現状研究用途を想定したものであり、ライセンスはCC-BY-NC 4.0で商用利用不可です。

Databricksで動かしてみる

SeamlessM4Tはローカルでも動作可能です。

インストール方法の詳細は公式github上にあります。

また、hugging face上にモデルが公開されており、Pythonでの動かし方も記載してあります。
この内容に従ってDatabricks上で動かしてみます。

環境はAWS Databricks、DBRは13.2ML、クラスタタイプg5.2xlargeのクラスタを利用しました。

インストール

ノートブックを作成して、gitリポジトリを適当なところにクローン。

%sh mkdir /tmp/seamessm4t && cd /tmp/seamessm4t && git clone https://github.com/facebookresearch/seamless_communication.git

クローンしたリポジトリを指定してインストール。

%pip install /tmp/seamessm4t/seamless_communication

libsndfileのインストール。
※ DBR13.2MLには最初からインストールされているようで、この工程は不要だったかも。

%sh apt-get --yes install libsndfile1

Translatorの作成

モデルはlargeとmediumがあります。今回はlargeを試しました。

import torch
from seamless_communication.models.inference import Translator

# Initialize a Translator object with a multitask model, vocoder on the GPU.
translator = Translator("seamlessM4T_large", vocoder_name_or_card="vocoder_36langs", device=torch.device("cuda:0"))

モデルがダウンロードされるのを待って、準備完了。
(torchのキャッシュとして保管されるようで、キャッシュの場所は/root/.cache/torch/hub内でした)

Text-to-Text translation(T2TT)を試す

まずはベタに日英翻訳。

# T2TT
input_text = "大規模言語モデルとは?"
target_lang = "eng"
src_lang = "jpn"
translated_text, _, _ = translator.predict(input_text, "t2tt", target_lang, src_lang=src_lang)

translated_text
Output
CString('What is a large-scale language model?')

単純な文章ではありますが、ちゃんと翻訳されてますね。

Text-to-Speech Translation(T2ST)を試す

# T2ST
input_text = "トンネルを抜けると、そこは雪国だった。"
target_lang = "eng"
src_lang = "jpn"

translated_text, wav, sr = translator.predict(input_text, "t2st", target_lang, src_lang=src_lang)

translated_text
Output
CString('When we got through the tunnel, it was snowing.')

また、wavに音声データが返却されるようになっているので、一度保存します。

import torchaudio

# Save the translated audio generation.
torchaudio.save(
    "/tmp/seamlessm4t.wav",
    wav[0].cpu(),
    sample_rate=sr,
)

再生。

import IPython

IPython.display.Audio("/tmp/seamlessm4t.wav")

翻訳された音声データが出来ています。

Speech-to-Text Translation(S2TT)を試す

SeamlessM4Tが出力した内容をそのままInputとして使ってみます。

# S2TT

target_lang = "eng"

translated_text, _, _ = translator.predict("/tmp/seamlessm4t.wav", "s2tt", target_lang)

translated_text
Output
CString('When we got through the tunnel, it was snowing.')

ちゃんと認識されました。

まとめ

いくつか試してみている感じだと、出力テキスト通りに音声データが必ずしも出来るわけではないみたいですね。
また、公式デモだと日本語翻訳がExperiment扱いになっていて、欧米系の言語に比べると精度落ちそうな感じですね。人物固有名詞を英訳するとHeとかになったし、ユースケースはちょっと考える必要があるかも。

あと、まだ詳しく確認できていませんが、Fine Tuningの方法とかもリポジトリ内のdocにありデータや環境を揃えられればいろいろ面白いことができそうです。

個人的にマルチモーダルモデルには興味があり、継続的に勉強したり動かしたりしてみたいと思います。

あと、これを使って、LLMに対するプロンプト指示を日本語で音声入力→を日英翻訳→LLMで推論→結果を英日翻訳&音声出力とかしてみたいなあ。
プロンプトは英語指定の方が精度上がる傾向にあるため、そのあたりを楽に行えるような仕組を準備するのもいいなと思います。

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?