[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2023-09-23 12:51:53 +00:00
parent 732e9ce1e3
commit 0ebd76b91c
5 changed files with 22 additions and 18 deletions

View File

@@ -208,7 +208,13 @@ class TextAudioSpeakerCollate:
torch.LongTensor([x[1].size(1) for x in batch]), dim=0, descending=True torch.LongTensor([x[1].size(1) for x in batch]), dim=0, descending=True
) )
max_text_len = max([batch[ids_sorted_decreasing[i]][7].size(1) for i in range(len(ids_sorted_decreasing))] + [len(x[0]) for x in batch]) max_text_len = max(
[
batch[ids_sorted_decreasing[i]][7].size(1)
for i in range(len(ids_sorted_decreasing))
]
+ [len(x[0]) for x in batch]
)
max_spec_len = max([x[1].size(1) for x in batch]) max_spec_len = max([x[1].size(1) for x in batch])
max_wav_len = max([x[2].size(1) for x in batch]) max_wav_len = max([x[2].size(1) for x in batch])

View File

@@ -6,12 +6,9 @@ import sys
from transformers import AutoTokenizer from transformers import AutoTokenizer
from text import punctuation, symbols
from typing import TextIO
import pyopenjtalk import pyopenjtalk
from num2words import num2words BERT = "./bert/bert-large-japanese-v2"
BERT = './bert/bert-large-japanese-v2'
_CONVRULES = [ _CONVRULES = [
# Conversion of 2 letters # Conversion of 2 letters
"アァ/ a a", "アァ/ a a",
@@ -385,6 +382,7 @@ def replace_punctuation(text):
replaced_text = replaced_text.replace(x, rep_map[x]) replaced_text = replaced_text.replace(x, rep_map[x])
return replaced_text return replaced_text
def text_normalize(text): def text_normalize(text):
res = unicodedata.normalize("NFKC", text) res = unicodedata.normalize("NFKC", text)
res = japanese_convert_numbers_to_words(res) res = japanese_convert_numbers_to_words(res)
@@ -393,27 +391,29 @@ def text_normalize(text):
return res return res
tokenizer = AutoTokenizer.from_pretrained(BERT) tokenizer = AutoTokenizer.from_pretrained(BERT)
def g2p(norm_text): def g2p(norm_text):
tokenized = tokenizer.tokenize(norm_text) tokenized = tokenizer.tokenize(norm_text)
st = [x.replace("#", "") for x in tokenized] st = [x.replace("#", "") for x in tokenized]
word2ph = [] word2ph = []
phs = pyopenjtalk.g2p(norm_text).split(" ") # Directly use the entire norm_text sequence. phs = pyopenjtalk.g2p(norm_text).split(
" "
) # Directly use the entire norm_text sequence.
for sub in st: # the following code is only for calculating word2ph for sub in st: # the following code is only for calculating word2ph
wph = 0 wph = 0
for x in sub: for x in sub:
sys.stdout.flush() sys.stdout.flush()
if x not in ['?', '.', '!', '', ',']: # This will throw warnings. if x not in ["?", ".", "!", "", ","]: # This will throw warnings.
phonemes = pyopenjtalk.g2p(x) phonemes = pyopenjtalk.g2p(x)
else: else:
phonemes = 'pau' phonemes = "pau"
# for x in range(repeat): # for x in range(repeat):
wph += len(phonemes.split(' ')) wph += len(phonemes.split(" "))
# print(f'{x}-->:{phones}') # print(f'{x}-->:{phones}')
word2ph.append(wph) word2ph.append(wph)
phonemes = ['_'] + phs + ['_'] phonemes = ["_"] + phs + ["_"]
tones = [0 for i in phonemes] tones = [0 for i in phonemes]
word2ph = [1] + word2ph + [1] word2ph = [1] + word2ph + [1]
return phonemes, tones, word2ph return phonemes, tones, word2ph

View File

@@ -2,7 +2,7 @@ import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM from transformers import AutoTokenizer, AutoModelForMaskedLM
import sys import sys
BERT = './bert/bert-large-japanese-v2' BERT = "./bert/bert-large-japanese-v2"
tokenizer = AutoTokenizer.from_pretrained(BERT) tokenizer = AutoTokenizer.from_pretrained(BERT)
# bert-large model has 25 hidden layers.You can decide which layer to use by setting this variable to a specific value # bert-large model has 25 hidden layers.You can decide which layer to use by setting this variable to a specific value
@@ -19,15 +19,13 @@ def get_bert_feature(text, word2ph, device=None):
device = "mps" device = "mps"
if not device: if not device:
device = "cuda" device = "cuda"
model = AutoModelForMaskedLM.from_pretrained(BERT).to( model = AutoModelForMaskedLM.from_pretrained(BERT).to(device)
device
)
with torch.no_grad(): with torch.no_grad():
inputs = tokenizer(text, return_tensors="pt") inputs = tokenizer(text, return_tensors="pt")
for i in inputs: for i in inputs:
inputs[i] = inputs[i].to(device) inputs[i] = inputs[i].to(device)
res = model(**inputs, output_hidden_states=True) res = model(**inputs, output_hidden_states=True)
res = res['hidden_states'][BERT_LAYER] res = res["hidden_states"][BERT_LAYER]
assert inputs["input_ids"].shape[-1] == len(word2ph) assert inputs["input_ids"].shape[-1] == len(word2ph)
word2phone = word2ph word2phone = word2ph
phone_level_feature = [] phone_level_feature = []

View File

@@ -118,7 +118,7 @@ ja_symbols = [
"z", "z",
"zy", "zy",
] ]
for x in range(ord('a'), ord('z')+1): for x in range(ord("a"), ord("z") + 1):
ja_symbols.append(chr(x).upper()) ja_symbols.append(chr(x).upper())
num_ja_tones = 1 num_ja_tones = 1