TLME
commited on
Commit
·
8c110e0
1
Parent(s):
9944720
init
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- README.md +1 -1
- __pycache__/attentions.cpython-38.pyc +0 -0
- __pycache__/commons.cpython-38.pyc +0 -0
- __pycache__/models.cpython-38.pyc +0 -0
- __pycache__/modules.cpython-38.pyc +0 -0
- __pycache__/transforms.cpython-38.pyc +0 -0
- __pycache__/utils.cpython-38.pyc +0 -0
- attentions.py +464 -0
- bert/bert-base-japanese-v3/README.md +53 -0
- bert/bert-base-japanese-v3/config.json +19 -0
- bert/bert-base-japanese-v3/flax_model.msgpack +3 -0
- bert/bert-base-japanese-v3/pytorch_model.bin +3 -0
- bert/bert-base-japanese-v3/tf_model.h5 +3 -0
- bert/bert-base-japanese-v3/tokenizer_config.json +10 -0
- bert/bert-base-japanese-v3/vocab.txt +0 -0
- bert/chinese-roberta-wwm-ext-large/.gitattributes +9 -0
- bert/chinese-roberta-wwm-ext-large/.gitignore +1 -0
- bert/chinese-roberta-wwm-ext-large/README.md +57 -0
- bert/chinese-roberta-wwm-ext-large/added_tokens.json +1 -0
- bert/chinese-roberta-wwm-ext-large/bert_config.json +19 -0
- bert/chinese-roberta-wwm-ext-large/config.json +28 -0
- bert/chinese-roberta-wwm-ext-large/flax_model.msgpack +3 -0
- bert/chinese-roberta-wwm-ext-large/special_tokens_map.json +1 -0
- bert/chinese-roberta-wwm-ext-large/tf_model.h5 +3 -0
- bert/chinese-roberta-wwm-ext-large/tokenizer.json +0 -0
- bert/chinese-roberta-wwm-ext-large/tokenizer_config.json +1 -0
- bert/chinese-roberta-wwm-ext-large/vocab.txt +0 -0
- commons.py +160 -0
- configs/config.json +403 -0
- logs/UGH/G_350000.pth +3 -0
- models.py +986 -0
- modules.py +597 -0
- monotonic_align/__init__.py +16 -0
- monotonic_align/core.py +46 -0
- requirements.txt +23 -0
- text/__init__.py +28 -0
- text/__pycache__/__init__.cpython-310.pyc +0 -0
- text/__pycache__/__init__.cpython-38.pyc +0 -0
- text/__pycache__/chinese.cpython-310.pyc +0 -0
- text/__pycache__/chinese.cpython-38.pyc +0 -0
- text/__pycache__/chinese_bert.cpython-310.pyc +0 -0
- text/__pycache__/chinese_bert.cpython-38.pyc +0 -0
- text/__pycache__/cleaner.cpython-310.pyc +0 -0
- text/__pycache__/cleaner.cpython-38.pyc +0 -0
- text/__pycache__/english_bert_mock.cpython-310.pyc +0 -0
- text/__pycache__/english_bert_mock.cpython-38.pyc +0 -0
- text/__pycache__/japanese.cpython-310.pyc +0 -0
- text/__pycache__/japanese.cpython-38.pyc +0 -0
- text/__pycache__/japanese_bert.cpython-310.pyc +0 -0
- text/__pycache__/japanese_bert.cpython-38.pyc +0 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Bert VITS Umamusume Genshin HonkaiSR
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Bert VITS Umamusume Genshin HonkaiSR
|
3 |
+
emoji: 🎙️
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
__pycache__/attentions.cpython-38.pyc
ADDED
Binary file (11.1 kB). View file
|
|
__pycache__/commons.cpython-38.pyc
ADDED
Binary file (5.78 kB). View file
|
|
__pycache__/models.cpython-38.pyc
ADDED
Binary file (20.9 kB). View file
|
|
__pycache__/modules.cpython-38.pyc
ADDED
Binary file (13 kB). View file
|
|
__pycache__/transforms.cpython-38.pyc
ADDED
Binary file (3.93 kB). View file
|
|
__pycache__/utils.cpython-38.pyc
ADDED
Binary file (11.1 kB). View file
|
|
attentions.py
ADDED
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
class LayerNorm(nn.Module):
|
13 |
+
def __init__(self, channels, eps=1e-5):
|
14 |
+
super().__init__()
|
15 |
+
self.channels = channels
|
16 |
+
self.eps = eps
|
17 |
+
|
18 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
19 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
20 |
+
|
21 |
+
def forward(self, x):
|
22 |
+
x = x.transpose(1, -1)
|
23 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
24 |
+
return x.transpose(1, -1)
|
25 |
+
|
26 |
+
|
27 |
+
@torch.jit.script
|
28 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
29 |
+
n_channels_int = n_channels[0]
|
30 |
+
in_act = input_a + input_b
|
31 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
32 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
33 |
+
acts = t_act * s_act
|
34 |
+
return acts
|
35 |
+
|
36 |
+
|
37 |
+
class Encoder(nn.Module):
|
38 |
+
def __init__(
|
39 |
+
self,
|
40 |
+
hidden_channels,
|
41 |
+
filter_channels,
|
42 |
+
n_heads,
|
43 |
+
n_layers,
|
44 |
+
kernel_size=1,
|
45 |
+
p_dropout=0.0,
|
46 |
+
window_size=4,
|
47 |
+
isflow=True,
|
48 |
+
**kwargs
|
49 |
+
):
|
50 |
+
super().__init__()
|
51 |
+
self.hidden_channels = hidden_channels
|
52 |
+
self.filter_channels = filter_channels
|
53 |
+
self.n_heads = n_heads
|
54 |
+
self.n_layers = n_layers
|
55 |
+
self.kernel_size = kernel_size
|
56 |
+
self.p_dropout = p_dropout
|
57 |
+
self.window_size = window_size
|
58 |
+
# if isflow:
|
59 |
+
# cond_layer = torch.nn.Conv1d(256, 2*hidden_channels*n_layers, 1)
|
60 |
+
# self.cond_pre = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, 1)
|
61 |
+
# self.cond_layer = weight_norm(cond_layer, name='weight')
|
62 |
+
# self.gin_channels = 256
|
63 |
+
self.cond_layer_idx = self.n_layers
|
64 |
+
if "gin_channels" in kwargs:
|
65 |
+
self.gin_channels = kwargs["gin_channels"]
|
66 |
+
if self.gin_channels != 0:
|
67 |
+
self.spk_emb_linear = nn.Linear(self.gin_channels, self.hidden_channels)
|
68 |
+
# vits2 says 3rd block, so idx is 2 by default
|
69 |
+
self.cond_layer_idx = (
|
70 |
+
kwargs["cond_layer_idx"] if "cond_layer_idx" in kwargs else 2
|
71 |
+
)
|
72 |
+
logging.debug(self.gin_channels, self.cond_layer_idx)
|
73 |
+
assert (
|
74 |
+
self.cond_layer_idx < self.n_layers
|
75 |
+
), "cond_layer_idx should be less than n_layers"
|
76 |
+
self.drop = nn.Dropout(p_dropout)
|
77 |
+
self.attn_layers = nn.ModuleList()
|
78 |
+
self.norm_layers_1 = nn.ModuleList()
|
79 |
+
self.ffn_layers = nn.ModuleList()
|
80 |
+
self.norm_layers_2 = nn.ModuleList()
|
81 |
+
for i in range(self.n_layers):
|
82 |
+
self.attn_layers.append(
|
83 |
+
MultiHeadAttention(
|
84 |
+
hidden_channels,
|
85 |
+
hidden_channels,
|
86 |
+
n_heads,
|
87 |
+
p_dropout=p_dropout,
|
88 |
+
window_size=window_size,
|
89 |
+
)
|
90 |
+
)
|
91 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
92 |
+
self.ffn_layers.append(
|
93 |
+
FFN(
|
94 |
+
hidden_channels,
|
95 |
+
hidden_channels,
|
96 |
+
filter_channels,
|
97 |
+
kernel_size,
|
98 |
+
p_dropout=p_dropout,
|
99 |
+
)
|
100 |
+
)
|
101 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
102 |
+
|
103 |
+
def forward(self, x, x_mask, g=None):
|
104 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
105 |
+
x = x * x_mask
|
106 |
+
for i in range(self.n_layers):
|
107 |
+
if i == self.cond_layer_idx and g is not None:
|
108 |
+
g = self.spk_emb_linear(g.transpose(1, 2))
|
109 |
+
g = g.transpose(1, 2)
|
110 |
+
x = x + g
|
111 |
+
x = x * x_mask
|
112 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
113 |
+
y = self.drop(y)
|
114 |
+
x = self.norm_layers_1[i](x + y)
|
115 |
+
|
116 |
+
y = self.ffn_layers[i](x, x_mask)
|
117 |
+
y = self.drop(y)
|
118 |
+
x = self.norm_layers_2[i](x + y)
|
119 |
+
x = x * x_mask
|
120 |
+
return x
|
121 |
+
|
122 |
+
|
123 |
+
class Decoder(nn.Module):
|
124 |
+
def __init__(
|
125 |
+
self,
|
126 |
+
hidden_channels,
|
127 |
+
filter_channels,
|
128 |
+
n_heads,
|
129 |
+
n_layers,
|
130 |
+
kernel_size=1,
|
131 |
+
p_dropout=0.0,
|
132 |
+
proximal_bias=False,
|
133 |
+
proximal_init=True,
|
134 |
+
**kwargs
|
135 |
+
):
|
136 |
+
super().__init__()
|
137 |
+
self.hidden_channels = hidden_channels
|
138 |
+
self.filter_channels = filter_channels
|
139 |
+
self.n_heads = n_heads
|
140 |
+
self.n_layers = n_layers
|
141 |
+
self.kernel_size = kernel_size
|
142 |
+
self.p_dropout = p_dropout
|
143 |
+
self.proximal_bias = proximal_bias
|
144 |
+
self.proximal_init = proximal_init
|
145 |
+
|
146 |
+
self.drop = nn.Dropout(p_dropout)
|
147 |
+
self.self_attn_layers = nn.ModuleList()
|
148 |
+
self.norm_layers_0 = nn.ModuleList()
|
149 |
+
self.encdec_attn_layers = nn.ModuleList()
|
150 |
+
self.norm_layers_1 = nn.ModuleList()
|
151 |
+
self.ffn_layers = nn.ModuleList()
|
152 |
+
self.norm_layers_2 = nn.ModuleList()
|
153 |
+
for i in range(self.n_layers):
|
154 |
+
self.self_attn_layers.append(
|
155 |
+
MultiHeadAttention(
|
156 |
+
hidden_channels,
|
157 |
+
hidden_channels,
|
158 |
+
n_heads,
|
159 |
+
p_dropout=p_dropout,
|
160 |
+
proximal_bias=proximal_bias,
|
161 |
+
proximal_init=proximal_init,
|
162 |
+
)
|
163 |
+
)
|
164 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
165 |
+
self.encdec_attn_layers.append(
|
166 |
+
MultiHeadAttention(
|
167 |
+
hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout
|
168 |
+
)
|
169 |
+
)
|
170 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
171 |
+
self.ffn_layers.append(
|
172 |
+
FFN(
|
173 |
+
hidden_channels,
|
174 |
+
hidden_channels,
|
175 |
+
filter_channels,
|
176 |
+
kernel_size,
|
177 |
+
p_dropout=p_dropout,
|
178 |
+
causal=True,
|
179 |
+
)
|
180 |
+
)
|
181 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
182 |
+
|
183 |
+
def forward(self, x, x_mask, h, h_mask):
|
184 |
+
"""
|
185 |
+
x: decoder input
|
186 |
+
h: encoder output
|
187 |
+
"""
|
188 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(
|
189 |
+
device=x.device, dtype=x.dtype
|
190 |
+
)
|
191 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
192 |
+
x = x * x_mask
|
193 |
+
for i in range(self.n_layers):
|
194 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
195 |
+
y = self.drop(y)
|
196 |
+
x = self.norm_layers_0[i](x + y)
|
197 |
+
|
198 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
199 |
+
y = self.drop(y)
|
200 |
+
x = self.norm_layers_1[i](x + y)
|
201 |
+
|
202 |
+
y = self.ffn_layers[i](x, x_mask)
|
203 |
+
y = self.drop(y)
|
204 |
+
x = self.norm_layers_2[i](x + y)
|
205 |
+
x = x * x_mask
|
206 |
+
return x
|
207 |
+
|
208 |
+
|
209 |
+
class MultiHeadAttention(nn.Module):
|
210 |
+
def __init__(
|
211 |
+
self,
|
212 |
+
channels,
|
213 |
+
out_channels,
|
214 |
+
n_heads,
|
215 |
+
p_dropout=0.0,
|
216 |
+
window_size=None,
|
217 |
+
heads_share=True,
|
218 |
+
block_length=None,
|
219 |
+
proximal_bias=False,
|
220 |
+
proximal_init=False,
|
221 |
+
):
|
222 |
+
super().__init__()
|
223 |
+
assert channels % n_heads == 0
|
224 |
+
|
225 |
+
self.channels = channels
|
226 |
+
self.out_channels = out_channels
|
227 |
+
self.n_heads = n_heads
|
228 |
+
self.p_dropout = p_dropout
|
229 |
+
self.window_size = window_size
|
230 |
+
self.heads_share = heads_share
|
231 |
+
self.block_length = block_length
|
232 |
+
self.proximal_bias = proximal_bias
|
233 |
+
self.proximal_init = proximal_init
|
234 |
+
self.attn = None
|
235 |
+
|
236 |
+
self.k_channels = channels // n_heads
|
237 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
238 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
239 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
240 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
241 |
+
self.drop = nn.Dropout(p_dropout)
|
242 |
+
|
243 |
+
if window_size is not None:
|
244 |
+
n_heads_rel = 1 if heads_share else n_heads
|
245 |
+
rel_stddev = self.k_channels**-0.5
|
246 |
+
self.emb_rel_k = nn.Parameter(
|
247 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
248 |
+
* rel_stddev
|
249 |
+
)
|
250 |
+
self.emb_rel_v = nn.Parameter(
|
251 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
252 |
+
* rel_stddev
|
253 |
+
)
|
254 |
+
|
255 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
256 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
257 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
258 |
+
if proximal_init:
|
259 |
+
with torch.no_grad():
|
260 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
261 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
262 |
+
|
263 |
+
def forward(self, x, c, attn_mask=None):
|
264 |
+
q = self.conv_q(x)
|
265 |
+
k = self.conv_k(c)
|
266 |
+
v = self.conv_v(c)
|
267 |
+
|
268 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
269 |
+
|
270 |
+
x = self.conv_o(x)
|
271 |
+
return x
|
272 |
+
|
273 |
+
def attention(self, query, key, value, mask=None):
|
274 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
275 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
276 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
277 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
278 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
279 |
+
|
280 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
281 |
+
if self.window_size is not None:
|
282 |
+
assert (
|
283 |
+
t_s == t_t
|
284 |
+
), "Relative attention is only available for self-attention."
|
285 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
286 |
+
rel_logits = self._matmul_with_relative_keys(
|
287 |
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
288 |
+
)
|
289 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
290 |
+
scores = scores + scores_local
|
291 |
+
if self.proximal_bias:
|
292 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
293 |
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
294 |
+
device=scores.device, dtype=scores.dtype
|
295 |
+
)
|
296 |
+
if mask is not None:
|
297 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
298 |
+
if self.block_length is not None:
|
299 |
+
assert (
|
300 |
+
t_s == t_t
|
301 |
+
), "Local attention is only available for self-attention."
|
302 |
+
block_mask = (
|
303 |
+
torch.ones_like(scores)
|
304 |
+
.triu(-self.block_length)
|
305 |
+
.tril(self.block_length)
|
306 |
+
)
|
307 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
308 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
309 |
+
p_attn = self.drop(p_attn)
|
310 |
+
output = torch.matmul(p_attn, value)
|
311 |
+
if self.window_size is not None:
|
312 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
313 |
+
value_relative_embeddings = self._get_relative_embeddings(
|
314 |
+
self.emb_rel_v, t_s
|
315 |
+
)
|
316 |
+
output = output + self._matmul_with_relative_values(
|
317 |
+
relative_weights, value_relative_embeddings
|
318 |
+
)
|
319 |
+
output = (
|
320 |
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
321 |
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
322 |
+
return output, p_attn
|
323 |
+
|
324 |
+
def _matmul_with_relative_values(self, x, y):
|
325 |
+
"""
|
326 |
+
x: [b, h, l, m]
|
327 |
+
y: [h or 1, m, d]
|
328 |
+
ret: [b, h, l, d]
|
329 |
+
"""
|
330 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
331 |
+
return ret
|
332 |
+
|
333 |
+
def _matmul_with_relative_keys(self, x, y):
|
334 |
+
"""
|
335 |
+
x: [b, h, l, d]
|
336 |
+
y: [h or 1, m, d]
|
337 |
+
ret: [b, h, l, m]
|
338 |
+
"""
|
339 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
340 |
+
return ret
|
341 |
+
|
342 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
343 |
+
2 * self.window_size + 1
|
344 |
+
# Pad first before slice to avoid using cond ops.
|
345 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
346 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
347 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
348 |
+
if pad_length > 0:
|
349 |
+
padded_relative_embeddings = F.pad(
|
350 |
+
relative_embeddings,
|
351 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
352 |
+
)
|
353 |
+
else:
|
354 |
+
padded_relative_embeddings = relative_embeddings
|
355 |
+
used_relative_embeddings = padded_relative_embeddings[
|
356 |
+
:, slice_start_position:slice_end_position
|
357 |
+
]
|
358 |
+
return used_relative_embeddings
|
359 |
+
|
360 |
+
def _relative_position_to_absolute_position(self, x):
|
361 |
+
"""
|
362 |
+
x: [b, h, l, 2*l-1]
|
363 |
+
ret: [b, h, l, l]
|
364 |
+
"""
|
365 |
+
batch, heads, length, _ = x.size()
|
366 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
367 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
368 |
+
|
369 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
370 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
371 |
+
x_flat = F.pad(
|
372 |
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
373 |
+
)
|
374 |
+
|
375 |
+
# Reshape and slice out the padded elements.
|
376 |
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
377 |
+
:, :, :length, length - 1 :
|
378 |
+
]
|
379 |
+
return x_final
|
380 |
+
|
381 |
+
def _absolute_position_to_relative_position(self, x):
|
382 |
+
"""
|
383 |
+
x: [b, h, l, l]
|
384 |
+
ret: [b, h, l, 2*l-1]
|
385 |
+
"""
|
386 |
+
batch, heads, length, _ = x.size()
|
387 |
+
# pad along column
|
388 |
+
x = F.pad(
|
389 |
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
390 |
+
)
|
391 |
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
392 |
+
# add 0's in the beginning that will skew the elements after reshape
|
393 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
394 |
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
395 |
+
return x_final
|
396 |
+
|
397 |
+
def _attention_bias_proximal(self, length):
|
398 |
+
"""Bias for self-attention to encourage attention to close positions.
|
399 |
+
Args:
|
400 |
+
length: an integer scalar.
|
401 |
+
Returns:
|
402 |
+
a Tensor with shape [1, 1, length, length]
|
403 |
+
"""
|
404 |
+
r = torch.arange(length, dtype=torch.float32)
|
405 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
406 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
407 |
+
|
408 |
+
|
409 |
+
class FFN(nn.Module):
|
410 |
+
def __init__(
|
411 |
+
self,
|
412 |
+
in_channels,
|
413 |
+
out_channels,
|
414 |
+
filter_channels,
|
415 |
+
kernel_size,
|
416 |
+
p_dropout=0.0,
|
417 |
+
activation=None,
|
418 |
+
causal=False,
|
419 |
+
):
|
420 |
+
super().__init__()
|
421 |
+
self.in_channels = in_channels
|
422 |
+
self.out_channels = out_channels
|
423 |
+
self.filter_channels = filter_channels
|
424 |
+
self.kernel_size = kernel_size
|
425 |
+
self.p_dropout = p_dropout
|
426 |
+
self.activation = activation
|
427 |
+
self.causal = causal
|
428 |
+
|
429 |
+
if causal:
|
430 |
+
self.padding = self._causal_padding
|
431 |
+
else:
|
432 |
+
self.padding = self._same_padding
|
433 |
+
|
434 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
435 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
436 |
+
self.drop = nn.Dropout(p_dropout)
|
437 |
+
|
438 |
+
def forward(self, x, x_mask):
|
439 |
+
x = self.conv_1(self.padding(x * x_mask))
|
440 |
+
if self.activation == "gelu":
|
441 |
+
x = x * torch.sigmoid(1.702 * x)
|
442 |
+
else:
|
443 |
+
x = torch.relu(x)
|
444 |
+
x = self.drop(x)
|
445 |
+
x = self.conv_2(self.padding(x * x_mask))
|
446 |
+
return x * x_mask
|
447 |
+
|
448 |
+
def _causal_padding(self, x):
|
449 |
+
if self.kernel_size == 1:
|
450 |
+
return x
|
451 |
+
pad_l = self.kernel_size - 1
|
452 |
+
pad_r = 0
|
453 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
454 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
455 |
+
return x
|
456 |
+
|
457 |
+
def _same_padding(self, x):
|
458 |
+
if self.kernel_size == 1:
|
459 |
+
return x
|
460 |
+
pad_l = (self.kernel_size - 1) // 2
|
461 |
+
pad_r = self.kernel_size // 2
|
462 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
463 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
464 |
+
return x
|
bert/bert-base-japanese-v3/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- cc100
|
5 |
+
- wikipedia
|
6 |
+
language:
|
7 |
+
- ja
|
8 |
+
widget:
|
9 |
+
- text: 東北大学で[MASK]の研究をしています。
|
10 |
+
---
|
11 |
+
|
12 |
+
# BERT base Japanese (unidic-lite with whole word masking, CC-100 and jawiki-20230102)
|
13 |
+
|
14 |
+
This is a [BERT](https://github.com/google-research/bert) model pretrained on texts in the Japanese language.
|
15 |
+
|
16 |
+
This version of the model processes input texts with word-level tokenization based on the Unidic 2.1.2 dictionary (available in [unidic-lite](https://pypi.org/project/unidic-lite/) package), followed by the WordPiece subword tokenization.
|
17 |
+
Additionally, the model is trained with the whole word masking enabled for the masked language modeling (MLM) objective.
|
18 |
+
|
19 |
+
The codes for the pretraining are available at [cl-tohoku/bert-japanese](https://github.com/cl-tohoku/bert-japanese/).
|
20 |
+
|
21 |
+
## Model architecture
|
22 |
+
|
23 |
+
The model architecture is the same as the original BERT base model; 12 layers, 768 dimensions of hidden states, and 12 attention heads.
|
24 |
+
|
25 |
+
## Training Data
|
26 |
+
|
27 |
+
The model is trained on the Japanese portion of [CC-100 dataset](https://data.statmt.org/cc-100/) and the Japanese version of Wikipedia.
|
28 |
+
For Wikipedia, we generated a text corpus from the [Wikipedia Cirrussearch dump file](https://dumps.wikimedia.org/other/cirrussearch/) as of January 2, 2023.
|
29 |
+
The corpus files generated from CC-100 and Wikipedia are 74.3GB and 4.9GB in size and consist of approximately 392M and 34M sentences, respectively.
|
30 |
+
|
31 |
+
For the purpose of splitting texts into sentences, we used [fugashi](https://github.com/polm/fugashi) with [mecab-ipadic-NEologd](https://github.com/neologd/mecab-ipadic-neologd) dictionary (v0.0.7).
|
32 |
+
|
33 |
+
## Tokenization
|
34 |
+
|
35 |
+
The texts are first tokenized by MeCab with the Unidic 2.1.2 dictionary and then split into subwords by the WordPiece algorithm.
|
36 |
+
The vocabulary size is 32768.
|
37 |
+
|
38 |
+
We used [fugashi](https://github.com/polm/fugashi) and [unidic-lite](https://github.com/polm/unidic-lite) packages for the tokenization.
|
39 |
+
|
40 |
+
## Training
|
41 |
+
|
42 |
+
We trained the model first on the CC-100 corpus for 1M steps and then on the Wikipedia corpus for another 1M steps.
|
43 |
+
For training of the MLM (masked language modeling) objective, we introduced whole word masking in which all of the subword tokens corresponding to a single word (tokenized by MeCab) are masked at once.
|
44 |
+
|
45 |
+
For training of each model, we used a v3-8 instance of Cloud TPUs provided by [TPU Research Cloud](https://sites.research.google/trc/about/).
|
46 |
+
|
47 |
+
## Licenses
|
48 |
+
|
49 |
+
The pretrained models are distributed under the Apache License 2.0.
|
50 |
+
|
51 |
+
## Acknowledgments
|
52 |
+
|
53 |
+
This model is trained with Cloud TPUs provided by [TPU Research Cloud](https://sites.research.google/trc/about/) program.
|
bert/bert-base-japanese-v3/config.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertForPreTraining"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"hidden_act": "gelu",
|
7 |
+
"hidden_dropout_prob": 0.1,
|
8 |
+
"hidden_size": 768,
|
9 |
+
"initializer_range": 0.02,
|
10 |
+
"intermediate_size": 3072,
|
11 |
+
"layer_norm_eps": 1e-12,
|
12 |
+
"max_position_embeddings": 512,
|
13 |
+
"model_type": "bert",
|
14 |
+
"num_attention_heads": 12,
|
15 |
+
"num_hidden_layers": 12,
|
16 |
+
"pad_token_id": 0,
|
17 |
+
"type_vocab_size": 2,
|
18 |
+
"vocab_size": 32768
|
19 |
+
}
|
bert/bert-base-japanese-v3/flax_model.msgpack
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7dce0b8b350432362a184b9f8bb90ffb0f2ff0c394ab43b915e318926f4e7569
|
3 |
+
size 447341816
|
bert/bert-base-japanese-v3/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e172862e0674054d65e0ba40d67df2a4687982f589db44aa27091c386e5450a4
|
3 |
+
size 447406217
|
bert/bert-base-japanese-v3/tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:71920d0dc0174d0a0ce32b934fe65f15320b2d53aa7e671718b33065748cb712
|
3 |
+
size 549871840
|
bert/bert-base-japanese-v3/tokenizer_config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"tokenizer_class": "BertJapaneseTokenizer",
|
3 |
+
"model_max_length": 512,
|
4 |
+
"do_lower_case": false,
|
5 |
+
"word_tokenizer_type": "mecab",
|
6 |
+
"subword_tokenizer_type": "wordpiece",
|
7 |
+
"mecab_kwargs": {
|
8 |
+
"mecab_dic": "unidic_lite"
|
9 |
+
}
|
10 |
+
}
|
bert/bert-base-japanese-v3/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
bert/chinese-roberta-wwm-ext-large/.gitattributes
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
bert/chinese-roberta-wwm-ext-large/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.bin
|
bert/chinese-roberta-wwm-ext-large/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- zh
|
4 |
+
tags:
|
5 |
+
- bert
|
6 |
+
license: "apache-2.0"
|
7 |
+
---
|
8 |
+
|
9 |
+
# Please use 'Bert' related functions to load this model!
|
10 |
+
|
11 |
+
## Chinese BERT with Whole Word Masking
|
12 |
+
For further accelerating Chinese natural language processing, we provide **Chinese pre-trained BERT with Whole Word Masking**.
|
13 |
+
|
14 |
+
**[Pre-Training with Whole Word Masking for Chinese BERT](https://arxiv.org/abs/1906.08101)**
|
15 |
+
Yiming Cui, Wanxiang Che, Ting Liu, Bing Qin, Ziqing Yang, Shijin Wang, Guoping Hu
|
16 |
+
|
17 |
+
This repository is developed based on:https://github.com/google-research/bert
|
18 |
+
|
19 |
+
You may also interested in,
|
20 |
+
- Chinese BERT series: https://github.com/ymcui/Chinese-BERT-wwm
|
21 |
+
- Chinese MacBERT: https://github.com/ymcui/MacBERT
|
22 |
+
- Chinese ELECTRA: https://github.com/ymcui/Chinese-ELECTRA
|
23 |
+
- Chinese XLNet: https://github.com/ymcui/Chinese-XLNet
|
24 |
+
- Knowledge Distillation Toolkit - TextBrewer: https://github.com/airaria/TextBrewer
|
25 |
+
|
26 |
+
More resources by HFL: https://github.com/ymcui/HFL-Anthology
|
27 |
+
|
28 |
+
## Citation
|
29 |
+
If you find the technical report or resource is useful, please cite the following technical report in your paper.
|
30 |
+
- Primary: https://arxiv.org/abs/2004.13922
|
31 |
+
```
|
32 |
+
@inproceedings{cui-etal-2020-revisiting,
|
33 |
+
title = "Revisiting Pre-Trained Models for {C}hinese Natural Language Processing",
|
34 |
+
author = "Cui, Yiming and
|
35 |
+
Che, Wanxiang and
|
36 |
+
Liu, Ting and
|
37 |
+
Qin, Bing and
|
38 |
+
Wang, Shijin and
|
39 |
+
Hu, Guoping",
|
40 |
+
booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: Findings",
|
41 |
+
month = nov,
|
42 |
+
year = "2020",
|
43 |
+
address = "Online",
|
44 |
+
publisher = "Association for Computational Linguistics",
|
45 |
+
url = "https://www.aclweb.org/anthology/2020.findings-emnlp.58",
|
46 |
+
pages = "657--668",
|
47 |
+
}
|
48 |
+
```
|
49 |
+
- Secondary: https://arxiv.org/abs/1906.08101
|
50 |
+
```
|
51 |
+
@article{chinese-bert-wwm,
|
52 |
+
title={Pre-Training with Whole Word Masking for Chinese BERT},
|
53 |
+
author={Cui, Yiming and Che, Wanxiang and Liu, Ting and Qin, Bing and Yang, Ziqing and Wang, Shijin and Hu, Guoping},
|
54 |
+
journal={arXiv preprint arXiv:1906.08101},
|
55 |
+
year={2019}
|
56 |
+
}
|
57 |
+
```
|
bert/chinese-roberta-wwm-ext-large/added_tokens.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
bert/chinese-roberta-wwm-ext-large/bert_config.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"attention_probs_dropout_prob": 0.1,
|
3 |
+
"directionality": "bidi",
|
4 |
+
"hidden_act": "gelu",
|
5 |
+
"hidden_dropout_prob": 0.1,
|
6 |
+
"hidden_size": 1024,
|
7 |
+
"initializer_range": 0.02,
|
8 |
+
"intermediate_size": 4096,
|
9 |
+
"max_position_embeddings": 512,
|
10 |
+
"num_attention_heads": 16,
|
11 |
+
"num_hidden_layers": 24,
|
12 |
+
"pooler_fc_size": 768,
|
13 |
+
"pooler_num_attention_heads": 12,
|
14 |
+
"pooler_num_fc_layers": 3,
|
15 |
+
"pooler_size_per_head": 128,
|
16 |
+
"pooler_type": "first_token_transform",
|
17 |
+
"type_vocab_size": 2,
|
18 |
+
"vocab_size": 21128
|
19 |
+
}
|
bert/chinese-roberta-wwm-ext-large/config.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"bos_token_id": 0,
|
7 |
+
"directionality": "bidi",
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 1024,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 4096,
|
14 |
+
"layer_norm_eps": 1e-12,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"model_type": "bert",
|
17 |
+
"num_attention_heads": 16,
|
18 |
+
"num_hidden_layers": 24,
|
19 |
+
"output_past": true,
|
20 |
+
"pad_token_id": 0,
|
21 |
+
"pooler_fc_size": 768,
|
22 |
+
"pooler_num_attention_heads": 12,
|
23 |
+
"pooler_num_fc_layers": 3,
|
24 |
+
"pooler_size_per_head": 128,
|
25 |
+
"pooler_type": "first_token_transform",
|
26 |
+
"type_vocab_size": 2,
|
27 |
+
"vocab_size": 21128
|
28 |
+
}
|
bert/chinese-roberta-wwm-ext-large/flax_model.msgpack
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a46a510fe646213c728b80c9d0d5691d05235523d67f9ac3c3ce4e67deabf926
|
3 |
+
size 1302196529
|
bert/chinese-roberta-wwm-ext-large/special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
bert/chinese-roberta-wwm-ext-large/tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:72d18616fb285b720cb869c25aa9f4d7371033dfd5d8ba82aca448fdd28132bf
|
3 |
+
size 1302594480
|
bert/chinese-roberta-wwm-ext-large/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
bert/chinese-roberta-wwm-ext-large/tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"init_inputs": []}
|
bert/chinese-roberta-wwm-ext-large/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
commons.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch.nn import functional as F
|
4 |
+
|
5 |
+
|
6 |
+
def init_weights(m, mean=0.0, std=0.01):
|
7 |
+
classname = m.__class__.__name__
|
8 |
+
if classname.find("Conv") != -1:
|
9 |
+
m.weight.data.normal_(mean, std)
|
10 |
+
|
11 |
+
|
12 |
+
def get_padding(kernel_size, dilation=1):
|
13 |
+
return int((kernel_size * dilation - dilation) / 2)
|
14 |
+
|
15 |
+
|
16 |
+
def convert_pad_shape(pad_shape):
|
17 |
+
layer = pad_shape[::-1]
|
18 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
19 |
+
return pad_shape
|
20 |
+
|
21 |
+
|
22 |
+
def intersperse(lst, item):
|
23 |
+
result = [item] * (len(lst) * 2 + 1)
|
24 |
+
result[1::2] = lst
|
25 |
+
return result
|
26 |
+
|
27 |
+
|
28 |
+
def kl_divergence(m_p, logs_p, m_q, logs_q):
|
29 |
+
"""KL(P||Q)"""
|
30 |
+
kl = (logs_q - logs_p) - 0.5
|
31 |
+
kl += (
|
32 |
+
0.5 * (torch.exp(2.0 * logs_p) + ((m_p - m_q) ** 2)) * torch.exp(-2.0 * logs_q)
|
33 |
+
)
|
34 |
+
return kl
|
35 |
+
|
36 |
+
|
37 |
+
def rand_gumbel(shape):
|
38 |
+
"""Sample from the Gumbel distribution, protect from overflows."""
|
39 |
+
uniform_samples = torch.rand(shape) * 0.99998 + 0.00001
|
40 |
+
return -torch.log(-torch.log(uniform_samples))
|
41 |
+
|
42 |
+
|
43 |
+
def rand_gumbel_like(x):
|
44 |
+
g = rand_gumbel(x.size()).to(dtype=x.dtype, device=x.device)
|
45 |
+
return g
|
46 |
+
|
47 |
+
|
48 |
+
def slice_segments(x, ids_str, segment_size=4):
|
49 |
+
ret = torch.zeros_like(x[:, :, :segment_size])
|
50 |
+
for i in range(x.size(0)):
|
51 |
+
idx_str = ids_str[i]
|
52 |
+
idx_end = idx_str + segment_size
|
53 |
+
ret[i] = x[i, :, idx_str:idx_end]
|
54 |
+
return ret
|
55 |
+
|
56 |
+
|
57 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
58 |
+
b, d, t = x.size()
|
59 |
+
if x_lengths is None:
|
60 |
+
x_lengths = t
|
61 |
+
ids_str_max = x_lengths - segment_size + 1
|
62 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
63 |
+
ret = slice_segments(x, ids_str, segment_size)
|
64 |
+
return ret, ids_str
|
65 |
+
|
66 |
+
|
67 |
+
def get_timing_signal_1d(length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
68 |
+
position = torch.arange(length, dtype=torch.float)
|
69 |
+
num_timescales = channels // 2
|
70 |
+
log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / (
|
71 |
+
num_timescales - 1
|
72 |
+
)
|
73 |
+
inv_timescales = min_timescale * torch.exp(
|
74 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment
|
75 |
+
)
|
76 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
77 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
78 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
79 |
+
signal = signal.view(1, channels, length)
|
80 |
+
return signal
|
81 |
+
|
82 |
+
|
83 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
84 |
+
b, channels, length = x.size()
|
85 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
86 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
87 |
+
|
88 |
+
|
89 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
90 |
+
b, channels, length = x.size()
|
91 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
92 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
93 |
+
|
94 |
+
|
95 |
+
def subsequent_mask(length):
|
96 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
97 |
+
return mask
|
98 |
+
|
99 |
+
|
100 |
+
@torch.jit.script
|
101 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
102 |
+
n_channels_int = n_channels[0]
|
103 |
+
in_act = input_a + input_b
|
104 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
105 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
106 |
+
acts = t_act * s_act
|
107 |
+
return acts
|
108 |
+
|
109 |
+
|
110 |
+
def convert_pad_shape(pad_shape):
|
111 |
+
layer = pad_shape[::-1]
|
112 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
113 |
+
return pad_shape
|
114 |
+
|
115 |
+
|
116 |
+
def shift_1d(x):
|
117 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
118 |
+
return x
|
119 |
+
|
120 |
+
|
121 |
+
def sequence_mask(length, max_length=None):
|
122 |
+
if max_length is None:
|
123 |
+
max_length = length.max()
|
124 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
125 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
126 |
+
|
127 |
+
|
128 |
+
def generate_path(duration, mask):
|
129 |
+
"""
|
130 |
+
duration: [b, 1, t_x]
|
131 |
+
mask: [b, 1, t_y, t_x]
|
132 |
+
"""
|
133 |
+
|
134 |
+
b, _, t_y, t_x = mask.shape
|
135 |
+
cum_duration = torch.cumsum(duration, -1)
|
136 |
+
|
137 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
138 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
139 |
+
path = path.view(b, t_x, t_y)
|
140 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
141 |
+
path = path.unsqueeze(1).transpose(2, 3) * mask
|
142 |
+
return path
|
143 |
+
|
144 |
+
|
145 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
146 |
+
if isinstance(parameters, torch.Tensor):
|
147 |
+
parameters = [parameters]
|
148 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
149 |
+
norm_type = float(norm_type)
|
150 |
+
if clip_value is not None:
|
151 |
+
clip_value = float(clip_value)
|
152 |
+
|
153 |
+
total_norm = 0
|
154 |
+
for p in parameters:
|
155 |
+
param_norm = p.grad.data.norm(norm_type)
|
156 |
+
total_norm += param_norm.item() ** norm_type
|
157 |
+
if clip_value is not None:
|
158 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
159 |
+
total_norm = total_norm ** (1.0 / norm_type)
|
160 |
+
return total_norm
|
configs/config.json
ADDED
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 100,
|
4 |
+
"eval_interval": 2000,
|
5 |
+
"seed": 52,
|
6 |
+
"epochs": 500,
|
7 |
+
"learning_rate": 0.00015,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 10,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 16384,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"skip_optimizer": true
|
22 |
+
},
|
23 |
+
"data": {
|
24 |
+
"training_files": "filelists/train.list",
|
25 |
+
"validation_files": "filelists/val.list",
|
26 |
+
"max_wav_value": 32768.0,
|
27 |
+
"sampling_rate": 44100,
|
28 |
+
"filter_length": 2048,
|
29 |
+
"hop_length": 512,
|
30 |
+
"win_length": 2048,
|
31 |
+
"n_mel_channels": 128,
|
32 |
+
"mel_fmin": 0.0,
|
33 |
+
"mel_fmax": null,
|
34 |
+
"add_blank": true,
|
35 |
+
"n_speakers": 350,
|
36 |
+
"cleaned_text": true,
|
37 |
+
"spk2id": {
|
38 |
+
"スペシャルウィーク_Special Week_特别周": 0,
|
39 |
+
"サイレンススズカ_Silence Suzuka_无声铃鹿": 1,
|
40 |
+
"トウカイテイオー_Tokai Teio_东海帝王": 2,
|
41 |
+
"マルゼンスキー_Maruzensky_丸善斯基": 3,
|
42 |
+
"フジキセキ_Fuji Kiseki_富士奇迹": 4,
|
43 |
+
"オグリキャップ_Oguri Cap_小栗帽": 5,
|
44 |
+
"ゴールドシップ_Gold Ship_黄金船": 6,
|
45 |
+
"ウオッカ_Vodka_伏特加": 7,
|
46 |
+
"ダイワスカーレット_Daiwa Scarlet_大和赤骥": 8,
|
47 |
+
"タイキシャトル_Taiki Shuttle_大树快车": 9,
|
48 |
+
"グラスワンダー_Grass Wonder_草上飞": 10,
|
49 |
+
"ヒシアマゾン_Hishi Amazon_菱亚马逊": 11,
|
50 |
+
"メジロマックイーン_Mejiro McQueen_目白麦昆": 12,
|
51 |
+
"エルコンドルパサー_El Condor Pasa_神鹰": 13,
|
52 |
+
"テイエムオペラオー_T.M. Opera O_好歌剧": 14,
|
53 |
+
"ナリタブライアン_Narita Brian_成田白仁": 15,
|
54 |
+
"シンボリルドルフ_Symboli Rudolf_鲁道夫象征": 16,
|
55 |
+
"エアグルーヴ_Air Groove_气槽": 17,
|
56 |
+
"アグネスデジタル_Agnes Digital_爱丽数码": 18,
|
57 |
+
"セイウンスカイ_Seiun Sky_青云天空": 19,
|
58 |
+
"タマモクロス_Tamamo Cross_玉藻十字": 20,
|
59 |
+
"ファインモーション_Fine Motion_美妙姿势": 21,
|
60 |
+
"ビワハヤヒデ_Biwa Hayahide_琵琶晨光": 22,
|
61 |
+
"マヤノトップガン_Mayano Top Gun_摩耶重炮": 23,
|
62 |
+
"マンハッタンカフェ_Manhattan Cafe_曼城茶座": 24,
|
63 |
+
"ミホノブルボン_Mihono Bourbon_美浦波旁": 25,
|
64 |
+
"メジロライアン_Mejiro Ryan_目白赖恩": 26,
|
65 |
+
"ヒシアケボノ_Hishi Akebono_菱曙": 27,
|
66 |
+
"ユキノビジン_Yukino Bijin_雪之美人": 28,
|
67 |
+
"ライスシャワー_Rice Shower_米浴": 29,
|
68 |
+
"アイネスフウジン_Ines Fujin_艾尼斯风神": 30,
|
69 |
+
"アグネスタキオン_Agnes Tachyon_爱丽速子": 31,
|
70 |
+
"_アドマイヤベガ_Admire Vega_爱慕织姬": 32,
|
71 |
+
"イナリワン_Inari One_稻荷一": 33,
|
72 |
+
"ウイニングチケット_Winning Ticket_胜利奖券": 34,
|
73 |
+
"エアシャカール_Air Shakur_空中神宫": 35,
|
74 |
+
"エイシンフラッシュ_Eishin Flash_荣进闪耀": 36,
|
75 |
+
"カレンチャン_Curren Chan_真机伶": 37,
|
76 |
+
"カワカミプリンセス_Kawakami Princess_川上公主": 38,
|
77 |
+
"ゴールドシチー_Gold City_黄金城市": 39,
|
78 |
+
"サクラバクシンオー_Sakura Bakushin O_樱花进王": 40,
|
79 |
+
"シーキングザパール_Seeking the Pearl_采珠": 41,
|
80 |
+
"シンコウウインディ_Shinko Windy_新光风": 42,
|
81 |
+
"スイープトウショウ_Sweep Tosho_东商变革": 43,
|
82 |
+
"スーパークリーク_Super Creek_超级溪流": 44,
|
83 |
+
"スマートファルコン_Smart Falcon_醒目飞鹰": 45,
|
84 |
+
"ゼンノロブロイ_Zenno Rob Roy_荒漠英雄": 46,
|
85 |
+
"トーセンジョーダン_Tosen Jordan_东瀛佐敦": 47,
|
86 |
+
"ナカヤマフェスタ_Nakayama Festa_中山庆典": 48,
|
87 |
+
"ナリタタイシン_Narita Taishin_成田大进": 49,
|
88 |
+
"ニシノフラワー_Nishino Flower_西野花": 50,
|
89 |
+
"ハルウララ_Haru Urara_春丽": 51,
|
90 |
+
"バンブーメモリー_Bamboo Memory_青竹回忆": 52,
|
91 |
+
"ビコーペガサス_Biko Pegasus_微光飞驹": 53,
|
92 |
+
"ーベラスサンデー_Marvelous Sunday_美丽周日": 54,
|
93 |
+
"マチカネフクキタル_Matikanefukukitaru_待兼福来": 55,
|
94 |
+
"ミスターシービー_Mr. C.B._千明代表": 56,
|
95 |
+
"メイショウドトウ_Meisho Doto_名将怒涛": 57,
|
96 |
+
"メジロドーベル_Mejiro Dober_目白多伯": 58,
|
97 |
+
"ナイスネイチャ_Nice Nature_优秀素质": 59,
|
98 |
+
"キングヘイロー_King Halo_圣王光环": 60,
|
99 |
+
"マチカネタンホイザ_Matikanetannhauser_待兼诗歌剧": 61,
|
100 |
+
"イクノディクタス_Ikuno Dictus_生野狄杜斯": 62,
|
101 |
+
"メジロパーマー_Mejiro Palmer_目白善信": 63,
|
102 |
+
"ダイタクヘリオス_Daitaku Helios_大拓太阳神": 64,
|
103 |
+
"ツインターボ_Twin Turbo_双涡轮": 65,
|
104 |
+
"サ トノダイヤモンド_Satono Diamond_里见光钻": 66,
|
105 |
+
"キタサンブラック_Kitasan Black_北部玄驹": 67,
|
106 |
+
"サクラチヨノオー_Sakura Chiyono O_樱花千代王": 68,
|
107 |
+
"シリウスシンボリ_Sirius Symboli_天狼星象征": 69,
|
108 |
+
"メジロアルダン_Mejiro Ardan_目白阿尔丹": 70,
|
109 |
+
"ヤエノムテキ_Yaeno Muteki_八重无敌": 71,
|
110 |
+
"ツルマルツヨシ_Tsurumaru Tsuyoshi_鹤丸刚志": 72,
|
111 |
+
"メジロブライト_Mejiro Bright_目白光明": 73,
|
112 |
+
"サクラローレル_Sakura Laurel_樱花桂冠": 74,
|
113 |
+
"ナリタトップロード_Narita Top Road_成田路": 75,
|
114 |
+
"ヤマニンゼファー_Yamanin Zephyr_也文摄辉": 76,
|
115 |
+
"シンボリクリスエス_Symboli Kris S_吉兆": 77,
|
116 |
+
"タニノギムレット_Tanino Gimlet_谷野美酒": 78,
|
117 |
+
"ダイイチルビー_Daiichi Ruby_第一红宝石": 79,
|
118 |
+
"メジロラモーヌ_Mejiro Ramonu_目白高峰": 80,
|
119 |
+
"アストンマーチャン_Aston Machan_真弓快车": 81,
|
120 |
+
"サトノクラウン_Satono Crown_里见皇冠": 82,
|
121 |
+
"シュヴァルグラン_Cheval Grand_高尚骏逸": 83,
|
122 |
+
"ケイエスミラクル_K.S.Miracle_凯斯奇迹": 84,
|
123 |
+
"ジャングルポケット_Jungle Pocket_森林宝穴": 85,
|
124 |
+
"コパノリッキー_Copano Rickey_小林历奇": 86,
|
125 |
+
"ホッコータルマエ_Hokko Tarumae_北港火山": 87,
|
126 |
+
"ワンダーアキュート_Wonder Acute_奇锐骏": 88,
|
127 |
+
"カツラギエース_Katsuragi Ace_葛城王牌": 89,
|
128 |
+
"ネオユニヴァース_Neo Universe_新宇宙": 90,
|
129 |
+
"ヒシミラクル_Hishi Miracle_菱钻奇宝": 91,
|
130 |
+
"タップダンスシチー_Tap Dance City_跳舞城": 92,
|
131 |
+
"モンジュー_Montjeu_望族": 93,
|
132 |
+
"駿川 たづな_Hayakawa Tazuna_骏川手纲": 94,
|
133 |
+
"秋川 やよい_Akikawa Yayoi_秋川弥生": 95,
|
134 |
+
"乙名史悦子_Otonashi Etsuko_乙名史悦子": 96,
|
135 |
+
"桐生院葵_Kiryuin Aoi_桐生院葵": 97,
|
136 |
+
"安 心沢 刺々美_Anshinzawa Sasami_安心泽刺刺美": 98,
|
137 |
+
"樫本 理子_Kashimoto Riko_㭴本理子": 99,
|
138 |
+
"ライトハロー_Light Hello_光辉致意": 100,
|
139 |
+
"ダーレーアラビアン_Darley Arabian_达利阿拉伯": 101,
|
140 |
+
"ゴドルフィンアラビアン_Godolphin Arabian_高多芬阿拉伯": 102,
|
141 |
+
"バイアリーターク_Byerley Turk_拜耶尔土耳其": 103,
|
142 |
+
"佐岳めい_Satake Mei_佐岳芽衣": 104,
|
143 |
+
"七七": 105,
|
144 |
+
"丽莎": 106,
|
145 |
+
"久岐忍": 107,
|
146 |
+
"九条裟罗": 108,
|
147 |
+
"云堇": 109,
|
148 |
+
"五郎": 110,
|
149 |
+
"优菈": 111,
|
150 |
+
"八重神子": 112,
|
151 |
+
"凝光": 113,
|
152 |
+
"凯亚": 114,
|
153 |
+
"凯瑟琳": 115,
|
154 |
+
"刻晴": 116,
|
155 |
+
"北斗": 117,
|
156 |
+
"卡维": 118,
|
157 |
+
"可莉": 119,
|
158 |
+
"坎蒂丝": 120,
|
159 |
+
"夏洛蒂": 121,
|
160 |
+
"多莉": 122,
|
161 |
+
"夜兰": 123,
|
162 |
+
"妮露": 124,
|
163 |
+
"娜维娅": 125,
|
164 |
+
"安柏": 126,
|
165 |
+
"宵宫": 127,
|
166 |
+
"戴因斯雷布": 128,
|
167 |
+
"托马": 129,
|
168 |
+
"提纳里": 130,
|
169 |
+
"散兵_流浪者": 131,
|
170 |
+
"早柚": 132,
|
171 |
+
"林尼": 133,
|
172 |
+
"枫原万叶": 134,
|
173 |
+
"柯莱": 135,
|
174 |
+
"派蒙": 136,
|
175 |
+
"温迪": 137,
|
176 |
+
"烟绯": 138,
|
177 |
+
"珊瑚宫心海": 139,
|
178 |
+
"珐露珊": 140,
|
179 |
+
"班尼特": 141,
|
180 |
+
"琳妮特": 142,
|
181 |
+
"琴": 143,
|
182 |
+
"瑶瑶": 144,
|
183 |
+
"甘雨": 145,
|
184 |
+
"申鹤": 146,
|
185 |
+
"白术": 147,
|
186 |
+
"砂糖": 148,
|
187 |
+
"神里绫人": 149,
|
188 |
+
"神里绫华": 150,
|
189 |
+
"空": 151,
|
190 |
+
"米卡": 152,
|
191 |
+
"纳西妲": 153,
|
192 |
+
"绮良良": 154,
|
193 |
+
"罗莎莉亚": 155,
|
194 |
+
"胡桃": 156,
|
195 |
+
"艾尔海森": 157,
|
196 |
+
"芙宁娜": 158,
|
197 |
+
"芭芭拉": 159,
|
198 |
+
"荒泷一斗": 160,
|
199 |
+
"荧": 161,
|
200 |
+
"莫娜": 162,
|
201 |
+
"莱依拉": 163,
|
202 |
+
"菲米尼": 164,
|
203 |
+
"菲谢尔": 165,
|
204 |
+
"行秋": 166,
|
205 |
+
"诺艾尔": 167,
|
206 |
+
"赛诺": 168,
|
207 |
+
"辛焱": 169,
|
208 |
+
"达达利亚": 170,
|
209 |
+
"迪卢克": 171,
|
210 |
+
"迪奥娜": 172,
|
211 |
+
"迪希雅": 173,
|
212 |
+
"那维莱特": 174,
|
213 |
+
"重云": 175,
|
214 |
+
"钟离": 176,
|
215 |
+
"阿贝多": 177,
|
216 |
+
"雷泽": 178,
|
217 |
+
"雷电将军_雷电影": 179,
|
218 |
+
"香菱": 180,
|
219 |
+
"魈": 181,
|
220 |
+
"鹿野院平藏": 182,
|
221 |
+
"三月七(中配)": 183,
|
222 |
+
"丹恒(中配)": 184,
|
223 |
+
"佩拉(中配)": 185,
|
224 |
+
"停云(中配)": 186,
|
225 |
+
"克拉拉(中配)": 187,
|
226 |
+
"卡芙卡(中配)": 188,
|
227 |
+
"卢卡(中配)": 189,
|
228 |
+
"姬子(中配)": 190,
|
229 |
+
"娜塔莎(中配)": 191,
|
230 |
+
"布洛妮娅(中配)": 192,
|
231 |
+
"希儿(中配)": 193,
|
232 |
+
"希露瓦(中配)": 194,
|
233 |
+
"帕姆(中配)": 195,
|
234 |
+
"开拓者(女)(中配)": 196,
|
235 |
+
"开拓者(男)(中配)": 197,
|
236 |
+
"彦卿(中配)": 198,
|
237 |
+
"景元(中配)": 199,
|
238 |
+
"杰帕德(中配)": 200,
|
239 |
+
"桑博(中配)": 201,
|
240 |
+
"玲可(中配)": 202,
|
241 |
+
"瓦尔特(中配)": 203,
|
242 |
+
"白露(中配)": 204,
|
243 |
+
"符玄(中配)": 205,
|
244 |
+
"素裳(��配)": 206,
|
245 |
+
"罗刹(中配)": 207,
|
246 |
+
"艾丝妲(中配)": 208,
|
247 |
+
"虎克(中配)": 209,
|
248 |
+
"银狼(中配)": 210,
|
249 |
+
"阿兰(中配)": 211,
|
250 |
+
"青雀(中配)": 212,
|
251 |
+
"驭空(中配)": 213,
|
252 |
+
"黑塔(中配)": 214,
|
253 |
+
"「公子」": 215,
|
254 |
+
"「散兵」": 216,
|
255 |
+
"アルハイゼン": 217,
|
256 |
+
"アルベド": 218,
|
257 |
+
"アンバー": 219,
|
258 |
+
"ウェンティ": 220,
|
259 |
+
"エウルア": 221,
|
260 |
+
"カーヴェ": 222,
|
261 |
+
"ガイア": 223,
|
262 |
+
"キャサリン": 224,
|
263 |
+
"キャンディス": 225,
|
264 |
+
"クレー": 226,
|
265 |
+
"コレイ": 227,
|
266 |
+
"ゴロー": 228,
|
267 |
+
"ジン": 229,
|
268 |
+
"スクロース": 230,
|
269 |
+
"セノ": 231,
|
270 |
+
"タルタリヤ": 232,
|
271 |
+
"ダインスレイヴ": 233,
|
272 |
+
"ティナリ": 234,
|
273 |
+
"ディオナ": 235,
|
274 |
+
"ディシア": 236,
|
275 |
+
"ディルック": 237,
|
276 |
+
"トーマ": 238,
|
277 |
+
"ドリー": 239,
|
278 |
+
"ナヒーダ": 240,
|
279 |
+
"ナヴィア": 241,
|
280 |
+
"ニィロウ": 242,
|
281 |
+
"ノエル": 243,
|
282 |
+
"バーバラ": 244,
|
283 |
+
"パイモン": 245,
|
284 |
+
"ファルザン": 246,
|
285 |
+
"フィッシュル": 247,
|
286 |
+
"フリーナ": 248,
|
287 |
+
"ベネット": 249,
|
288 |
+
"ミカ": 250,
|
289 |
+
"モナ": 251,
|
290 |
+
"ヨォーヨ": 252,
|
291 |
+
"リサ": 253,
|
292 |
+
"リネ": 254,
|
293 |
+
"リネット": 255,
|
294 |
+
"レイラ": 256,
|
295 |
+
"レザー": 257,
|
296 |
+
"九条裟羅": 258,
|
297 |
+
"夜蘭": 259,
|
298 |
+
"宵宮": 260,
|
299 |
+
"影": 261,
|
300 |
+
"楓原万葉": 262,
|
301 |
+
"煙緋": 263,
|
302 |
+
"珊瑚宮心海": 264,
|
303 |
+
"申鶴": 265,
|
304 |
+
"白朮": 266,
|
305 |
+
"神里綾人": 267,
|
306 |
+
"神里綾華": 268,
|
307 |
+
"綺良々": 269,
|
308 |
+
"荒瀧一斗": 270,
|
309 |
+
"蛍": 271,
|
310 |
+
"辛炎": 272,
|
311 |
+
"重雲": 273,
|
312 |
+
"鍾離": 274,
|
313 |
+
"雲菫": 275,
|
314 |
+
"鹿野院平蔵": 276,
|
315 |
+
"アスター": 277,
|
316 |
+
"アーラン": 278,
|
317 |
+
"カフカ": 279,
|
318 |
+
"クラーラ": 280,
|
319 |
+
"サンポ": 281,
|
320 |
+
"ジェパード": 282,
|
321 |
+
"セーバル": 283,
|
322 |
+
"ゼーレ": 284,
|
323 |
+
"ナターシャ": 285,
|
324 |
+
"パム": 286,
|
325 |
+
"フック": 287,
|
326 |
+
"ブローニャ": 288,
|
327 |
+
"ヘルタ": 289,
|
328 |
+
"ペラ": 290,
|
329 |
+
"リンクス": 291,
|
330 |
+
"ルカ": 292,
|
331 |
+
"ヴェルト": 293,
|
332 |
+
"三月なのか": 294,
|
333 |
+
"丹恒": 295,
|
334 |
+
"停雲": 296,
|
335 |
+
"姫子": 297,
|
336 |
+
"彦卿": 298,
|
337 |
+
"御空": 299,
|
338 |
+
"景元": 300,
|
339 |
+
"白露": 301,
|
340 |
+
"符玄": 302,
|
341 |
+
"素裳": 303,
|
342 |
+
"羅刹": 304,
|
343 |
+
"銀狼": 305,
|
344 |
+
"開拓者(女)": 306,
|
345 |
+
"開拓者(男)": 307,
|
346 |
+
"青雀": 308
|
347 |
+
}
|
348 |
+
},
|
349 |
+
"model": {
|
350 |
+
"use_spk_conditioned_encoder": true,
|
351 |
+
"use_noise_scaled_mas": true,
|
352 |
+
"use_mel_posterior_encoder": false,
|
353 |
+
"use_duration_discriminator": true,
|
354 |
+
"inter_channels": 192,
|
355 |
+
"hidden_channels": 192,
|
356 |
+
"filter_channels": 768,
|
357 |
+
"n_heads": 2,
|
358 |
+
"n_layers": 6,
|
359 |
+
"kernel_size": 3,
|
360 |
+
"p_dropout": 0.1,
|
361 |
+
"resblock": "1",
|
362 |
+
"resblock_kernel_sizes": [
|
363 |
+
3,
|
364 |
+
7,
|
365 |
+
11
|
366 |
+
],
|
367 |
+
"resblock_dilation_sizes": [
|
368 |
+
[
|
369 |
+
1,
|
370 |
+
3,
|
371 |
+
5
|
372 |
+
],
|
373 |
+
[
|
374 |
+
1,
|
375 |
+
3,
|
376 |
+
5
|
377 |
+
],
|
378 |
+
[
|
379 |
+
1,
|
380 |
+
3,
|
381 |
+
5
|
382 |
+
]
|
383 |
+
],
|
384 |
+
"upsample_rates": [
|
385 |
+
8,
|
386 |
+
8,
|
387 |
+
2,
|
388 |
+
2,
|
389 |
+
2
|
390 |
+
],
|
391 |
+
"upsample_initial_channel": 512,
|
392 |
+
"upsample_kernel_sizes": [
|
393 |
+
16,
|
394 |
+
16,
|
395 |
+
8,
|
396 |
+
2,
|
397 |
+
2
|
398 |
+
],
|
399 |
+
"n_layers_q": 3,
|
400 |
+
"use_spectral_norm": false,
|
401 |
+
"gin_channels": 256
|
402 |
+
}
|
403 |
+
}
|
logs/UGH/G_350000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:48565f7cbb6206c3e4421fa61096522b6b1c1ba199d37f19427fb3b2809cae0d
|
3 |
+
size 858216603
|
models.py
ADDED
@@ -0,0 +1,986 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import modules
|
8 |
+
import attentions
|
9 |
+
import monotonic_align
|
10 |
+
|
11 |
+
from torch.nn import Conv1d, ConvTranspose1d, Conv2d
|
12 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
13 |
+
|
14 |
+
from commons import init_weights, get_padding
|
15 |
+
from text import symbols, num_tones, num_languages
|
16 |
+
|
17 |
+
|
18 |
+
class DurationDiscriminator(nn.Module): # vits2
|
19 |
+
def __init__(
|
20 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
21 |
+
):
|
22 |
+
super().__init__()
|
23 |
+
|
24 |
+
self.in_channels = in_channels
|
25 |
+
self.filter_channels = filter_channels
|
26 |
+
self.kernel_size = kernel_size
|
27 |
+
self.p_dropout = p_dropout
|
28 |
+
self.gin_channels = gin_channels
|
29 |
+
|
30 |
+
self.drop = nn.Dropout(p_dropout)
|
31 |
+
self.conv_1 = nn.Conv1d(
|
32 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
33 |
+
)
|
34 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
35 |
+
self.conv_2 = nn.Conv1d(
|
36 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
37 |
+
)
|
38 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
39 |
+
self.dur_proj = nn.Conv1d(1, filter_channels, 1)
|
40 |
+
|
41 |
+
self.pre_out_conv_1 = nn.Conv1d(
|
42 |
+
2 * filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
43 |
+
)
|
44 |
+
self.pre_out_norm_1 = modules.LayerNorm(filter_channels)
|
45 |
+
self.pre_out_conv_2 = nn.Conv1d(
|
46 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
47 |
+
)
|
48 |
+
self.pre_out_norm_2 = modules.LayerNorm(filter_channels)
|
49 |
+
|
50 |
+
if gin_channels != 0:
|
51 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
52 |
+
|
53 |
+
self.output_layer = nn.Sequential(nn.Linear(filter_channels, 1), nn.Sigmoid())
|
54 |
+
|
55 |
+
def forward_probability(self, x, x_mask, dur, g=None):
|
56 |
+
dur = self.dur_proj(dur)
|
57 |
+
x = torch.cat([x, dur], dim=1)
|
58 |
+
x = self.pre_out_conv_1(x * x_mask)
|
59 |
+
x = torch.relu(x)
|
60 |
+
x = self.pre_out_norm_1(x)
|
61 |
+
x = self.drop(x)
|
62 |
+
x = self.pre_out_conv_2(x * x_mask)
|
63 |
+
x = torch.relu(x)
|
64 |
+
x = self.pre_out_norm_2(x)
|
65 |
+
x = self.drop(x)
|
66 |
+
x = x * x_mask
|
67 |
+
x = x.transpose(1, 2)
|
68 |
+
output_prob = self.output_layer(x)
|
69 |
+
return output_prob
|
70 |
+
|
71 |
+
def forward(self, x, x_mask, dur_r, dur_hat, g=None):
|
72 |
+
x = torch.detach(x)
|
73 |
+
if g is not None:
|
74 |
+
g = torch.detach(g)
|
75 |
+
x = x + self.cond(g)
|
76 |
+
x = self.conv_1(x * x_mask)
|
77 |
+
x = torch.relu(x)
|
78 |
+
x = self.norm_1(x)
|
79 |
+
x = self.drop(x)
|
80 |
+
x = self.conv_2(x * x_mask)
|
81 |
+
x = torch.relu(x)
|
82 |
+
x = self.norm_2(x)
|
83 |
+
x = self.drop(x)
|
84 |
+
|
85 |
+
output_probs = []
|
86 |
+
for dur in [dur_r, dur_hat]:
|
87 |
+
output_prob = self.forward_probability(x, x_mask, dur, g)
|
88 |
+
output_probs.append(output_prob)
|
89 |
+
|
90 |
+
return output_probs
|
91 |
+
|
92 |
+
|
93 |
+
class TransformerCouplingBlock(nn.Module):
|
94 |
+
def __init__(
|
95 |
+
self,
|
96 |
+
channels,
|
97 |
+
hidden_channels,
|
98 |
+
filter_channels,
|
99 |
+
n_heads,
|
100 |
+
n_layers,
|
101 |
+
kernel_size,
|
102 |
+
p_dropout,
|
103 |
+
n_flows=4,
|
104 |
+
gin_channels=0,
|
105 |
+
share_parameter=False,
|
106 |
+
):
|
107 |
+
super().__init__()
|
108 |
+
self.channels = channels
|
109 |
+
self.hidden_channels = hidden_channels
|
110 |
+
self.kernel_size = kernel_size
|
111 |
+
self.n_layers = n_layers
|
112 |
+
self.n_flows = n_flows
|
113 |
+
self.gin_channels = gin_channels
|
114 |
+
|
115 |
+
self.flows = nn.ModuleList()
|
116 |
+
|
117 |
+
self.wn = (
|
118 |
+
attentions.FFT(
|
119 |
+
hidden_channels,
|
120 |
+
filter_channels,
|
121 |
+
n_heads,
|
122 |
+
n_layers,
|
123 |
+
kernel_size,
|
124 |
+
p_dropout,
|
125 |
+
isflow=True,
|
126 |
+
gin_channels=self.gin_channels,
|
127 |
+
)
|
128 |
+
if share_parameter
|
129 |
+
else None
|
130 |
+
)
|
131 |
+
|
132 |
+
for i in range(n_flows):
|
133 |
+
self.flows.append(
|
134 |
+
modules.TransformerCouplingLayer(
|
135 |
+
channels,
|
136 |
+
hidden_channels,
|
137 |
+
kernel_size,
|
138 |
+
n_layers,
|
139 |
+
n_heads,
|
140 |
+
p_dropout,
|
141 |
+
filter_channels,
|
142 |
+
mean_only=True,
|
143 |
+
wn_sharing_parameter=self.wn,
|
144 |
+
gin_channels=self.gin_channels,
|
145 |
+
)
|
146 |
+
)
|
147 |
+
self.flows.append(modules.Flip())
|
148 |
+
|
149 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
150 |
+
if not reverse:
|
151 |
+
for flow in self.flows:
|
152 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
153 |
+
else:
|
154 |
+
for flow in reversed(self.flows):
|
155 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
156 |
+
return x
|
157 |
+
|
158 |
+
|
159 |
+
class StochasticDurationPredictor(nn.Module):
|
160 |
+
def __init__(
|
161 |
+
self,
|
162 |
+
in_channels,
|
163 |
+
filter_channels,
|
164 |
+
kernel_size,
|
165 |
+
p_dropout,
|
166 |
+
n_flows=4,
|
167 |
+
gin_channels=0,
|
168 |
+
):
|
169 |
+
super().__init__()
|
170 |
+
filter_channels = in_channels # it needs to be removed from future version.
|
171 |
+
self.in_channels = in_channels
|
172 |
+
self.filter_channels = filter_channels
|
173 |
+
self.kernel_size = kernel_size
|
174 |
+
self.p_dropout = p_dropout
|
175 |
+
self.n_flows = n_flows
|
176 |
+
self.gin_channels = gin_channels
|
177 |
+
|
178 |
+
self.log_flow = modules.Log()
|
179 |
+
self.flows = nn.ModuleList()
|
180 |
+
self.flows.append(modules.ElementwiseAffine(2))
|
181 |
+
for i in range(n_flows):
|
182 |
+
self.flows.append(
|
183 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
184 |
+
)
|
185 |
+
self.flows.append(modules.Flip())
|
186 |
+
|
187 |
+
self.post_pre = nn.Conv1d(1, filter_channels, 1)
|
188 |
+
self.post_proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
189 |
+
self.post_convs = modules.DDSConv(
|
190 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
191 |
+
)
|
192 |
+
self.post_flows = nn.ModuleList()
|
193 |
+
self.post_flows.append(modules.ElementwiseAffine(2))
|
194 |
+
for i in range(4):
|
195 |
+
self.post_flows.append(
|
196 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
197 |
+
)
|
198 |
+
self.post_flows.append(modules.Flip())
|
199 |
+
|
200 |
+
self.pre = nn.Conv1d(in_channels, filter_channels, 1)
|
201 |
+
self.proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
202 |
+
self.convs = modules.DDSConv(
|
203 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
204 |
+
)
|
205 |
+
if gin_channels != 0:
|
206 |
+
self.cond = nn.Conv1d(gin_channels, filter_channels, 1)
|
207 |
+
|
208 |
+
def forward(self, x, x_mask, w=None, g=None, reverse=False, noise_scale=1.0):
|
209 |
+
x = torch.detach(x)
|
210 |
+
x = self.pre(x)
|
211 |
+
if g is not None:
|
212 |
+
g = torch.detach(g)
|
213 |
+
x = x + self.cond(g)
|
214 |
+
x = self.convs(x, x_mask)
|
215 |
+
x = self.proj(x) * x_mask
|
216 |
+
|
217 |
+
if not reverse:
|
218 |
+
flows = self.flows
|
219 |
+
assert w is not None
|
220 |
+
|
221 |
+
logdet_tot_q = 0
|
222 |
+
h_w = self.post_pre(w)
|
223 |
+
h_w = self.post_convs(h_w, x_mask)
|
224 |
+
h_w = self.post_proj(h_w) * x_mask
|
225 |
+
e_q = (
|
226 |
+
torch.randn(w.size(0), 2, w.size(2)).to(device=x.device, dtype=x.dtype)
|
227 |
+
* x_mask
|
228 |
+
)
|
229 |
+
z_q = e_q
|
230 |
+
for flow in self.post_flows:
|
231 |
+
z_q, logdet_q = flow(z_q, x_mask, g=(x + h_w))
|
232 |
+
logdet_tot_q += logdet_q
|
233 |
+
z_u, z1 = torch.split(z_q, [1, 1], 1)
|
234 |
+
u = torch.sigmoid(z_u) * x_mask
|
235 |
+
z0 = (w - u) * x_mask
|
236 |
+
logdet_tot_q += torch.sum(
|
237 |
+
(F.logsigmoid(z_u) + F.logsigmoid(-z_u)) * x_mask, [1, 2]
|
238 |
+
)
|
239 |
+
logq = (
|
240 |
+
torch.sum(-0.5 * (math.log(2 * math.pi) + (e_q**2)) * x_mask, [1, 2])
|
241 |
+
- logdet_tot_q
|
242 |
+
)
|
243 |
+
|
244 |
+
logdet_tot = 0
|
245 |
+
z0, logdet = self.log_flow(z0, x_mask)
|
246 |
+
logdet_tot += logdet
|
247 |
+
z = torch.cat([z0, z1], 1)
|
248 |
+
for flow in flows:
|
249 |
+
z, logdet = flow(z, x_mask, g=x, reverse=reverse)
|
250 |
+
logdet_tot = logdet_tot + logdet
|
251 |
+
nll = (
|
252 |
+
torch.sum(0.5 * (math.log(2 * math.pi) + (z**2)) * x_mask, [1, 2])
|
253 |
+
- logdet_tot
|
254 |
+
)
|
255 |
+
return nll + logq # [b]
|
256 |
+
else:
|
257 |
+
flows = list(reversed(self.flows))
|
258 |
+
flows = flows[:-2] + [flows[-1]] # remove a useless vflow
|
259 |
+
z = (
|
260 |
+
torch.randn(x.size(0), 2, x.size(2)).to(device=x.device, dtype=x.dtype)
|
261 |
+
* noise_scale
|
262 |
+
)
|
263 |
+
for flow in flows:
|
264 |
+
z = flow(z, x_mask, g=x, reverse=reverse)
|
265 |
+
z0, z1 = torch.split(z, [1, 1], 1)
|
266 |
+
logw = z0
|
267 |
+
return logw
|
268 |
+
|
269 |
+
|
270 |
+
class DurationPredictor(nn.Module):
|
271 |
+
def __init__(
|
272 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
273 |
+
):
|
274 |
+
super().__init__()
|
275 |
+
|
276 |
+
self.in_channels = in_channels
|
277 |
+
self.filter_channels = filter_channels
|
278 |
+
self.kernel_size = kernel_size
|
279 |
+
self.p_dropout = p_dropout
|
280 |
+
self.gin_channels = gin_channels
|
281 |
+
|
282 |
+
self.drop = nn.Dropout(p_dropout)
|
283 |
+
self.conv_1 = nn.Conv1d(
|
284 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
285 |
+
)
|
286 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
287 |
+
self.conv_2 = nn.Conv1d(
|
288 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
289 |
+
)
|
290 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
291 |
+
self.proj = nn.Conv1d(filter_channels, 1, 1)
|
292 |
+
|
293 |
+
if gin_channels != 0:
|
294 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
295 |
+
|
296 |
+
def forward(self, x, x_mask, g=None):
|
297 |
+
x = torch.detach(x)
|
298 |
+
if g is not None:
|
299 |
+
g = torch.detach(g)
|
300 |
+
x = x + self.cond(g)
|
301 |
+
x = self.conv_1(x * x_mask)
|
302 |
+
x = torch.relu(x)
|
303 |
+
x = self.norm_1(x)
|
304 |
+
x = self.drop(x)
|
305 |
+
x = self.conv_2(x * x_mask)
|
306 |
+
x = torch.relu(x)
|
307 |
+
x = self.norm_2(x)
|
308 |
+
x = self.drop(x)
|
309 |
+
x = self.proj(x * x_mask)
|
310 |
+
return x * x_mask
|
311 |
+
|
312 |
+
|
313 |
+
class TextEncoder(nn.Module):
|
314 |
+
def __init__(
|
315 |
+
self,
|
316 |
+
n_vocab,
|
317 |
+
out_channels,
|
318 |
+
hidden_channels,
|
319 |
+
filter_channels,
|
320 |
+
n_heads,
|
321 |
+
n_layers,
|
322 |
+
kernel_size,
|
323 |
+
p_dropout,
|
324 |
+
gin_channels=0,
|
325 |
+
):
|
326 |
+
super().__init__()
|
327 |
+
self.n_vocab = n_vocab
|
328 |
+
self.out_channels = out_channels
|
329 |
+
self.hidden_channels = hidden_channels
|
330 |
+
self.filter_channels = filter_channels
|
331 |
+
self.n_heads = n_heads
|
332 |
+
self.n_layers = n_layers
|
333 |
+
self.kernel_size = kernel_size
|
334 |
+
self.p_dropout = p_dropout
|
335 |
+
self.gin_channels = gin_channels
|
336 |
+
self.emb = nn.Embedding(len(symbols), hidden_channels)
|
337 |
+
nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5)
|
338 |
+
self.tone_emb = nn.Embedding(num_tones, hidden_channels)
|
339 |
+
nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5)
|
340 |
+
self.language_emb = nn.Embedding(num_languages, hidden_channels)
|
341 |
+
nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5)
|
342 |
+
self.bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
343 |
+
self.ja_bert_proj = nn.Conv1d(768, hidden_channels, 1)
|
344 |
+
|
345 |
+
self.encoder = attentions.Encoder(
|
346 |
+
hidden_channels,
|
347 |
+
filter_channels,
|
348 |
+
n_heads,
|
349 |
+
n_layers,
|
350 |
+
kernel_size,
|
351 |
+
p_dropout,
|
352 |
+
gin_channels=self.gin_channels,
|
353 |
+
)
|
354 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
355 |
+
|
356 |
+
def forward(self, x, x_lengths, tone, language, bert, ja_bert, g=None):
|
357 |
+
bert_emb = self.bert_proj(bert).transpose(1, 2)
|
358 |
+
ja_bert_emb = self.ja_bert_proj(ja_bert).transpose(1, 2)
|
359 |
+
x = (
|
360 |
+
self.emb(x)
|
361 |
+
+ self.tone_emb(tone)
|
362 |
+
+ self.language_emb(language)
|
363 |
+
+ bert_emb
|
364 |
+
+ ja_bert_emb
|
365 |
+
) * math.sqrt(
|
366 |
+
self.hidden_channels
|
367 |
+
) # [b, t, h]
|
368 |
+
x = torch.transpose(x, 1, -1) # [b, h, t]
|
369 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
370 |
+
x.dtype
|
371 |
+
)
|
372 |
+
|
373 |
+
x = self.encoder(x * x_mask, x_mask, g=g)
|
374 |
+
stats = self.proj(x) * x_mask
|
375 |
+
|
376 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
377 |
+
return x, m, logs, x_mask
|
378 |
+
|
379 |
+
|
380 |
+
class ResidualCouplingBlock(nn.Module):
|
381 |
+
def __init__(
|
382 |
+
self,
|
383 |
+
channels,
|
384 |
+
hidden_channels,
|
385 |
+
kernel_size,
|
386 |
+
dilation_rate,
|
387 |
+
n_layers,
|
388 |
+
n_flows=4,
|
389 |
+
gin_channels=0,
|
390 |
+
):
|
391 |
+
super().__init__()
|
392 |
+
self.channels = channels
|
393 |
+
self.hidden_channels = hidden_channels
|
394 |
+
self.kernel_size = kernel_size
|
395 |
+
self.dilation_rate = dilation_rate
|
396 |
+
self.n_layers = n_layers
|
397 |
+
self.n_flows = n_flows
|
398 |
+
self.gin_channels = gin_channels
|
399 |
+
|
400 |
+
self.flows = nn.ModuleList()
|
401 |
+
for i in range(n_flows):
|
402 |
+
self.flows.append(
|
403 |
+
modules.ResidualCouplingLayer(
|
404 |
+
channels,
|
405 |
+
hidden_channels,
|
406 |
+
kernel_size,
|
407 |
+
dilation_rate,
|
408 |
+
n_layers,
|
409 |
+
gin_channels=gin_channels,
|
410 |
+
mean_only=True,
|
411 |
+
)
|
412 |
+
)
|
413 |
+
self.flows.append(modules.Flip())
|
414 |
+
|
415 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
416 |
+
if not reverse:
|
417 |
+
for flow in self.flows:
|
418 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
419 |
+
else:
|
420 |
+
for flow in reversed(self.flows):
|
421 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
422 |
+
return x
|
423 |
+
|
424 |
+
|
425 |
+
class PosteriorEncoder(nn.Module):
|
426 |
+
def __init__(
|
427 |
+
self,
|
428 |
+
in_channels,
|
429 |
+
out_channels,
|
430 |
+
hidden_channels,
|
431 |
+
kernel_size,
|
432 |
+
dilation_rate,
|
433 |
+
n_layers,
|
434 |
+
gin_channels=0,
|
435 |
+
):
|
436 |
+
super().__init__()
|
437 |
+
self.in_channels = in_channels
|
438 |
+
self.out_channels = out_channels
|
439 |
+
self.hidden_channels = hidden_channels
|
440 |
+
self.kernel_size = kernel_size
|
441 |
+
self.dilation_rate = dilation_rate
|
442 |
+
self.n_layers = n_layers
|
443 |
+
self.gin_channels = gin_channels
|
444 |
+
|
445 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
446 |
+
self.enc = modules.WN(
|
447 |
+
hidden_channels,
|
448 |
+
kernel_size,
|
449 |
+
dilation_rate,
|
450 |
+
n_layers,
|
451 |
+
gin_channels=gin_channels,
|
452 |
+
)
|
453 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
454 |
+
|
455 |
+
def forward(self, x, x_lengths, g=None):
|
456 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
457 |
+
x.dtype
|
458 |
+
)
|
459 |
+
x = self.pre(x) * x_mask
|
460 |
+
x = self.enc(x, x_mask, g=g)
|
461 |
+
stats = self.proj(x) * x_mask
|
462 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
463 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
464 |
+
return z, m, logs, x_mask
|
465 |
+
|
466 |
+
|
467 |
+
class Generator(torch.nn.Module):
|
468 |
+
def __init__(
|
469 |
+
self,
|
470 |
+
initial_channel,
|
471 |
+
resblock,
|
472 |
+
resblock_kernel_sizes,
|
473 |
+
resblock_dilation_sizes,
|
474 |
+
upsample_rates,
|
475 |
+
upsample_initial_channel,
|
476 |
+
upsample_kernel_sizes,
|
477 |
+
gin_channels=0,
|
478 |
+
):
|
479 |
+
super(Generator, self).__init__()
|
480 |
+
self.num_kernels = len(resblock_kernel_sizes)
|
481 |
+
self.num_upsamples = len(upsample_rates)
|
482 |
+
self.conv_pre = Conv1d(
|
483 |
+
initial_channel, upsample_initial_channel, 7, 1, padding=3
|
484 |
+
)
|
485 |
+
resblock = modules.ResBlock1 if resblock == "1" else modules.ResBlock2
|
486 |
+
|
487 |
+
self.ups = nn.ModuleList()
|
488 |
+
for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):
|
489 |
+
self.ups.append(
|
490 |
+
weight_norm(
|
491 |
+
ConvTranspose1d(
|
492 |
+
upsample_initial_channel // (2**i),
|
493 |
+
upsample_initial_channel // (2 ** (i + 1)),
|
494 |
+
k,
|
495 |
+
u,
|
496 |
+
padding=(k - u) // 2,
|
497 |
+
)
|
498 |
+
)
|
499 |
+
)
|
500 |
+
|
501 |
+
self.resblocks = nn.ModuleList()
|
502 |
+
for i in range(len(self.ups)):
|
503 |
+
ch = upsample_initial_channel // (2 ** (i + 1))
|
504 |
+
for j, (k, d) in enumerate(
|
505 |
+
zip(resblock_kernel_sizes, resblock_dilation_sizes)
|
506 |
+
):
|
507 |
+
self.resblocks.append(resblock(ch, k, d))
|
508 |
+
|
509 |
+
self.conv_post = Conv1d(ch, 1, 7, 1, padding=3, bias=False)
|
510 |
+
self.ups.apply(init_weights)
|
511 |
+
|
512 |
+
if gin_channels != 0:
|
513 |
+
self.cond = nn.Conv1d(gin_channels, upsample_initial_channel, 1)
|
514 |
+
|
515 |
+
def forward(self, x, g=None):
|
516 |
+
x = self.conv_pre(x)
|
517 |
+
if g is not None:
|
518 |
+
x = x + self.cond(g)
|
519 |
+
|
520 |
+
for i in range(self.num_upsamples):
|
521 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
522 |
+
x = self.ups[i](x)
|
523 |
+
xs = None
|
524 |
+
for j in range(self.num_kernels):
|
525 |
+
if xs is None:
|
526 |
+
xs = self.resblocks[i * self.num_kernels + j](x)
|
527 |
+
else:
|
528 |
+
xs += self.resblocks[i * self.num_kernels + j](x)
|
529 |
+
x = xs / self.num_kernels
|
530 |
+
x = F.leaky_relu(x)
|
531 |
+
x = self.conv_post(x)
|
532 |
+
x = torch.tanh(x)
|
533 |
+
|
534 |
+
return x
|
535 |
+
|
536 |
+
def remove_weight_norm(self):
|
537 |
+
print("Removing weight norm...")
|
538 |
+
for layer in self.ups:
|
539 |
+
remove_weight_norm(layer)
|
540 |
+
for layer in self.resblocks:
|
541 |
+
layer.remove_weight_norm()
|
542 |
+
|
543 |
+
|
544 |
+
class DiscriminatorP(torch.nn.Module):
|
545 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
546 |
+
super(DiscriminatorP, self).__init__()
|
547 |
+
self.period = period
|
548 |
+
self.use_spectral_norm = use_spectral_norm
|
549 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
550 |
+
self.convs = nn.ModuleList(
|
551 |
+
[
|
552 |
+
norm_f(
|
553 |
+
Conv2d(
|
554 |
+
1,
|
555 |
+
32,
|
556 |
+
(kernel_size, 1),
|
557 |
+
(stride, 1),
|
558 |
+
padding=(get_padding(kernel_size, 1), 0),
|
559 |
+
)
|
560 |
+
),
|
561 |
+
norm_f(
|
562 |
+
Conv2d(
|
563 |
+
32,
|
564 |
+
128,
|
565 |
+
(kernel_size, 1),
|
566 |
+
(stride, 1),
|
567 |
+
padding=(get_padding(kernel_size, 1), 0),
|
568 |
+
)
|
569 |
+
),
|
570 |
+
norm_f(
|
571 |
+
Conv2d(
|
572 |
+
128,
|
573 |
+
512,
|
574 |
+
(kernel_size, 1),
|
575 |
+
(stride, 1),
|
576 |
+
padding=(get_padding(kernel_size, 1), 0),
|
577 |
+
)
|
578 |
+
),
|
579 |
+
norm_f(
|
580 |
+
Conv2d(
|
581 |
+
512,
|
582 |
+
1024,
|
583 |
+
(kernel_size, 1),
|
584 |
+
(stride, 1),
|
585 |
+
padding=(get_padding(kernel_size, 1), 0),
|
586 |
+
)
|
587 |
+
),
|
588 |
+
norm_f(
|
589 |
+
Conv2d(
|
590 |
+
1024,
|
591 |
+
1024,
|
592 |
+
(kernel_size, 1),
|
593 |
+
1,
|
594 |
+
padding=(get_padding(kernel_size, 1), 0),
|
595 |
+
)
|
596 |
+
),
|
597 |
+
]
|
598 |
+
)
|
599 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
600 |
+
|
601 |
+
def forward(self, x):
|
602 |
+
fmap = []
|
603 |
+
|
604 |
+
# 1d to 2d
|
605 |
+
b, c, t = x.shape
|
606 |
+
if t % self.period != 0: # pad first
|
607 |
+
n_pad = self.period - (t % self.period)
|
608 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
609 |
+
t = t + n_pad
|
610 |
+
x = x.view(b, c, t // self.period, self.period)
|
611 |
+
|
612 |
+
for layer in self.convs:
|
613 |
+
x = layer(x)
|
614 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
615 |
+
fmap.append(x)
|
616 |
+
x = self.conv_post(x)
|
617 |
+
fmap.append(x)
|
618 |
+
x = torch.flatten(x, 1, -1)
|
619 |
+
|
620 |
+
return x, fmap
|
621 |
+
|
622 |
+
|
623 |
+
class DiscriminatorS(torch.nn.Module):
|
624 |
+
def __init__(self, use_spectral_norm=False):
|
625 |
+
super(DiscriminatorS, self).__init__()
|
626 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
627 |
+
self.convs = nn.ModuleList(
|
628 |
+
[
|
629 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
630 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
631 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
632 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
633 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
634 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
635 |
+
]
|
636 |
+
)
|
637 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
638 |
+
|
639 |
+
def forward(self, x):
|
640 |
+
fmap = []
|
641 |
+
|
642 |
+
for layer in self.convs:
|
643 |
+
x = layer(x)
|
644 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
645 |
+
fmap.append(x)
|
646 |
+
x = self.conv_post(x)
|
647 |
+
fmap.append(x)
|
648 |
+
x = torch.flatten(x, 1, -1)
|
649 |
+
|
650 |
+
return x, fmap
|
651 |
+
|
652 |
+
|
653 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
654 |
+
def __init__(self, use_spectral_norm=False):
|
655 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
656 |
+
periods = [2, 3, 5, 7, 11]
|
657 |
+
|
658 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
659 |
+
discs = discs + [
|
660 |
+
DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods
|
661 |
+
]
|
662 |
+
self.discriminators = nn.ModuleList(discs)
|
663 |
+
|
664 |
+
def forward(self, y, y_hat):
|
665 |
+
y_d_rs = []
|
666 |
+
y_d_gs = []
|
667 |
+
fmap_rs = []
|
668 |
+
fmap_gs = []
|
669 |
+
for i, d in enumerate(self.discriminators):
|
670 |
+
y_d_r, fmap_r = d(y)
|
671 |
+
y_d_g, fmap_g = d(y_hat)
|
672 |
+
y_d_rs.append(y_d_r)
|
673 |
+
y_d_gs.append(y_d_g)
|
674 |
+
fmap_rs.append(fmap_r)
|
675 |
+
fmap_gs.append(fmap_g)
|
676 |
+
|
677 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
678 |
+
|
679 |
+
|
680 |
+
class ReferenceEncoder(nn.Module):
|
681 |
+
"""
|
682 |
+
inputs --- [N, Ty/r, n_mels*r] mels
|
683 |
+
outputs --- [N, ref_enc_gru_size]
|
684 |
+
"""
|
685 |
+
|
686 |
+
def __init__(self, spec_channels, gin_channels=0):
|
687 |
+
super().__init__()
|
688 |
+
self.spec_channels = spec_channels
|
689 |
+
ref_enc_filters = [32, 32, 64, 64, 128, 128]
|
690 |
+
K = len(ref_enc_filters)
|
691 |
+
filters = [1] + ref_enc_filters
|
692 |
+
convs = [
|
693 |
+
weight_norm(
|
694 |
+
nn.Conv2d(
|
695 |
+
in_channels=filters[i],
|
696 |
+
out_channels=filters[i + 1],
|
697 |
+
kernel_size=(3, 3),
|
698 |
+
stride=(2, 2),
|
699 |
+
padding=(1, 1),
|
700 |
+
)
|
701 |
+
)
|
702 |
+
for i in range(K)
|
703 |
+
]
|
704 |
+
self.convs = nn.ModuleList(convs)
|
705 |
+
# self.wns = nn.ModuleList([weight_norm(num_features=ref_enc_filters[i]) for i in range(K)]) # noqa: E501
|
706 |
+
|
707 |
+
out_channels = self.calculate_channels(spec_channels, 3, 2, 1, K)
|
708 |
+
self.gru = nn.GRU(
|
709 |
+
input_size=ref_enc_filters[-1] * out_channels,
|
710 |
+
hidden_size=256 // 2,
|
711 |
+
batch_first=True,
|
712 |
+
)
|
713 |
+
self.proj = nn.Linear(128, gin_channels)
|
714 |
+
|
715 |
+
def forward(self, inputs, mask=None):
|
716 |
+
N = inputs.size(0)
|
717 |
+
out = inputs.view(N, 1, -1, self.spec_channels) # [N, 1, Ty, n_freqs]
|
718 |
+
for conv in self.convs:
|
719 |
+
out = conv(out)
|
720 |
+
# out = wn(out)
|
721 |
+
out = F.relu(out) # [N, 128, Ty//2^K, n_mels//2^K]
|
722 |
+
|
723 |
+
out = out.transpose(1, 2) # [N, Ty//2^K, 128, n_mels//2^K]
|
724 |
+
T = out.size(1)
|
725 |
+
N = out.size(0)
|
726 |
+
out = out.contiguous().view(N, T, -1) # [N, Ty//2^K, 128*n_mels//2^K]
|
727 |
+
|
728 |
+
self.gru.flatten_parameters()
|
729 |
+
memory, out = self.gru(out) # out --- [1, N, 128]
|
730 |
+
|
731 |
+
return self.proj(out.squeeze(0))
|
732 |
+
|
733 |
+
def calculate_channels(self, L, kernel_size, stride, pad, n_convs):
|
734 |
+
for i in range(n_convs):
|
735 |
+
L = (L - kernel_size + 2 * pad) // stride + 1
|
736 |
+
return L
|
737 |
+
|
738 |
+
|
739 |
+
class SynthesizerTrn(nn.Module):
|
740 |
+
"""
|
741 |
+
Synthesizer for Training
|
742 |
+
"""
|
743 |
+
|
744 |
+
def __init__(
|
745 |
+
self,
|
746 |
+
n_vocab,
|
747 |
+
spec_channels,
|
748 |
+
segment_size,
|
749 |
+
inter_channels,
|
750 |
+
hidden_channels,
|
751 |
+
filter_channels,
|
752 |
+
n_heads,
|
753 |
+
n_layers,
|
754 |
+
kernel_size,
|
755 |
+
p_dropout,
|
756 |
+
resblock,
|
757 |
+
resblock_kernel_sizes,
|
758 |
+
resblock_dilation_sizes,
|
759 |
+
upsample_rates,
|
760 |
+
upsample_initial_channel,
|
761 |
+
upsample_kernel_sizes,
|
762 |
+
n_speakers=256,
|
763 |
+
gin_channels=256,
|
764 |
+
use_sdp=True,
|
765 |
+
n_flow_layer=4,
|
766 |
+
n_layers_trans_flow=6,
|
767 |
+
flow_share_parameter=False,
|
768 |
+
use_transformer_flow=True,
|
769 |
+
**kwargs
|
770 |
+
):
|
771 |
+
super().__init__()
|
772 |
+
self.n_vocab = n_vocab
|
773 |
+
self.spec_channels = spec_channels
|
774 |
+
self.inter_channels = inter_channels
|
775 |
+
self.hidden_channels = hidden_channels
|
776 |
+
self.filter_channels = filter_channels
|
777 |
+
self.n_heads = n_heads
|
778 |
+
self.n_layers = n_layers
|
779 |
+
self.kernel_size = kernel_size
|
780 |
+
self.p_dropout = p_dropout
|
781 |
+
self.resblock = resblock
|
782 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
783 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
784 |
+
self.upsample_rates = upsample_rates
|
785 |
+
self.upsample_initial_channel = upsample_initial_channel
|
786 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
787 |
+
self.segment_size = segment_size
|
788 |
+
self.n_speakers = n_speakers
|
789 |
+
self.gin_channels = gin_channels
|
790 |
+
self.n_layers_trans_flow = n_layers_trans_flow
|
791 |
+
self.use_spk_conditioned_encoder = kwargs.get(
|
792 |
+
"use_spk_conditioned_encoder", True
|
793 |
+
)
|
794 |
+
self.use_sdp = use_sdp
|
795 |
+
self.use_noise_scaled_mas = kwargs.get("use_noise_scaled_mas", False)
|
796 |
+
self.mas_noise_scale_initial = kwargs.get("mas_noise_scale_initial", 0.01)
|
797 |
+
self.noise_scale_delta = kwargs.get("noise_scale_delta", 2e-6)
|
798 |
+
self.current_mas_noise_scale = self.mas_noise_scale_initial
|
799 |
+
if self.use_spk_conditioned_encoder and gin_channels > 0:
|
800 |
+
self.enc_gin_channels = gin_channels
|
801 |
+
self.enc_p = TextEncoder(
|
802 |
+
n_vocab,
|
803 |
+
inter_channels,
|
804 |
+
hidden_channels,
|
805 |
+
filter_channels,
|
806 |
+
n_heads,
|
807 |
+
n_layers,
|
808 |
+
kernel_size,
|
809 |
+
p_dropout,
|
810 |
+
gin_channels=self.enc_gin_channels,
|
811 |
+
)
|
812 |
+
self.dec = Generator(
|
813 |
+
inter_channels,
|
814 |
+
resblock,
|
815 |
+
resblock_kernel_sizes,
|
816 |
+
resblock_dilation_sizes,
|
817 |
+
upsample_rates,
|
818 |
+
upsample_initial_channel,
|
819 |
+
upsample_kernel_sizes,
|
820 |
+
gin_channels=gin_channels,
|
821 |
+
)
|
822 |
+
self.enc_q = PosteriorEncoder(
|
823 |
+
spec_channels,
|
824 |
+
inter_channels,
|
825 |
+
hidden_channels,
|
826 |
+
5,
|
827 |
+
1,
|
828 |
+
16,
|
829 |
+
gin_channels=gin_channels,
|
830 |
+
)
|
831 |
+
if use_transformer_flow:
|
832 |
+
self.flow = TransformerCouplingBlock(
|
833 |
+
inter_channels,
|
834 |
+
hidden_channels,
|
835 |
+
filter_channels,
|
836 |
+
n_heads,
|
837 |
+
n_layers_trans_flow,
|
838 |
+
5,
|
839 |
+
p_dropout,
|
840 |
+
n_flow_layer,
|
841 |
+
gin_channels=gin_channels,
|
842 |
+
share_parameter=flow_share_parameter,
|
843 |
+
)
|
844 |
+
else:
|
845 |
+
self.flow = ResidualCouplingBlock(
|
846 |
+
inter_channels,
|
847 |
+
hidden_channels,
|
848 |
+
5,
|
849 |
+
1,
|
850 |
+
n_flow_layer,
|
851 |
+
gin_channels=gin_channels,
|
852 |
+
)
|
853 |
+
self.sdp = StochasticDurationPredictor(
|
854 |
+
hidden_channels, 192, 3, 0.5, 4, gin_channels=gin_channels
|
855 |
+
)
|
856 |
+
self.dp = DurationPredictor(
|
857 |
+
hidden_channels, 256, 3, 0.5, gin_channels=gin_channels
|
858 |
+
)
|
859 |
+
|
860 |
+
if n_speakers > 1:
|
861 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
862 |
+
else:
|
863 |
+
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
864 |
+
|
865 |
+
def forward(self, x, x_lengths, y, y_lengths, sid, tone, language, bert, ja_bert):
|
866 |
+
if self.n_speakers > 0:
|
867 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
868 |
+
else:
|
869 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
870 |
+
x, m_p, logs_p, x_mask = self.enc_p(
|
871 |
+
x, x_lengths, tone, language, bert, ja_bert, g=g
|
872 |
+
)
|
873 |
+
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
874 |
+
z_p = self.flow(z, y_mask, g=g)
|
875 |
+
|
876 |
+
with torch.no_grad():
|
877 |
+
# negative cross-entropy
|
878 |
+
s_p_sq_r = torch.exp(-2 * logs_p) # [b, d, t]
|
879 |
+
neg_cent1 = torch.sum(
|
880 |
+
-0.5 * math.log(2 * math.pi) - logs_p, [1], keepdim=True
|
881 |
+
) # [b, 1, t_s]
|
882 |
+
neg_cent2 = torch.matmul(
|
883 |
+
-0.5 * (z_p**2).transpose(1, 2), s_p_sq_r
|
884 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
885 |
+
neg_cent3 = torch.matmul(
|
886 |
+
z_p.transpose(1, 2), (m_p * s_p_sq_r)
|
887 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
888 |
+
neg_cent4 = torch.sum(
|
889 |
+
-0.5 * (m_p**2) * s_p_sq_r, [1], keepdim=True
|
890 |
+
) # [b, 1, t_s]
|
891 |
+
neg_cent = neg_cent1 + neg_cent2 + neg_cent3 + neg_cent4
|
892 |
+
if self.use_noise_scaled_mas:
|
893 |
+
epsilon = (
|
894 |
+
torch.std(neg_cent)
|
895 |
+
* torch.randn_like(neg_cent)
|
896 |
+
* self.current_mas_noise_scale
|
897 |
+
)
|
898 |
+
neg_cent = neg_cent + epsilon
|
899 |
+
|
900 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
901 |
+
attn = (
|
902 |
+
monotonic_align.maximum_path(neg_cent, attn_mask.squeeze(1))
|
903 |
+
.unsqueeze(1)
|
904 |
+
.detach()
|
905 |
+
)
|
906 |
+
|
907 |
+
w = attn.sum(2)
|
908 |
+
|
909 |
+
l_length_sdp = self.sdp(x, x_mask, w, g=g)
|
910 |
+
l_length_sdp = l_length_sdp / torch.sum(x_mask)
|
911 |
+
|
912 |
+
logw_ = torch.log(w + 1e-6) * x_mask
|
913 |
+
logw = self.dp(x, x_mask, g=g)
|
914 |
+
l_length_dp = torch.sum((logw - logw_) ** 2, [1, 2]) / torch.sum(
|
915 |
+
x_mask
|
916 |
+
) # for averaging
|
917 |
+
|
918 |
+
l_length = l_length_dp + l_length_sdp
|
919 |
+
|
920 |
+
# expand prior
|
921 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(1, 2)
|
922 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(1, 2)
|
923 |
+
|
924 |
+
z_slice, ids_slice = commons.rand_slice_segments(
|
925 |
+
z, y_lengths, self.segment_size
|
926 |
+
)
|
927 |
+
o = self.dec(z_slice, g=g)
|
928 |
+
return (
|
929 |
+
o,
|
930 |
+
l_length,
|
931 |
+
attn,
|
932 |
+
ids_slice,
|
933 |
+
x_mask,
|
934 |
+
y_mask,
|
935 |
+
(z, z_p, m_p, logs_p, m_q, logs_q),
|
936 |
+
(x, logw, logw_),
|
937 |
+
)
|
938 |
+
|
939 |
+
def infer(
|
940 |
+
self,
|
941 |
+
x,
|
942 |
+
x_lengths,
|
943 |
+
sid,
|
944 |
+
tone,
|
945 |
+
language,
|
946 |
+
bert,
|
947 |
+
ja_bert,
|
948 |
+
noise_scale=0.667,
|
949 |
+
length_scale=1,
|
950 |
+
noise_scale_w=0.8,
|
951 |
+
max_len=None,
|
952 |
+
sdp_ratio=0,
|
953 |
+
y=None,
|
954 |
+
):
|
955 |
+
# x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert)
|
956 |
+
# g = self.gst(y)
|
957 |
+
if self.n_speakers > 0:
|
958 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
959 |
+
else:
|
960 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
961 |
+
x, m_p, logs_p, x_mask = self.enc_p(
|
962 |
+
x, x_lengths, tone, language, bert, ja_bert, g=g
|
963 |
+
)
|
964 |
+
logw = self.sdp(x, x_mask, g=g, reverse=True, noise_scale=noise_scale_w) * (
|
965 |
+
sdp_ratio
|
966 |
+
) + self.dp(x, x_mask, g=g) * (1 - sdp_ratio)
|
967 |
+
w = torch.exp(logw) * x_mask * length_scale
|
968 |
+
w_ceil = torch.ceil(w)
|
969 |
+
y_lengths = torch.clamp_min(torch.sum(w_ceil, [1, 2]), 1).long()
|
970 |
+
y_mask = torch.unsqueeze(commons.sequence_mask(y_lengths, None), 1).to(
|
971 |
+
x_mask.dtype
|
972 |
+
)
|
973 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
974 |
+
attn = commons.generate_path(w_ceil, attn_mask)
|
975 |
+
|
976 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(
|
977 |
+
1, 2
|
978 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
979 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(
|
980 |
+
1, 2
|
981 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
982 |
+
|
983 |
+
z_p = m_p + torch.randn_like(m_p) * torch.exp(logs_p) * noise_scale
|
984 |
+
z = self.flow(z_p, y_mask, g=g, reverse=True)
|
985 |
+
o = self.dec((z * y_mask)[:, :, :max_len], g=g)
|
986 |
+
return o, attn, y_mask, (z, z_p, m_p, logs_p)
|
modules.py
ADDED
@@ -0,0 +1,597 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
from torch.nn import Conv1d
|
7 |
+
from torch.nn.utils import weight_norm, remove_weight_norm
|
8 |
+
|
9 |
+
import commons
|
10 |
+
from commons import init_weights, get_padding
|
11 |
+
from transforms import piecewise_rational_quadratic_transform
|
12 |
+
from attentions import Encoder
|
13 |
+
|
14 |
+
LRELU_SLOPE = 0.1
|
15 |
+
|
16 |
+
|
17 |
+
class LayerNorm(nn.Module):
|
18 |
+
def __init__(self, channels, eps=1e-5):
|
19 |
+
super().__init__()
|
20 |
+
self.channels = channels
|
21 |
+
self.eps = eps
|
22 |
+
|
23 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
24 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
25 |
+
|
26 |
+
def forward(self, x):
|
27 |
+
x = x.transpose(1, -1)
|
28 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
29 |
+
return x.transpose(1, -1)
|
30 |
+
|
31 |
+
|
32 |
+
class ConvReluNorm(nn.Module):
|
33 |
+
def __init__(
|
34 |
+
self,
|
35 |
+
in_channels,
|
36 |
+
hidden_channels,
|
37 |
+
out_channels,
|
38 |
+
kernel_size,
|
39 |
+
n_layers,
|
40 |
+
p_dropout,
|
41 |
+
):
|
42 |
+
super().__init__()
|
43 |
+
self.in_channels = in_channels
|
44 |
+
self.hidden_channels = hidden_channels
|
45 |
+
self.out_channels = out_channels
|
46 |
+
self.kernel_size = kernel_size
|
47 |
+
self.n_layers = n_layers
|
48 |
+
self.p_dropout = p_dropout
|
49 |
+
assert n_layers > 1, "Number of layers should be larger than 0."
|
50 |
+
|
51 |
+
self.conv_layers = nn.ModuleList()
|
52 |
+
self.norm_layers = nn.ModuleList()
|
53 |
+
self.conv_layers.append(
|
54 |
+
nn.Conv1d(
|
55 |
+
in_channels, hidden_channels, kernel_size, padding=kernel_size // 2
|
56 |
+
)
|
57 |
+
)
|
58 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
59 |
+
self.relu_drop = nn.Sequential(nn.ReLU(), nn.Dropout(p_dropout))
|
60 |
+
for _ in range(n_layers - 1):
|
61 |
+
self.conv_layers.append(
|
62 |
+
nn.Conv1d(
|
63 |
+
hidden_channels,
|
64 |
+
hidden_channels,
|
65 |
+
kernel_size,
|
66 |
+
padding=kernel_size // 2,
|
67 |
+
)
|
68 |
+
)
|
69 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
70 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
71 |
+
self.proj.weight.data.zero_()
|
72 |
+
self.proj.bias.data.zero_()
|
73 |
+
|
74 |
+
def forward(self, x, x_mask):
|
75 |
+
x_org = x
|
76 |
+
for i in range(self.n_layers):
|
77 |
+
x = self.conv_layers[i](x * x_mask)
|
78 |
+
x = self.norm_layers[i](x)
|
79 |
+
x = self.relu_drop(x)
|
80 |
+
x = x_org + self.proj(x)
|
81 |
+
return x * x_mask
|
82 |
+
|
83 |
+
|
84 |
+
class DDSConv(nn.Module):
|
85 |
+
"""
|
86 |
+
Dialted and Depth-Separable Convolution
|
87 |
+
"""
|
88 |
+
|
89 |
+
def __init__(self, channels, kernel_size, n_layers, p_dropout=0.0):
|
90 |
+
super().__init__()
|
91 |
+
self.channels = channels
|
92 |
+
self.kernel_size = kernel_size
|
93 |
+
self.n_layers = n_layers
|
94 |
+
self.p_dropout = p_dropout
|
95 |
+
|
96 |
+
self.drop = nn.Dropout(p_dropout)
|
97 |
+
self.convs_sep = nn.ModuleList()
|
98 |
+
self.convs_1x1 = nn.ModuleList()
|
99 |
+
self.norms_1 = nn.ModuleList()
|
100 |
+
self.norms_2 = nn.ModuleList()
|
101 |
+
for i in range(n_layers):
|
102 |
+
dilation = kernel_size**i
|
103 |
+
padding = (kernel_size * dilation - dilation) // 2
|
104 |
+
self.convs_sep.append(
|
105 |
+
nn.Conv1d(
|
106 |
+
channels,
|
107 |
+
channels,
|
108 |
+
kernel_size,
|
109 |
+
groups=channels,
|
110 |
+
dilation=dilation,
|
111 |
+
padding=padding,
|
112 |
+
)
|
113 |
+
)
|
114 |
+
self.convs_1x1.append(nn.Conv1d(channels, channels, 1))
|
115 |
+
self.norms_1.append(LayerNorm(channels))
|
116 |
+
self.norms_2.append(LayerNorm(channels))
|
117 |
+
|
118 |
+
def forward(self, x, x_mask, g=None):
|
119 |
+
if g is not None:
|
120 |
+
x = x + g
|
121 |
+
for i in range(self.n_layers):
|
122 |
+
y = self.convs_sep[i](x * x_mask)
|
123 |
+
y = self.norms_1[i](y)
|
124 |
+
y = F.gelu(y)
|
125 |
+
y = self.convs_1x1[i](y)
|
126 |
+
y = self.norms_2[i](y)
|
127 |
+
y = F.gelu(y)
|
128 |
+
y = self.drop(y)
|
129 |
+
x = x + y
|
130 |
+
return x * x_mask
|
131 |
+
|
132 |
+
|
133 |
+
class WN(torch.nn.Module):
|
134 |
+
def __init__(
|
135 |
+
self,
|
136 |
+
hidden_channels,
|
137 |
+
kernel_size,
|
138 |
+
dilation_rate,
|
139 |
+
n_layers,
|
140 |
+
gin_channels=0,
|
141 |
+
p_dropout=0,
|
142 |
+
):
|
143 |
+
super(WN, self).__init__()
|
144 |
+
assert kernel_size % 2 == 1
|
145 |
+
self.hidden_channels = hidden_channels
|
146 |
+
self.kernel_size = (kernel_size,)
|
147 |
+
self.dilation_rate = dilation_rate
|
148 |
+
self.n_layers = n_layers
|
149 |
+
self.gin_channels = gin_channels
|
150 |
+
self.p_dropout = p_dropout
|
151 |
+
|
152 |
+
self.in_layers = torch.nn.ModuleList()
|
153 |
+
self.res_skip_layers = torch.nn.ModuleList()
|
154 |
+
self.drop = nn.Dropout(p_dropout)
|
155 |
+
|
156 |
+
if gin_channels != 0:
|
157 |
+
cond_layer = torch.nn.Conv1d(
|
158 |
+
gin_channels, 2 * hidden_channels * n_layers, 1
|
159 |
+
)
|
160 |
+
self.cond_layer = torch.nn.utils.weight_norm(cond_layer, name="weight")
|
161 |
+
|
162 |
+
for i in range(n_layers):
|
163 |
+
dilation = dilation_rate**i
|
164 |
+
padding = int((kernel_size * dilation - dilation) / 2)
|
165 |
+
in_layer = torch.nn.Conv1d(
|
166 |
+
hidden_channels,
|
167 |
+
2 * hidden_channels,
|
168 |
+
kernel_size,
|
169 |
+
dilation=dilation,
|
170 |
+
padding=padding,
|
171 |
+
)
|
172 |
+
in_layer = torch.nn.utils.weight_norm(in_layer, name="weight")
|
173 |
+
self.in_layers.append(in_layer)
|
174 |
+
|
175 |
+
# last one is not necessary
|
176 |
+
if i < n_layers - 1:
|
177 |
+
res_skip_channels = 2 * hidden_channels
|
178 |
+
else:
|
179 |
+
res_skip_channels = hidden_channels
|
180 |
+
|
181 |
+
res_skip_layer = torch.nn.Conv1d(hidden_channels, res_skip_channels, 1)
|
182 |
+
res_skip_layer = torch.nn.utils.weight_norm(res_skip_layer, name="weight")
|
183 |
+
self.res_skip_layers.append(res_skip_layer)
|
184 |
+
|
185 |
+
def forward(self, x, x_mask, g=None, **kwargs):
|
186 |
+
output = torch.zeros_like(x)
|
187 |
+
n_channels_tensor = torch.IntTensor([self.hidden_channels])
|
188 |
+
|
189 |
+
if g is not None:
|
190 |
+
g = self.cond_layer(g)
|
191 |
+
|
192 |
+
for i in range(self.n_layers):
|
193 |
+
x_in = self.in_layers[i](x)
|
194 |
+
if g is not None:
|
195 |
+
cond_offset = i * 2 * self.hidden_channels
|
196 |
+
g_l = g[:, cond_offset : cond_offset + 2 * self.hidden_channels, :]
|
197 |
+
else:
|
198 |
+
g_l = torch.zeros_like(x_in)
|
199 |
+
|
200 |
+
acts = commons.fused_add_tanh_sigmoid_multiply(x_in, g_l, n_channels_tensor)
|
201 |
+
acts = self.drop(acts)
|
202 |
+
|
203 |
+
res_skip_acts = self.res_skip_layers[i](acts)
|
204 |
+
if i < self.n_layers - 1:
|
205 |
+
res_acts = res_skip_acts[:, : self.hidden_channels, :]
|
206 |
+
x = (x + res_acts) * x_mask
|
207 |
+
output = output + res_skip_acts[:, self.hidden_channels :, :]
|
208 |
+
else:
|
209 |
+
output = output + res_skip_acts
|
210 |
+
return output * x_mask
|
211 |
+
|
212 |
+
def remove_weight_norm(self):
|
213 |
+
if self.gin_channels != 0:
|
214 |
+
torch.nn.utils.remove_weight_norm(self.cond_layer)
|
215 |
+
for l in self.in_layers:
|
216 |
+
torch.nn.utils.remove_weight_norm(l)
|
217 |
+
for l in self.res_skip_layers:
|
218 |
+
torch.nn.utils.remove_weight_norm(l)
|
219 |
+
|
220 |
+
|
221 |
+
class ResBlock1(torch.nn.Module):
|
222 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):
|
223 |
+
super(ResBlock1, self).__init__()
|
224 |
+
self.convs1 = nn.ModuleList(
|
225 |
+
[
|
226 |
+
weight_norm(
|
227 |
+
Conv1d(
|
228 |
+
channels,
|
229 |
+
channels,
|
230 |
+
kernel_size,
|
231 |
+
1,
|
232 |
+
dilation=dilation[0],
|
233 |
+
padding=get_padding(kernel_size, dilation[0]),
|
234 |
+
)
|
235 |
+
),
|
236 |
+
weight_norm(
|
237 |
+
Conv1d(
|
238 |
+
channels,
|
239 |
+
channels,
|
240 |
+
kernel_size,
|
241 |
+
1,
|
242 |
+
dilation=dilation[1],
|
243 |
+
padding=get_padding(kernel_size, dilation[1]),
|
244 |
+
)
|
245 |
+
),
|
246 |
+
weight_norm(
|
247 |
+
Conv1d(
|
248 |
+
channels,
|
249 |
+
channels,
|
250 |
+
kernel_size,
|
251 |
+
1,
|
252 |
+
dilation=dilation[2],
|
253 |
+
padding=get_padding(kernel_size, dilation[2]),
|
254 |
+
)
|
255 |
+
),
|
256 |
+
]
|
257 |
+
)
|
258 |
+
self.convs1.apply(init_weights)
|
259 |
+
|
260 |
+
self.convs2 = nn.ModuleList(
|
261 |
+
[
|
262 |
+
weight_norm(
|
263 |
+
Conv1d(
|
264 |
+
channels,
|
265 |
+
channels,
|
266 |
+
kernel_size,
|
267 |
+
1,
|
268 |
+
dilation=1,
|
269 |
+
padding=get_padding(kernel_size, 1),
|
270 |
+
)
|
271 |
+
),
|
272 |
+
weight_norm(
|
273 |
+
Conv1d(
|
274 |
+
channels,
|
275 |
+
channels,
|
276 |
+
kernel_size,
|
277 |
+
1,
|
278 |
+
dilation=1,
|
279 |
+
padding=get_padding(kernel_size, 1),
|
280 |
+
)
|
281 |
+
),
|
282 |
+
weight_norm(
|
283 |
+
Conv1d(
|
284 |
+
channels,
|
285 |
+
channels,
|
286 |
+
kernel_size,
|
287 |
+
1,
|
288 |
+
dilation=1,
|
289 |
+
padding=get_padding(kernel_size, 1),
|
290 |
+
)
|
291 |
+
),
|
292 |
+
]
|
293 |
+
)
|
294 |
+
self.convs2.apply(init_weights)
|
295 |
+
|
296 |
+
def forward(self, x, x_mask=None):
|
297 |
+
for c1, c2 in zip(self.convs1, self.convs2):
|
298 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
299 |
+
if x_mask is not None:
|
300 |
+
xt = xt * x_mask
|
301 |
+
xt = c1(xt)
|
302 |
+
xt = F.leaky_relu(xt, LRELU_SLOPE)
|
303 |
+
if x_mask is not None:
|
304 |
+
xt = xt * x_mask
|
305 |
+
xt = c2(xt)
|
306 |
+
x = xt + x
|
307 |
+
if x_mask is not None:
|
308 |
+
x = x * x_mask
|
309 |
+
return x
|
310 |
+
|
311 |
+
def remove_weight_norm(self):
|
312 |
+
for l in self.convs1:
|
313 |
+
remove_weight_norm(l)
|
314 |
+
for l in self.convs2:
|
315 |
+
remove_weight_norm(l)
|
316 |
+
|
317 |
+
|
318 |
+
class ResBlock2(torch.nn.Module):
|
319 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3)):
|
320 |
+
super(ResBlock2, self).__init__()
|
321 |
+
self.convs = nn.ModuleList(
|
322 |
+
[
|
323 |
+
weight_norm(
|
324 |
+
Conv1d(
|
325 |
+
channels,
|
326 |
+
channels,
|
327 |
+
kernel_size,
|
328 |
+
1,
|
329 |
+
dilation=dilation[0],
|
330 |
+
padding=get_padding(kernel_size, dilation[0]),
|
331 |
+
)
|
332 |
+
),
|
333 |
+
weight_norm(
|
334 |
+
Conv1d(
|
335 |
+
channels,
|
336 |
+
channels,
|
337 |
+
kernel_size,
|
338 |
+
1,
|
339 |
+
dilation=dilation[1],
|
340 |
+
padding=get_padding(kernel_size, dilation[1]),
|
341 |
+
)
|
342 |
+
),
|
343 |
+
]
|
344 |
+
)
|
345 |
+
self.convs.apply(init_weights)
|
346 |
+
|
347 |
+
def forward(self, x, x_mask=None):
|
348 |
+
for c in self.convs:
|
349 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
350 |
+
if x_mask is not None:
|
351 |
+
xt = xt * x_mask
|
352 |
+
xt = c(xt)
|
353 |
+
x = xt + x
|
354 |
+
if x_mask is not None:
|
355 |
+
x = x * x_mask
|
356 |
+
return x
|
357 |
+
|
358 |
+
def remove_weight_norm(self):
|
359 |
+
for l in self.convs:
|
360 |
+
remove_weight_norm(l)
|
361 |
+
|
362 |
+
|
363 |
+
class Log(nn.Module):
|
364 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
365 |
+
if not reverse:
|
366 |
+
y = torch.log(torch.clamp_min(x, 1e-5)) * x_mask
|
367 |
+
logdet = torch.sum(-y, [1, 2])
|
368 |
+
return y, logdet
|
369 |
+
else:
|
370 |
+
x = torch.exp(x) * x_mask
|
371 |
+
return x
|
372 |
+
|
373 |
+
|
374 |
+
class Flip(nn.Module):
|
375 |
+
def forward(self, x, *args, reverse=False, **kwargs):
|
376 |
+
x = torch.flip(x, [1])
|
377 |
+
if not reverse:
|
378 |
+
logdet = torch.zeros(x.size(0)).to(dtype=x.dtype, device=x.device)
|
379 |
+
return x, logdet
|
380 |
+
else:
|
381 |
+
return x
|
382 |
+
|
383 |
+
|
384 |
+
class ElementwiseAffine(nn.Module):
|
385 |
+
def __init__(self, channels):
|
386 |
+
super().__init__()
|
387 |
+
self.channels = channels
|
388 |
+
self.m = nn.Parameter(torch.zeros(channels, 1))
|
389 |
+
self.logs = nn.Parameter(torch.zeros(channels, 1))
|
390 |
+
|
391 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
392 |
+
if not reverse:
|
393 |
+
y = self.m + torch.exp(self.logs) * x
|
394 |
+
y = y * x_mask
|
395 |
+
logdet = torch.sum(self.logs * x_mask, [1, 2])
|
396 |
+
return y, logdet
|
397 |
+
else:
|
398 |
+
x = (x - self.m) * torch.exp(-self.logs) * x_mask
|
399 |
+
return x
|
400 |
+
|
401 |
+
|
402 |
+
class ResidualCouplingLayer(nn.Module):
|
403 |
+
def __init__(
|
404 |
+
self,
|
405 |
+
channels,
|
406 |
+
hidden_channels,
|
407 |
+
kernel_size,
|
408 |
+
dilation_rate,
|
409 |
+
n_layers,
|
410 |
+
p_dropout=0,
|
411 |
+
gin_channels=0,
|
412 |
+
mean_only=False,
|
413 |
+
):
|
414 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
415 |
+
super().__init__()
|
416 |
+
self.channels = channels
|
417 |
+
self.hidden_channels = hidden_channels
|
418 |
+
self.kernel_size = kernel_size
|
419 |
+
self.dilation_rate = dilation_rate
|
420 |
+
self.n_layers = n_layers
|
421 |
+
self.half_channels = channels // 2
|
422 |
+
self.mean_only = mean_only
|
423 |
+
|
424 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
425 |
+
self.enc = WN(
|
426 |
+
hidden_channels,
|
427 |
+
kernel_size,
|
428 |
+
dilation_rate,
|
429 |
+
n_layers,
|
430 |
+
p_dropout=p_dropout,
|
431 |
+
gin_channels=gin_channels,
|
432 |
+
)
|
433 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
434 |
+
self.post.weight.data.zero_()
|
435 |
+
self.post.bias.data.zero_()
|
436 |
+
|
437 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
438 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
439 |
+
h = self.pre(x0) * x_mask
|
440 |
+
h = self.enc(h, x_mask, g=g)
|
441 |
+
stats = self.post(h) * x_mask
|
442 |
+
if not self.mean_only:
|
443 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
444 |
+
else:
|
445 |
+
m = stats
|
446 |
+
logs = torch.zeros_like(m)
|
447 |
+
|
448 |
+
if not reverse:
|
449 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
450 |
+
x = torch.cat([x0, x1], 1)
|
451 |
+
logdet = torch.sum(logs, [1, 2])
|
452 |
+
return x, logdet
|
453 |
+
else:
|
454 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
455 |
+
x = torch.cat([x0, x1], 1)
|
456 |
+
return x
|
457 |
+
|
458 |
+
|
459 |
+
class ConvFlow(nn.Module):
|
460 |
+
def __init__(
|
461 |
+
self,
|
462 |
+
in_channels,
|
463 |
+
filter_channels,
|
464 |
+
kernel_size,
|
465 |
+
n_layers,
|
466 |
+
num_bins=10,
|
467 |
+
tail_bound=5.0,
|
468 |
+
):
|
469 |
+
super().__init__()
|
470 |
+
self.in_channels = in_channels
|
471 |
+
self.filter_channels = filter_channels
|
472 |
+
self.kernel_size = kernel_size
|
473 |
+
self.n_layers = n_layers
|
474 |
+
self.num_bins = num_bins
|
475 |
+
self.tail_bound = tail_bound
|
476 |
+
self.half_channels = in_channels // 2
|
477 |
+
|
478 |
+
self.pre = nn.Conv1d(self.half_channels, filter_channels, 1)
|
479 |
+
self.convs = DDSConv(filter_channels, kernel_size, n_layers, p_dropout=0.0)
|
480 |
+
self.proj = nn.Conv1d(
|
481 |
+
filter_channels, self.half_channels * (num_bins * 3 - 1), 1
|
482 |
+
)
|
483 |
+
self.proj.weight.data.zero_()
|
484 |
+
self.proj.bias.data.zero_()
|
485 |
+
|
486 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
487 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
488 |
+
h = self.pre(x0)
|
489 |
+
h = self.convs(h, x_mask, g=g)
|
490 |
+
h = self.proj(h) * x_mask
|
491 |
+
|
492 |
+
b, c, t = x0.shape
|
493 |
+
h = h.reshape(b, c, -1, t).permute(0, 1, 3, 2) # [b, cx?, t] -> [b, c, t, ?]
|
494 |
+
|
495 |
+
unnormalized_widths = h[..., : self.num_bins] / math.sqrt(self.filter_channels)
|
496 |
+
unnormalized_heights = h[..., self.num_bins : 2 * self.num_bins] / math.sqrt(
|
497 |
+
self.filter_channels
|
498 |
+
)
|
499 |
+
unnormalized_derivatives = h[..., 2 * self.num_bins :]
|
500 |
+
|
501 |
+
x1, logabsdet = piecewise_rational_quadratic_transform(
|
502 |
+
x1,
|
503 |
+
unnormalized_widths,
|
504 |
+
unnormalized_heights,
|
505 |
+
unnormalized_derivatives,
|
506 |
+
inverse=reverse,
|
507 |
+
tails="linear",
|
508 |
+
tail_bound=self.tail_bound,
|
509 |
+
)
|
510 |
+
|
511 |
+
x = torch.cat([x0, x1], 1) * x_mask
|
512 |
+
logdet = torch.sum(logabsdet * x_mask, [1, 2])
|
513 |
+
if not reverse:
|
514 |
+
return x, logdet
|
515 |
+
else:
|
516 |
+
return x
|
517 |
+
|
518 |
+
|
519 |
+
class TransformerCouplingLayer(nn.Module):
|
520 |
+
def __init__(
|
521 |
+
self,
|
522 |
+
channels,
|
523 |
+
hidden_channels,
|
524 |
+
kernel_size,
|
525 |
+
n_layers,
|
526 |
+
n_heads,
|
527 |
+
p_dropout=0,
|
528 |
+
filter_channels=0,
|
529 |
+
mean_only=False,
|
530 |
+
wn_sharing_parameter=None,
|
531 |
+
gin_channels=0,
|
532 |
+
):
|
533 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
534 |
+
super().__init__()
|
535 |
+
self.channels = channels
|
536 |
+
self.hidden_channels = hidden_channels
|
537 |
+
self.kernel_size = kernel_size
|
538 |
+
self.n_layers = n_layers
|
539 |
+
self.half_channels = channels // 2
|
540 |
+
self.mean_only = mean_only
|
541 |
+
|
542 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
543 |
+
self.enc = (
|
544 |
+
Encoder(
|
545 |
+
hidden_channels,
|
546 |
+
filter_channels,
|
547 |
+
n_heads,
|
548 |
+
n_layers,
|
549 |
+
kernel_size,
|
550 |
+
p_dropout,
|
551 |
+
isflow=True,
|
552 |
+
gin_channels=gin_channels,
|
553 |
+
)
|
554 |
+
if wn_sharing_parameter is None
|
555 |
+
else wn_sharing_parameter
|
556 |
+
)
|
557 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
558 |
+
self.post.weight.data.zero_()
|
559 |
+
self.post.bias.data.zero_()
|
560 |
+
|
561 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
562 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
563 |
+
h = self.pre(x0) * x_mask
|
564 |
+
h = self.enc(h, x_mask, g=g)
|
565 |
+
stats = self.post(h) * x_mask
|
566 |
+
if not self.mean_only:
|
567 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
568 |
+
else:
|
569 |
+
m = stats
|
570 |
+
logs = torch.zeros_like(m)
|
571 |
+
|
572 |
+
if not reverse:
|
573 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
574 |
+
x = torch.cat([x0, x1], 1)
|
575 |
+
logdet = torch.sum(logs, [1, 2])
|
576 |
+
return x, logdet
|
577 |
+
else:
|
578 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
579 |
+
x = torch.cat([x0, x1], 1)
|
580 |
+
return x
|
581 |
+
|
582 |
+
x1, logabsdet = piecewise_rational_quadratic_transform(
|
583 |
+
x1,
|
584 |
+
unnormalized_widths,
|
585 |
+
unnormalized_heights,
|
586 |
+
unnormalized_derivatives,
|
587 |
+
inverse=reverse,
|
588 |
+
tails="linear",
|
589 |
+
tail_bound=self.tail_bound,
|
590 |
+
)
|
591 |
+
|
592 |
+
x = torch.cat([x0, x1], 1) * x_mask
|
593 |
+
logdet = torch.sum(logabsdet * x_mask, [1, 2])
|
594 |
+
if not reverse:
|
595 |
+
return x, logdet
|
596 |
+
else:
|
597 |
+
return x
|
monotonic_align/__init__.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from numpy import zeros, int32, float32
|
2 |
+
from torch import from_numpy
|
3 |
+
|
4 |
+
from .core import maximum_path_jit
|
5 |
+
|
6 |
+
|
7 |
+
def maximum_path(neg_cent, mask):
|
8 |
+
device = neg_cent.device
|
9 |
+
dtype = neg_cent.dtype
|
10 |
+
neg_cent = neg_cent.data.cpu().numpy().astype(float32)
|
11 |
+
path = zeros(neg_cent.shape, dtype=int32)
|
12 |
+
|
13 |
+
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(int32)
|
14 |
+
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(int32)
|
15 |
+
maximum_path_jit(path, neg_cent, t_t_max, t_s_max)
|
16 |
+
return from_numpy(path).to(device=device, dtype=dtype)
|
monotonic_align/core.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numba
|
2 |
+
|
3 |
+
|
4 |
+
@numba.jit(
|
5 |
+
numba.void(
|
6 |
+
numba.int32[:, :, ::1],
|
7 |
+
numba.float32[:, :, ::1],
|
8 |
+
numba.int32[::1],
|
9 |
+
numba.int32[::1],
|
10 |
+
),
|
11 |
+
nopython=True,
|
12 |
+
nogil=True,
|
13 |
+
)
|
14 |
+
def maximum_path_jit(paths, values, t_ys, t_xs):
|
15 |
+
b = paths.shape[0]
|
16 |
+
max_neg_val = -1e9
|
17 |
+
for i in range(int(b)):
|
18 |
+
path = paths[i]
|
19 |
+
value = values[i]
|
20 |
+
t_y = t_ys[i]
|
21 |
+
t_x = t_xs[i]
|
22 |
+
|
23 |
+
v_prev = v_cur = 0.0
|
24 |
+
index = t_x - 1
|
25 |
+
|
26 |
+
for y in range(t_y):
|
27 |
+
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
28 |
+
if x == y:
|
29 |
+
v_cur = max_neg_val
|
30 |
+
else:
|
31 |
+
v_cur = value[y - 1, x]
|
32 |
+
if x == 0:
|
33 |
+
if y == 0:
|
34 |
+
v_prev = 0.0
|
35 |
+
else:
|
36 |
+
v_prev = max_neg_val
|
37 |
+
else:
|
38 |
+
v_prev = value[y - 1, x - 1]
|
39 |
+
value[y, x] += max(v_prev, v_cur)
|
40 |
+
|
41 |
+
for y in range(t_y - 1, -1, -1):
|
42 |
+
path[y, index] = 1
|
43 |
+
if index != 0 and (
|
44 |
+
index == y or value[y - 1, index] < value[y - 1, index - 1]
|
45 |
+
):
|
46 |
+
index = index - 1
|
requirements.txt
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
librosa==0.9.1
|
2 |
+
matplotlib
|
3 |
+
numpy
|
4 |
+
numba
|
5 |
+
phonemizer
|
6 |
+
scipy
|
7 |
+
tensorboard
|
8 |
+
torch
|
9 |
+
torchvision
|
10 |
+
Unidecode
|
11 |
+
amfm_decompy
|
12 |
+
jieba
|
13 |
+
transformers
|
14 |
+
pypinyin
|
15 |
+
cn2an
|
16 |
+
gradio
|
17 |
+
av
|
18 |
+
mecab-python3
|
19 |
+
loguru
|
20 |
+
unidic-lite
|
21 |
+
cmudict
|
22 |
+
fugashi
|
23 |
+
num2words
|
text/__init__.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from text.symbols import *
|
2 |
+
|
3 |
+
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
|
4 |
+
|
5 |
+
|
6 |
+
def cleaned_text_to_sequence(cleaned_text, tones, language):
|
7 |
+
"""Converts a string of text to a sequence of IDs corresponding to the symbols in the text.
|
8 |
+
Args:
|
9 |
+
text: string to convert to a sequence
|
10 |
+
Returns:
|
11 |
+
List of integers corresponding to the symbols in the text
|
12 |
+
"""
|
13 |
+
phones = [_symbol_to_id[symbol] for symbol in cleaned_text]
|
14 |
+
tone_start = language_tone_start_map[language]
|
15 |
+
tones = [i + tone_start for i in tones]
|
16 |
+
lang_id = language_id_map[language]
|
17 |
+
lang_ids = [lang_id for i in phones]
|
18 |
+
return phones, tones, lang_ids
|
19 |
+
|
20 |
+
|
21 |
+
def get_bert(norm_text, word2ph, language, device):
|
22 |
+
from .chinese_bert import get_bert_feature as zh_bert
|
23 |
+
from .english_bert_mock import get_bert_feature as en_bert
|
24 |
+
from .japanese_bert import get_bert_feature as jp_bert
|
25 |
+
|
26 |
+
lang_bert_func_map = {"ZH": zh_bert, "EN": en_bert, "JP": jp_bert}
|
27 |
+
bert = lang_bert_func_map[language](norm_text, word2ph, device)
|
28 |
+
return bert
|
text/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.57 kB). View file
|
|
text/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (1.58 kB). View file
|
|
text/__pycache__/chinese.cpython-310.pyc
ADDED
Binary file (4.59 kB). View file
|
|
text/__pycache__/chinese.cpython-38.pyc
ADDED
Binary file (4.52 kB). View file
|
|
text/__pycache__/chinese_bert.cpython-310.pyc
ADDED
Binary file (1.69 kB). View file
|
|
text/__pycache__/chinese_bert.cpython-38.pyc
ADDED
Binary file (1.63 kB). View file
|
|
text/__pycache__/cleaner.cpython-310.pyc
ADDED
Binary file (955 Bytes). View file
|
|
text/__pycache__/cleaner.cpython-38.pyc
ADDED
Binary file (945 Bytes). View file
|
|
text/__pycache__/english_bert_mock.cpython-310.pyc
ADDED
Binary file (313 Bytes). View file
|
|
text/__pycache__/english_bert_mock.cpython-38.pyc
ADDED
Binary file (311 Bytes). View file
|
|
text/__pycache__/japanese.cpython-310.pyc
ADDED
Binary file (12.9 kB). View file
|
|
text/__pycache__/japanese.cpython-38.pyc
ADDED
Binary file (14 kB). View file
|
|
text/__pycache__/japanese_bert.cpython-310.pyc
ADDED
Binary file (1.18 kB). View file
|
|
text/__pycache__/japanese_bert.cpython-38.pyc
ADDED
Binary file (1.16 kB). View file
|
|