머신러닝AI2023. 8. 31. 23:59

GPU를 쓰는 이 녀석의 특성에 따라 이 글은 앞의 https://infoengineer.tistory.com/96 를 계승한다. GPU에 맞게 설정을 끝냈다고 가정한다.

 

meta에서 텍스트와 음성 모두를 읽어서 번역하고 텍스트화하는 성능 좋은 모델을 발표했다. meta의 sequence 처리 모델인 faitseq2를 먼저 설치한 후 SeamlessM4T를 통해 아래 5개의 기능을 우리가 아는 거의 모든 언어간이 가능하다. 한글도 포함되어 있다! 그리고 무려 speech to speech 번역도 가능하다. 여기서는 우선 가장 단순 T2TT(텍스트 번역)을 해보자.

 

  • Speech-to-speech translation (S2ST)
  • Speech-to-text translation (S2TT)
  • Text-to-speech translation (T2ST)
  • Text-to-text translation (T2TT)
  • Automatic speech recognition (ASR)

설치 실행은 매우 단순하다. Anaconda를 사용해 보자.

 

$ conda create -n fairseq2 python=3.10
$ conda activate fairseq2
$ pip install fairseq2
$ git clone https://github.com/facebookresearch/seamless_communication
$ cd seamless_communication/
$ pip install .
$ sudo apt install libsndfile1
$ conda install -y -c conda-forge libsndfile

 

$ m4t_predict "The wind blows always to the west, and the girl is waiting always on the beach" t2tt kor --src_lang eng

2023-08-31 23:49:20,161 INFO -- m4t_scripts.predict.predict: Running inference on the GPU in torch.float16.
Using the cached checkpoint of the model 'seamlessM4T_large'. Set `force=True` to download again.
Using the cached tokenizer of the model 'seamlessM4T_large'. Set `force=True` to download again.
Using the cached checkpoint of the model 'vocoder_36langs'. Set `force=True` to download again.
2023-08-31 23:49:26,134 INFO -- m4t_scripts.predict.predict: Translated text in kor: 바람은 항상 서쪽으로 불고, 소녀는 항상 해변에서 기다리고 있습니다

 

$ m4t_predict "We introduce SONAR, a new multilingual and multimodal fixed-size sentence embedding space, with a full suite of speech and text encoders and decoders. It substantially outperforms existing sentence embeddings such as LASER3 and LabSE on the xsim and xsim++ multilingual similarity search tasks." t2tt kor --src_lang eng

2023-09-01 00:02:20,217 INFO -- m4t_scripts.predict.predict: Running inference on the GPU in torch.float16.
Using the cached checkpoint of the model 'seamlessM4T_large'. Set `force=True` to download again.
Using the cached tokenizer of the model 'seamlessM4T_large'. Set `force=True` to download again.
Using the cached checkpoint of the model 'vocoder_36langs'. Set `force=True` to download again.
2023-09-01 00:02:26,722 INFO -- m4t_scripts.predict.predict: Translated text in kor: 우리는 SONAR를 소개합니다. 새로운 다국어 및 멀티모달 고정 크기의 문장  ⁇ 입 공간으로, 음성 및 텍스트 인코더 및 디코더의 전체 스위트를 갖추고 있습니다. 그것은 xsim 및 xsim++ 다국어 유사성 검색 작업에서 LASER3 및 LabSE와 같은 기존 문장  ⁇ 입을 크게 능가합니다.

 

속도가 NVidia 4080 GPU에서 약 7초가 소요되는데, 모델로딩 시간을 빼면 그럭저럭 괜찮은 시간에 나오는 것 같다.

모델은 2가지가 있는데 디폴트로 SeamlessM4T-Large가 선택된다.

SeamlessM4T-Large 2.3B 🤗 Model card - checkpoint metrics
SeamlessM4T-Medium 1.2B 🤗 Model card - checkpoint metrics

GPU를 사용하면 그리 느리지 않은 좋은 라이브러리를 확보한 셈이다. 라이센스는 무료로 자유롭게 쓰면 되는(하지만 재배포는 제약이 있다) Creative Commons Attribution-NonCommercial 4.0 International Public License 를 취한다.

 

 

 

반응형
Posted by 작동미학