Apply Code Formatter Change
This commit is contained in:
committed by
github-actions[bot]
parent
d82ba3457a
commit
eef212fd00
@@ -4,19 +4,26 @@ import sys
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained("./bert/bert-base-japanese-v3")
|
||||
|
||||
|
||||
def get_bert_feature(text, word2ph, device=None):
|
||||
if sys.platform == "darwin" and torch.backends.mps.is_available() and device == "cpu":
|
||||
if (
|
||||
sys.platform == "darwin"
|
||||
and torch.backends.mps.is_available()
|
||||
and device == "cpu"
|
||||
):
|
||||
device = "mps"
|
||||
if not device:
|
||||
device = "cuda"
|
||||
model = AutoModelForMaskedLM.from_pretrained("./bert/bert-base-japanese-v3").to(device)
|
||||
model = AutoModelForMaskedLM.from_pretrained("./bert/bert-base-japanese-v3").to(
|
||||
device
|
||||
)
|
||||
with torch.no_grad():
|
||||
inputs = tokenizer(text, return_tensors='pt')
|
||||
inputs = tokenizer(text, return_tensors="pt")
|
||||
for i in inputs:
|
||||
inputs[i] = inputs[i].to(device)
|
||||
res = model(**inputs, output_hidden_states=True)
|
||||
res = torch.cat(res['hidden_states'][-3:-2], -1)[0].cpu()
|
||||
assert inputs['input_ids'].shape[-1] == len(word2ph)
|
||||
res = torch.cat(res["hidden_states"][-3:-2], -1)[0].cpu()
|
||||
assert inputs["input_ids"].shape[-1] == len(word2ph)
|
||||
word2phone = word2ph
|
||||
phone_level_feature = []
|
||||
for i in range(len(word2phone)):
|
||||
|
||||
Reference in New Issue
Block a user