大規模的預訓練的語言模型已被證明有助於改善文本到語音(TTS)模型的自然性,使它們能夠產生更自然的韻律模式。但是,這些模型通常是單詞級或sup-phoneme級別的,並通過音素共同訓練,這使得僅需要音素的下游TTS任務效率低下。在這項工作中,我們提出了一個音素級Bert(PL-BERT),其藉口任務是預測相應的素描以及常規的蒙版音素預測。主觀評估表明,與最先進(SOTA)的STYLETTS基線(OOD)文本相比,我們的音素級Bert編碼器顯著改善了合成語音自然的平均意見分數(MOS)。
論文:https://arxiv.org/abs/2301.08810
音頻樣本:https://pl-bert.github.io/
git clone https://github.com/yl4579/PL-BERT.git
cd PL-BERTconda create --name BERT python=3.8
conda activate BERT
python -m ipykernel install --user --name BERT --display-name " BERT "pip install pandas singleton-decorator datasets " transformers<4.33.3 " accelerate nltk phonemizer sacremoses pebble有關更多詳細信息,請參閱筆記本preprocess.ipynb。預處理僅適用於英文Wikipedia數據集。如果我有額外的時間來對其他語言進行培訓,我將為日語建立一個新的分支。您也可以參考#6,以使用日語等其他語言進行預處理。
請在筆記本火車上運行每個單元。 IPYNB。如果您想使用其他配置文件,則需要在單元2中更改單元格2中的行config_path = "Configs/config.yml" 。培訓代碼在Jupyter筆記本中主要是因為最初的植被是在Jupyter Notebook中進行的,但是如果您願意,您可以輕鬆使其成為Python腳本。
這是如何將其用於Styletts Finetuning的示例。您可以通過用預訓練的PL-Bert替換文本編碼器來將其用於其他TTS模型。
from transformers import AlbertConfig , AlbertModel
log_dir = "YOUR PL-BERT CHECKPOINT PATH"
config_path = os . path . join ( log_dir , "config.yml" )
plbert_config = yaml . safe_load ( open ( config_path ))
albert_base_configuration = AlbertConfig ( ** plbert_config [ 'model_params' ])
bert = AlbertModel ( albert_base_configuration )
files = os . listdir ( log_dir )
ckpts = []
for f in os . listdir ( log_dir ):
if f . startswith ( "step_" ): ckpts . append ( f )
iters = [ int ( f . split ( '_' )[ - 1 ]. split ( '.' )[ 0 ]) for f in ckpts if os . path . isfile ( os . path . join ( log_dir , f ))]
iters = sorted ( iters )[ - 1 ]
checkpoint = torch . load ( log_dir + "/step_" + str ( iters ) + ".t7" , map_location = 'cpu' )
state_dict = checkpoint [ 'net' ]
from collections import OrderedDict
new_state_dict = OrderedDict ()
for k , v in state_dict . items ():
name = k [ 7 :] # remove `module.`
if name . startswith ( 'encoder.' ):
name = name [ 8 :] # remove `encoder.`
new_state_dict [ name ] = v
bert . load_state_dict ( new_state_dict )
nets = Munch ( bert = bert ,
# linear projection to match the hidden size (BERT 768, StyleTTS 512)
bert_encoder = nn . Linear ( plbert_config [ 'model_params' ][ 'hidden_size' ], args . hidden_dim ),
predictor = predictor ,
decoder = decoder ,
pitch_extractor = pitch_extractor ,
text_encoder = text_encoder ,
style_encoder = style_encoder ,
text_aligner = text_aligner ,
discriminator = discriminator ) # for stability
for g in optimizer . optimizers [ 'bert' ]. param_groups :
g [ 'betas' ] = ( 0.9 , 0.99 )
g [ 'lr' ] = 1e-5
g [ 'initial_lr' ] = 1e-5
g [ 'min_lr' ] = 0
g [ 'weight_decay' ] = 0.01 bert_dur = model . bert ( texts , attention_mask = ( ~ text_mask ). int ()). last_hidden_state
d_en = model . bert_encoder ( bert_dur ). transpose ( - 1 , - 2 )
d , _ = model . predictor ( d_en , s ,
input_lengths ,
s2s_attn_mono ,
m )第257行:
_ , p = model . predictor ( d_en , s ,
input_lengths ,
s2s_attn_mono ,
m )和第415行:
bert_dur = model . bert ( texts , attention_mask = ( ~ text_mask ). int ()). last_hidden_state
d_en = model . bert_encoder ( bert_dur ). transpose ( - 1 , - 2 )
d , p = model . predictor ( d_en , s ,
input_lengths ,
s2s_attn_mono ,
m ) optimizer . step ( 'bert_encoder' )
optimizer . step ( 'bert' )可以在以下位置下載Wikipedia上1M步驟的預訓練的PL-BERT:PL-BERT LINK。
可以在此處下載LJSpeech數據集上的演示以及預先修飾的Styletts回購和預訓練的模型:Styletts鏈接。該ZIP文件包含上面的代碼修改,上面列出的預訓練的PL-BERT模型,w/ pl-bert的預先訓練的styletts,w/ o pl-bert的預訓練的styletts和pretains the pl-bert和preaded hifigan在styletts repo上的ljspeech上。