🚀 超棒v4日語->英語神經機器翻譯模型 by MingShiba
本模型是一個強大的日語到英語的神經機器翻譯(NMT)模型,由MingShiba開發。它能高效準確地完成日語到英語的翻譯任務,適用於多種翻譯場景。
相關鏈接
🚀 快速開始
📦 安裝指南
使用Python下載模型
- 安裝Python,可從 Python官網 下載。
- 打開命令提示符(
cmd
)。
- 檢查Python版本:
python --version
- 安裝
huggingface_hub
庫:
python -m pip install huggingface_hub
- 進入Python交互環境:
python
- 在Python中執行以下代碼下載模型:
import huggingface_hub
huggingface_hub.download_snapshot('entai2965/sugoi-v4-ja-en-ctranslate2',local_dir='sugoi-v4-ja-en-ctranslate2')
運行模型(批量語法)
- 參考 CTranslate2與Fairseq的使用指南。
- 打開命令提示符(
cmd
)。
- 安裝
ctranslate2
和sentencepiece
庫:
python -m pip install ctranslate2 sentencepiece
- 進入Python交互環境:
python
💻 使用示例
基礎用法
import ctranslate2
import sentencepiece
model_path='sugoi-v4-ja-en-ctranslate2'
sentencepiece_model_path=model_path+'/spm'
device='cpu'
string1='は靜かに前へと歩み出た。'
string2='悲しいGPTと話したことがありますか?'
raw_list=[string1,string2]
translator = ctranslate2.Translator(model_path, device=device)
tokenizer_for_source_language = sentencepiece.SentencePieceProcessor(sentencepiece_model_path+'/spm.ja.nopretok.model')
tokenizer_for_target_language = sentencepiece.SentencePieceProcessor(sentencepiece_model_path+'/spm.en.nopretok.model')
tokenized_batch=[]
for text in raw_list:
tokenized_batch.append(tokenizer_for_source_language.encode(text,out_type=str))
translated_batch=translator.translate_batch(source=tokenized_batch,beam_size=5)
assert(len(raw_list)==len(translated_batch))
for count,tokens in enumerate(translated_batch):
translated_batch[count]=tokenizer_for_target_language.decode(tokens.hypotheses[0]).replace('<unk>','')
for text in translated_batch:
print(text)
高級用法(函數式編程版本)
import ctranslate2
import sentencepiece
model_path='sugoi-v4-ja-en-ctranslate2'
sentencepiece_model_path=model_path+'/spm'
device='cpu'
string1='は靜かに前へと歩み出た。'
string2='悲しいGPTと話したことがありますか?'
raw_list=[string1,string2]
translator = ctranslate2.Translator(model_path, device=device)
tokenizer_for_source_language = sentencepiece.SentencePieceProcessor(sentencepiece_model_path+'/spm.ja.nopretok.model')
tokenizer_for_target_language = sentencepiece.SentencePieceProcessor(sentencepiece_model_path+'/spm.en.nopretok.model')
translated_batch=[tokenizer_for_target_language.decode(tokens.hypotheses[0]).replace('<unk>','') for tokens in translator.translate_batch(source=[tokenizer_for_source_language.encode(text,out_type=str) for text in raw_list],beam_size=5)]
assert(len(raw_list)==len(translated_batch))
for text in translated_batch:
print(text)
📄 許可證
本模型採用其他許可證(ntt-license
),具體許可信息請參考 LICENSE 文件。
模型信息
屬性 |
詳情 |
模型類型 |
神經機器翻譯(NMT)模型 |
訓練數據 |
未提及 |
支持語言 |
日語、英語 |
庫名稱 |
fairseq |
標籤 |
nmt |