Commit
•
d232606
1
Parent(s):
5a07064
Upload 83 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitignore +1 -0
- LICENSE +661 -0
- README.md +6 -5
- app.py +422 -0
- attentions.py +462 -0
- bert/bert_models.json +14 -0
- bert/chinese-roberta-wwm-ext-large/.gitattributes +9 -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/config.json +28 -0
- bert/chinese-roberta-wwm-ext-large/pytorch_model.bin +3 -0
- bert/chinese-roberta-wwm-ext-large/special_tokens_map.json +1 -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
- bert/deberta-v2-large-japanese-char-wwm/.gitattributes +34 -0
- bert/deberta-v2-large-japanese-char-wwm/README.md +89 -0
- bert/deberta-v2-large-japanese-char-wwm/config.json +37 -0
- bert/deberta-v2-large-japanese-char-wwm/pytorch_model.bin +3 -0
- bert/deberta-v2-large-japanese-char-wwm/special_tokens_map.json +7 -0
- bert/deberta-v2-large-japanese-char-wwm/tokenizer_config.json +19 -0
- bert/deberta-v2-large-japanese-char-wwm/vocab.txt +0 -0
- bert/deberta-v3-large/.gitattributes +27 -0
- bert/deberta-v3-large/README.md +93 -0
- bert/deberta-v3-large/config.json +22 -0
- bert/deberta-v3-large/generator_config.json +22 -0
- bert/deberta-v3-large/pytorch_model.bin +3 -0
- bert/deberta-v3-large/pytorch_model.bin.bin +3 -0
- bert/deberta-v3-large/spm.model +3 -0
- bert/deberta-v3-large/tokenizer_config.json +4 -0
- bert_gen.py +84 -0
- common/constants.py +20 -0
- common/log.py +16 -0
- common/stdout_wrapper.py +34 -0
- common/subprocess_utils.py +32 -0
- common/tts_model.py +250 -0
- commons.py +152 -0
- config.py +269 -0
- config.yml +51 -0
- configs/config.json +71 -0
- configs/configs_jp_extra.json +78 -0
- configs/paths.yml +8 -0
- data_utils.py +425 -0
- default_config.yml +81 -0
- infer.py +306 -0
- losses.py +153 -0
- mel_processing.py +146 -0
- model_assets/AbeShinzo20240210/AbeShinzo20240210_e300_s43800.safetensors +3 -0
- model_assets/AbeShinzo20240210/config.json +121 -0
- model_assets/AbeShinzo20240210/config.json.bak +117 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__/
|
LICENSE
ADDED
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 19 November 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU Affero General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works, specifically designed to ensure
|
12 |
+
cooperation with the community in the case of network server software.
|
13 |
+
|
14 |
+
The licenses for most software and other practical works are designed
|
15 |
+
to take away your freedom to share and change the works. By contrast,
|
16 |
+
our General Public Licenses are intended to guarantee your freedom to
|
17 |
+
share and change all versions of a program--to make sure it remains free
|
18 |
+
software for all its users.
|
19 |
+
|
20 |
+
When we speak of free software, we are referring to freedom, not
|
21 |
+
price. Our General Public Licenses are designed to make sure that you
|
22 |
+
have the freedom to distribute copies of free software (and charge for
|
23 |
+
them if you wish), that you receive source code or can get it if you
|
24 |
+
want it, that you can change the software or use pieces of it in new
|
25 |
+
free programs, and that you know you can do these things.
|
26 |
+
|
27 |
+
Developers that use our General Public Licenses protect your rights
|
28 |
+
with two steps: (1) assert copyright on the software, and (2) offer
|
29 |
+
you this License which gives you legal permission to copy, distribute
|
30 |
+
and/or modify the software.
|
31 |
+
|
32 |
+
A secondary benefit of defending all users' freedom is that
|
33 |
+
improvements made in alternate versions of the program, if they
|
34 |
+
receive widespread use, become available for other developers to
|
35 |
+
incorporate. Many developers of free software are heartened and
|
36 |
+
encouraged by the resulting cooperation. However, in the case of
|
37 |
+
software used on network servers, this result may fail to come about.
|
38 |
+
The GNU General Public License permits making a modified version and
|
39 |
+
letting the public access it on a server without ever releasing its
|
40 |
+
source code to the public.
|
41 |
+
|
42 |
+
The GNU Affero General Public License is designed specifically to
|
43 |
+
ensure that, in such cases, the modified source code becomes available
|
44 |
+
to the community. It requires the operator of a network server to
|
45 |
+
provide the source code of the modified version running there to the
|
46 |
+
users of that server. Therefore, public use of a modified version, on
|
47 |
+
a publicly accessible server, gives the public access to the source
|
48 |
+
code of the modified version.
|
49 |
+
|
50 |
+
An older license, called the Affero General Public License and
|
51 |
+
published by Affero, was designed to accomplish similar goals. This is
|
52 |
+
a different license, not a version of the Affero GPL, but Affero has
|
53 |
+
released a new version of the Affero GPL which permits relicensing under
|
54 |
+
this license.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
TERMS AND CONDITIONS
|
60 |
+
|
61 |
+
0. Definitions.
|
62 |
+
|
63 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
64 |
+
|
65 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
66 |
+
works, such as semiconductor masks.
|
67 |
+
|
68 |
+
"The Program" refers to any copyrightable work licensed under this
|
69 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
70 |
+
"recipients" may be individuals or organizations.
|
71 |
+
|
72 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
73 |
+
in a fashion requiring copyright permission, other than the making of an
|
74 |
+
exact copy. The resulting work is called a "modified version" of the
|
75 |
+
earlier work or a work "based on" the earlier work.
|
76 |
+
|
77 |
+
A "covered work" means either the unmodified Program or a work based
|
78 |
+
on the Program.
|
79 |
+
|
80 |
+
To "propagate" a work means to do anything with it that, without
|
81 |
+
permission, would make you directly or secondarily liable for
|
82 |
+
infringement under applicable copyright law, except executing it on a
|
83 |
+
computer or modifying a private copy. Propagation includes copying,
|
84 |
+
distribution (with or without modification), making available to the
|
85 |
+
public, and in some countries other activities as well.
|
86 |
+
|
87 |
+
To "convey" a work means any kind of propagation that enables other
|
88 |
+
parties to make or receive copies. Mere interaction with a user through
|
89 |
+
a computer network, with no transfer of a copy, is not conveying.
|
90 |
+
|
91 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
92 |
+
to the extent that it includes a convenient and prominently visible
|
93 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
94 |
+
tells the user that there is no warranty for the work (except to the
|
95 |
+
extent that warranties are provided), that licensees may convey the
|
96 |
+
work under this License, and how to view a copy of this License. If
|
97 |
+
the interface presents a list of user commands or options, such as a
|
98 |
+
menu, a prominent item in the list meets this criterion.
|
99 |
+
|
100 |
+
1. Source Code.
|
101 |
+
|
102 |
+
The "source code" for a work means the preferred form of the work
|
103 |
+
for making modifications to it. "Object code" means any non-source
|
104 |
+
form of a work.
|
105 |
+
|
106 |
+
A "Standard Interface" means an interface that either is an official
|
107 |
+
standard defined by a recognized standards body, or, in the case of
|
108 |
+
interfaces specified for a particular programming language, one that
|
109 |
+
is widely used among developers working in that language.
|
110 |
+
|
111 |
+
The "System Libraries" of an executable work include anything, other
|
112 |
+
than the work as a whole, that (a) is included in the normal form of
|
113 |
+
packaging a Major Component, but which is not part of that Major
|
114 |
+
Component, and (b) serves only to enable use of the work with that
|
115 |
+
Major Component, or to implement a Standard Interface for which an
|
116 |
+
implementation is available to the public in source code form. A
|
117 |
+
"Major Component", in this context, means a major essential component
|
118 |
+
(kernel, window system, and so on) of the specific operating system
|
119 |
+
(if any) on which the executable work runs, or a compiler used to
|
120 |
+
produce the work, or an object code interpreter used to run it.
|
121 |
+
|
122 |
+
The "Corresponding Source" for a work in object code form means all
|
123 |
+
the source code needed to generate, install, and (for an executable
|
124 |
+
work) run the object code and to modify the work, including scripts to
|
125 |
+
control those activities. However, it does not include the work's
|
126 |
+
System Libraries, or general-purpose tools or generally available free
|
127 |
+
programs which are used unmodified in performing those activities but
|
128 |
+
which are not part of the work. For example, Corresponding Source
|
129 |
+
includes interface definition files associated with source files for
|
130 |
+
the work, and the source code for shared libraries and dynamically
|
131 |
+
linked subprograms that the work is specifically designed to require,
|
132 |
+
such as by intimate data communication or control flow between those
|
133 |
+
subprograms and other parts of the work.
|
134 |
+
|
135 |
+
The Corresponding Source need not include anything that users
|
136 |
+
can regenerate automatically from other parts of the Corresponding
|
137 |
+
Source.
|
138 |
+
|
139 |
+
The Corresponding Source for a work in source code form is that
|
140 |
+
same work.
|
141 |
+
|
142 |
+
2. Basic Permissions.
|
143 |
+
|
144 |
+
All rights granted under this License are granted for the term of
|
145 |
+
copyright on the Program, and are irrevocable provided the stated
|
146 |
+
conditions are met. This License explicitly affirms your unlimited
|
147 |
+
permission to run the unmodified Program. The output from running a
|
148 |
+
covered work is covered by this License only if the output, given its
|
149 |
+
content, constitutes a covered work. This License acknowledges your
|
150 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
151 |
+
|
152 |
+
You may make, run and propagate covered works that you do not
|
153 |
+
convey, without conditions so long as your license otherwise remains
|
154 |
+
in force. You may convey covered works to others for the sole purpose
|
155 |
+
of having them make modifications exclusively for you, or provide you
|
156 |
+
with facilities for running those works, provided that you comply with
|
157 |
+
the terms of this License in conveying all material for which you do
|
158 |
+
not control copyright. Those thus making or running the covered works
|
159 |
+
for you must do so exclusively on your behalf, under your direction
|
160 |
+
and control, on terms that prohibit them from making any copies of
|
161 |
+
your copyrighted material outside their relationship with you.
|
162 |
+
|
163 |
+
Conveying under any other circumstances is permitted solely under
|
164 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
165 |
+
makes it unnecessary.
|
166 |
+
|
167 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
168 |
+
|
169 |
+
No covered work shall be deemed part of an effective technological
|
170 |
+
measure under any applicable law fulfilling obligations under article
|
171 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
172 |
+
similar laws prohibiting or restricting circumvention of such
|
173 |
+
measures.
|
174 |
+
|
175 |
+
When you convey a covered work, you waive any legal power to forbid
|
176 |
+
circumvention of technological measures to the extent such circumvention
|
177 |
+
is effected by exercising rights under this License with respect to
|
178 |
+
the covered work, and you disclaim any intention to limit operation or
|
179 |
+
modification of the work as a means of enforcing, against the work's
|
180 |
+
users, your or third parties' legal rights to forbid circumvention of
|
181 |
+
technological measures.
|
182 |
+
|
183 |
+
4. Conveying Verbatim Copies.
|
184 |
+
|
185 |
+
You may convey verbatim copies of the Program's source code as you
|
186 |
+
receive it, in any medium, provided that you conspicuously and
|
187 |
+
appropriately publish on each copy an appropriate copyright notice;
|
188 |
+
keep intact all notices stating that this License and any
|
189 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
190 |
+
keep intact all notices of the absence of any warranty; and give all
|
191 |
+
recipients a copy of this License along with the Program.
|
192 |
+
|
193 |
+
You may charge any price or no price for each copy that you convey,
|
194 |
+
and you may offer support or warranty protection for a fee.
|
195 |
+
|
196 |
+
5. Conveying Modified Source Versions.
|
197 |
+
|
198 |
+
You may convey a work based on the Program, or the modifications to
|
199 |
+
produce it from the Program, in the form of source code under the
|
200 |
+
terms of section 4, provided that you also meet all of these conditions:
|
201 |
+
|
202 |
+
a) The work must carry prominent notices stating that you modified
|
203 |
+
it, and giving a relevant date.
|
204 |
+
|
205 |
+
b) The work must carry prominent notices stating that it is
|
206 |
+
released under this License and any conditions added under section
|
207 |
+
7. This requirement modifies the requirement in section 4 to
|
208 |
+
"keep intact all notices".
|
209 |
+
|
210 |
+
c) You must license the entire work, as a whole, under this
|
211 |
+
License to anyone who comes into possession of a copy. This
|
212 |
+
License will therefore apply, along with any applicable section 7
|
213 |
+
additional terms, to the whole of the work, and all its parts,
|
214 |
+
regardless of how they are packaged. This License gives no
|
215 |
+
permission to license the work in any other way, but it does not
|
216 |
+
invalidate such permission if you have separately received it.
|
217 |
+
|
218 |
+
d) If the work has interactive user interfaces, each must display
|
219 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
220 |
+
interfaces that do not display Appropriate Legal Notices, your
|
221 |
+
work need not make them do so.
|
222 |
+
|
223 |
+
A compilation of a covered work with other separate and independent
|
224 |
+
works, which are not by their nature extensions of the covered work,
|
225 |
+
and which are not combined with it such as to form a larger program,
|
226 |
+
in or on a volume of a storage or distribution medium, is called an
|
227 |
+
"aggregate" if the compilation and its resulting copyright are not
|
228 |
+
used to limit the access or legal rights of the compilation's users
|
229 |
+
beyond what the individual works permit. Inclusion of a covered work
|
230 |
+
in an aggregate does not cause this License to apply to the other
|
231 |
+
parts of the aggregate.
|
232 |
+
|
233 |
+
6. Conveying Non-Source Forms.
|
234 |
+
|
235 |
+
You may convey a covered work in object code form under the terms
|
236 |
+
of sections 4 and 5, provided that you also convey the
|
237 |
+
machine-readable Corresponding Source under the terms of this License,
|
238 |
+
in one of these ways:
|
239 |
+
|
240 |
+
a) Convey the object code in, or embodied in, a physical product
|
241 |
+
(including a physical distribution medium), accompanied by the
|
242 |
+
Corresponding Source fixed on a durable physical medium
|
243 |
+
customarily used for software interchange.
|
244 |
+
|
245 |
+
b) Convey the object code in, or embodied in, a physical product
|
246 |
+
(including a physical distribution medium), accompanied by a
|
247 |
+
written offer, valid for at least three years and valid for as
|
248 |
+
long as you offer spare parts or customer support for that product
|
249 |
+
model, to give anyone who possesses the object code either (1) a
|
250 |
+
copy of the Corresponding Source for all the software in the
|
251 |
+
product that is covered by this License, on a durable physical
|
252 |
+
medium customarily used for software interchange, for a price no
|
253 |
+
more than your reasonable cost of physically performing this
|
254 |
+
conveying of source, or (2) access to copy the
|
255 |
+
Corresponding Source from a network server at no charge.
|
256 |
+
|
257 |
+
c) Convey individual copies of the object code with a copy of the
|
258 |
+
written offer to provide the Corresponding Source. This
|
259 |
+
alternative is allowed only occasionally and noncommercially, and
|
260 |
+
only if you received the object code with such an offer, in accord
|
261 |
+
with subsection 6b.
|
262 |
+
|
263 |
+
d) Convey the object code by offering access from a designated
|
264 |
+
place (gratis or for a charge), and offer equivalent access to the
|
265 |
+
Corresponding Source in the same way through the same place at no
|
266 |
+
further charge. You need not require recipients to copy the
|
267 |
+
Corresponding Source along with the object code. If the place to
|
268 |
+
copy the object code is a network server, the Corresponding Source
|
269 |
+
may be on a different server (operated by you or a third party)
|
270 |
+
that supports equivalent copying facilities, provided you maintain
|
271 |
+
clear directions next to the object code saying where to find the
|
272 |
+
Corresponding Source. Regardless of what server hosts the
|
273 |
+
Corresponding Source, you remain obligated to ensure that it is
|
274 |
+
available for as long as needed to satisfy these requirements.
|
275 |
+
|
276 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
277 |
+
you inform other peers where the object code and Corresponding
|
278 |
+
Source of the work are being offered to the general public at no
|
279 |
+
charge under subsection 6d.
|
280 |
+
|
281 |
+
A separable portion of the object code, whose source code is excluded
|
282 |
+
from the Corresponding Source as a System Library, need not be
|
283 |
+
included in conveying the object code work.
|
284 |
+
|
285 |
+
A "User Product" is either (1) a "consumer product", which means any
|
286 |
+
tangible personal property which is normally used for personal, family,
|
287 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
288 |
+
into a dwelling. In determining whether a product is a consumer product,
|
289 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
290 |
+
product received by a particular user, "normally used" refers to a
|
291 |
+
typical or common use of that class of product, regardless of the status
|
292 |
+
of the particular user or of the way in which the particular user
|
293 |
+
actually uses, or expects or is expected to use, the product. A product
|
294 |
+
is a consumer product regardless of whether the product has substantial
|
295 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
296 |
+
the only significant mode of use of the product.
|
297 |
+
|
298 |
+
"Installation Information" for a User Product means any methods,
|
299 |
+
procedures, authorization keys, or other information required to install
|
300 |
+
and execute modified versions of a covered work in that User Product from
|
301 |
+
a modified version of its Corresponding Source. The information must
|
302 |
+
suffice to ensure that the continued functioning of the modified object
|
303 |
+
code is in no case prevented or interfered with solely because
|
304 |
+
modification has been made.
|
305 |
+
|
306 |
+
If you convey an object code work under this section in, or with, or
|
307 |
+
specifically for use in, a User Product, and the conveying occurs as
|
308 |
+
part of a transaction in which the right of possession and use of the
|
309 |
+
User Product is transferred to the recipient in perpetuity or for a
|
310 |
+
fixed term (regardless of how the transaction is characterized), the
|
311 |
+
Corresponding Source conveyed under this section must be accompanied
|
312 |
+
by the Installation Information. But this requirement does not apply
|
313 |
+
if neither you nor any third party retains the ability to install
|
314 |
+
modified object code on the User Product (for example, the work has
|
315 |
+
been installed in ROM).
|
316 |
+
|
317 |
+
The requirement to provide Installation Information does not include a
|
318 |
+
requirement to continue to provide support service, warranty, or updates
|
319 |
+
for a work that has been modified or installed by the recipient, or for
|
320 |
+
the User Product in which it has been modified or installed. Access to a
|
321 |
+
network may be denied when the modification itself materially and
|
322 |
+
adversely affects the operation of the network or violates the rules and
|
323 |
+
protocols for communication across the network.
|
324 |
+
|
325 |
+
Corresponding Source conveyed, and Installation Information provided,
|
326 |
+
in accord with this section must be in a format that is publicly
|
327 |
+
documented (and with an implementation available to the public in
|
328 |
+
source code form), and must require no special password or key for
|
329 |
+
unpacking, reading or copying.
|
330 |
+
|
331 |
+
7. Additional Terms.
|
332 |
+
|
333 |
+
"Additional permissions" are terms that supplement the terms of this
|
334 |
+
License by making exceptions from one or more of its conditions.
|
335 |
+
Additional permissions that are applicable to the entire Program shall
|
336 |
+
be treated as though they were included in this License, to the extent
|
337 |
+
that they are valid under applicable law. If additional permissions
|
338 |
+
apply only to part of the Program, that part may be used separately
|
339 |
+
under those permissions, but the entire Program remains governed by
|
340 |
+
this License without regard to the additional permissions.
|
341 |
+
|
342 |
+
When you convey a copy of a covered work, you may at your option
|
343 |
+
remove any additional permissions from that copy, or from any part of
|
344 |
+
it. (Additional permissions may be written to require their own
|
345 |
+
removal in certain cases when you modify the work.) You may place
|
346 |
+
additional permissions on material, added by you to a covered work,
|
347 |
+
for which you have or can give appropriate copyright permission.
|
348 |
+
|
349 |
+
Notwithstanding any other provision of this License, for material you
|
350 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
351 |
+
that material) supplement the terms of this License with terms:
|
352 |
+
|
353 |
+
a) Disclaiming warranty or limiting liability differently from the
|
354 |
+
terms of sections 15 and 16 of this License; or
|
355 |
+
|
356 |
+
b) Requiring preservation of specified reasonable legal notices or
|
357 |
+
author attributions in that material or in the Appropriate Legal
|
358 |
+
Notices displayed by works containing it; or
|
359 |
+
|
360 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
361 |
+
requiring that modified versions of such material be marked in
|
362 |
+
reasonable ways as different from the original version; or
|
363 |
+
|
364 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
365 |
+
authors of the material; or
|
366 |
+
|
367 |
+
e) Declining to grant rights under trademark law for use of some
|
368 |
+
trade names, trademarks, or service marks; or
|
369 |
+
|
370 |
+
f) Requiring indemnification of licensors and authors of that
|
371 |
+
material by anyone who conveys the material (or modified versions of
|
372 |
+
it) with contractual assumptions of liability to the recipient, for
|
373 |
+
any liability that these contractual assumptions directly impose on
|
374 |
+
those licensors and authors.
|
375 |
+
|
376 |
+
All other non-permissive additional terms are considered "further
|
377 |
+
restrictions" within the meaning of section 10. If the Program as you
|
378 |
+
received it, or any part of it, contains a notice stating that it is
|
379 |
+
governed by this License along with a term that is a further
|
380 |
+
restriction, you may remove that term. If a license document contains
|
381 |
+
a further restriction but permits relicensing or conveying under this
|
382 |
+
License, you may add to a covered work material governed by the terms
|
383 |
+
of that license document, provided that the further restriction does
|
384 |
+
not survive such relicensing or conveying.
|
385 |
+
|
386 |
+
If you add terms to a covered work in accord with this section, you
|
387 |
+
must place, in the relevant source files, a statement of the
|
388 |
+
additional terms that apply to those files, or a notice indicating
|
389 |
+
where to find the applicable terms.
|
390 |
+
|
391 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
392 |
+
form of a separately written license, or stated as exceptions;
|
393 |
+
the above requirements apply either way.
|
394 |
+
|
395 |
+
8. Termination.
|
396 |
+
|
397 |
+
You may not propagate or modify a covered work except as expressly
|
398 |
+
provided under this License. Any attempt otherwise to propagate or
|
399 |
+
modify it is void, and will automatically terminate your rights under
|
400 |
+
this License (including any patent licenses granted under the third
|
401 |
+
paragraph of section 11).
|
402 |
+
|
403 |
+
However, if you cease all violation of this License, then your
|
404 |
+
license from a particular copyright holder is reinstated (a)
|
405 |
+
provisionally, unless and until the copyright holder explicitly and
|
406 |
+
finally terminates your license, and (b) permanently, if the copyright
|
407 |
+
holder fails to notify you of the violation by some reasonable means
|
408 |
+
prior to 60 days after the cessation.
|
409 |
+
|
410 |
+
Moreover, your license from a particular copyright holder is
|
411 |
+
reinstated permanently if the copyright holder notifies you of the
|
412 |
+
violation by some reasonable means, this is the first time you have
|
413 |
+
received notice of violation of this License (for any work) from that
|
414 |
+
copyright holder, and you cure the violation prior to 30 days after
|
415 |
+
your receipt of the notice.
|
416 |
+
|
417 |
+
Termination of your rights under this section does not terminate the
|
418 |
+
licenses of parties who have received copies or rights from you under
|
419 |
+
this License. If your rights have been terminated and not permanently
|
420 |
+
reinstated, you do not qualify to receive new licenses for the same
|
421 |
+
material under section 10.
|
422 |
+
|
423 |
+
9. Acceptance Not Required for Having Copies.
|
424 |
+
|
425 |
+
You are not required to accept this License in order to receive or
|
426 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
427 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
428 |
+
to receive a copy likewise does not require acceptance. However,
|
429 |
+
nothing other than this License grants you permission to propagate or
|
430 |
+
modify any covered work. These actions infringe copyright if you do
|
431 |
+
not accept this License. Therefore, by modifying or propagating a
|
432 |
+
covered work, you indicate your acceptance of this License to do so.
|
433 |
+
|
434 |
+
10. Automatic Licensing of Downstream Recipients.
|
435 |
+
|
436 |
+
Each time you convey a covered work, the recipient automatically
|
437 |
+
receives a license from the original licensors, to run, modify and
|
438 |
+
propagate that work, subject to this License. You are not responsible
|
439 |
+
for enforcing compliance by third parties with this License.
|
440 |
+
|
441 |
+
An "entity transaction" is a transaction transferring control of an
|
442 |
+
organization, or substantially all assets of one, or subdividing an
|
443 |
+
organization, or merging organizations. If propagation of a covered
|
444 |
+
work results from an entity transaction, each party to that
|
445 |
+
transaction who receives a copy of the work also receives whatever
|
446 |
+
licenses to the work the party's predecessor in interest had or could
|
447 |
+
give under the previous paragraph, plus a right to possession of the
|
448 |
+
Corresponding Source of the work from the predecessor in interest, if
|
449 |
+
the predecessor has it or can get it with reasonable efforts.
|
450 |
+
|
451 |
+
You may not impose any further restrictions on the exercise of the
|
452 |
+
rights granted or affirmed under this License. For example, you may
|
453 |
+
not impose a license fee, royalty, or other charge for exercise of
|
454 |
+
rights granted under this License, and you may not initiate litigation
|
455 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
456 |
+
any patent claim is infringed by making, using, selling, offering for
|
457 |
+
sale, or importing the Program or any portion of it.
|
458 |
+
|
459 |
+
11. Patents.
|
460 |
+
|
461 |
+
A "contributor" is a copyright holder who authorizes use under this
|
462 |
+
License of the Program or a work on which the Program is based. The
|
463 |
+
work thus licensed is called the contributor's "contributor version".
|
464 |
+
|
465 |
+
A contributor's "essential patent claims" are all patent claims
|
466 |
+
owned or controlled by the contributor, whether already acquired or
|
467 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
468 |
+
by this License, of making, using, or selling its contributor version,
|
469 |
+
but do not include claims that would be infringed only as a
|
470 |
+
consequence of further modification of the contributor version. For
|
471 |
+
purposes of this definition, "control" includes the right to grant
|
472 |
+
patent sublicenses in a manner consistent with the requirements of
|
473 |
+
this License.
|
474 |
+
|
475 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
476 |
+
patent license under the contributor's essential patent claims, to
|
477 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
478 |
+
propagate the contents of its contributor version.
|
479 |
+
|
480 |
+
In the following three paragraphs, a "patent license" is any express
|
481 |
+
agreement or commitment, however denominated, not to enforce a patent
|
482 |
+
(such as an express permission to practice a patent or covenant not to
|
483 |
+
sue for patent infringement). To "grant" such a patent license to a
|
484 |
+
party means to make such an agreement or commitment not to enforce a
|
485 |
+
patent against the party.
|
486 |
+
|
487 |
+
If you convey a covered work, knowingly relying on a patent license,
|
488 |
+
and the Corresponding Source of the work is not available for anyone
|
489 |
+
to copy, free of charge and under the terms of this License, through a
|
490 |
+
publicly available network server or other readily accessible means,
|
491 |
+
then you must either (1) cause the Corresponding Source to be so
|
492 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
493 |
+
patent license for this particular work, or (3) arrange, in a manner
|
494 |
+
consistent with the requirements of this License, to extend the patent
|
495 |
+
license to downstream recipients. "Knowingly relying" means you have
|
496 |
+
actual knowledge that, but for the patent license, your conveying the
|
497 |
+
covered work in a country, or your recipient's use of the covered work
|
498 |
+
in a country, would infringe one or more identifiable patents in that
|
499 |
+
country that you have reason to believe are valid.
|
500 |
+
|
501 |
+
If, pursuant to or in connection with a single transaction or
|
502 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
503 |
+
covered work, and grant a patent license to some of the parties
|
504 |
+
receiving the covered work authorizing them to use, propagate, modify
|
505 |
+
or convey a specific copy of the covered work, then the patent license
|
506 |
+
you grant is automatically extended to all recipients of the covered
|
507 |
+
work and works based on it.
|
508 |
+
|
509 |
+
A patent license is "discriminatory" if it does not include within
|
510 |
+
the scope of its coverage, prohibits the exercise of, or is
|
511 |
+
conditioned on the non-exercise of one or more of the rights that are
|
512 |
+
specifically granted under this License. You may not convey a covered
|
513 |
+
work if you are a party to an arrangement with a third party that is
|
514 |
+
in the business of distributing software, under which you make payment
|
515 |
+
to the third party based on the extent of your activity of conveying
|
516 |
+
the work, and under which the third party grants, to any of the
|
517 |
+
parties who would receive the covered work from you, a discriminatory
|
518 |
+
patent license (a) in connection with copies of the covered work
|
519 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
520 |
+
for and in connection with specific products or compilations that
|
521 |
+
contain the covered work, unless you entered into that arrangement,
|
522 |
+
or that patent license was granted, prior to 28 March 2007.
|
523 |
+
|
524 |
+
Nothing in this License shall be construed as excluding or limiting
|
525 |
+
any implied license or other defenses to infringement that may
|
526 |
+
otherwise be available to you under applicable patent law.
|
527 |
+
|
528 |
+
12. No Surrender of Others' Freedom.
|
529 |
+
|
530 |
+
If conditions are imposed on you (whether by court order, agreement or
|
531 |
+
otherwise) that contradict the conditions of this License, they do not
|
532 |
+
excuse you from the conditions of this License. If you cannot convey a
|
533 |
+
covered work so as to satisfy simultaneously your obligations under this
|
534 |
+
License and any other pertinent obligations, then as a consequence you may
|
535 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
536 |
+
to collect a royalty for further conveying from those to whom you convey
|
537 |
+
the Program, the only way you could satisfy both those terms and this
|
538 |
+
License would be to refrain entirely from conveying the Program.
|
539 |
+
|
540 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
541 |
+
|
542 |
+
Notwithstanding any other provision of this License, if you modify the
|
543 |
+
Program, your modified version must prominently offer all users
|
544 |
+
interacting with it remotely through a computer network (if your version
|
545 |
+
supports such interaction) an opportunity to receive the Corresponding
|
546 |
+
Source of your version by providing access to the Corresponding Source
|
547 |
+
from a network server at no charge, through some standard or customary
|
548 |
+
means of facilitating copying of software. This Corresponding Source
|
549 |
+
shall include the Corresponding Source for any work covered by version 3
|
550 |
+
of the GNU General Public License that is incorporated pursuant to the
|
551 |
+
following paragraph.
|
552 |
+
|
553 |
+
Notwithstanding any other provision of this License, you have
|
554 |
+
permission to link or combine any covered work with a work licensed
|
555 |
+
under version 3 of the GNU General Public License into a single
|
556 |
+
combined work, and to convey the resulting work. The terms of this
|
557 |
+
License will continue to apply to the part which is the covered work,
|
558 |
+
but the work with which it is combined will remain governed by version
|
559 |
+
3 of the GNU General Public License.
|
560 |
+
|
561 |
+
14. Revised Versions of this License.
|
562 |
+
|
563 |
+
The Free Software Foundation may publish revised and/or new versions of
|
564 |
+
the GNU Affero General Public License from time to time. Such new versions
|
565 |
+
will be similar in spirit to the present version, but may differ in detail to
|
566 |
+
address new problems or concerns.
|
567 |
+
|
568 |
+
Each version is given a distinguishing version number. If the
|
569 |
+
Program specifies that a certain numbered version of the GNU Affero General
|
570 |
+
Public License "or any later version" applies to it, you have the
|
571 |
+
option of following the terms and conditions either of that numbered
|
572 |
+
version or of any later version published by the Free Software
|
573 |
+
Foundation. If the Program does not specify a version number of the
|
574 |
+
GNU Affero General Public License, you may choose any version ever published
|
575 |
+
by the Free Software Foundation.
|
576 |
+
|
577 |
+
If the Program specifies that a proxy can decide which future
|
578 |
+
versions of the GNU Affero General Public License can be used, that proxy's
|
579 |
+
public statement of acceptance of a version permanently authorizes you
|
580 |
+
to choose that version for the Program.
|
581 |
+
|
582 |
+
Later license versions may give you additional or different
|
583 |
+
permissions. However, no additional obligations are imposed on any
|
584 |
+
author or copyright holder as a result of your choosing to follow a
|
585 |
+
later version.
|
586 |
+
|
587 |
+
15. Disclaimer of Warranty.
|
588 |
+
|
589 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
590 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
591 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
592 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
593 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
594 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
595 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
596 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
597 |
+
|
598 |
+
16. Limitation of Liability.
|
599 |
+
|
600 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
601 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
602 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
603 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
604 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
605 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
606 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
607 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
608 |
+
SUCH DAMAGES.
|
609 |
+
|
610 |
+
17. Interpretation of Sections 15 and 16.
|
611 |
+
|
612 |
+
If the disclaimer of warranty and limitation of liability provided
|
613 |
+
above cannot be given local legal effect according to their terms,
|
614 |
+
reviewing courts shall apply local law that most closely approximates
|
615 |
+
an absolute waiver of all civil liability in connection with the
|
616 |
+
Program, unless a warranty or assumption of liability accompanies a
|
617 |
+
copy of the Program in return for a fee.
|
618 |
+
|
619 |
+
END OF TERMS AND CONDITIONS
|
620 |
+
|
621 |
+
How to Apply These Terms to Your New Programs
|
622 |
+
|
623 |
+
If you develop a new program, and you want it to be of the greatest
|
624 |
+
possible use to the public, the best way to achieve this is to make it
|
625 |
+
free software which everyone can redistribute and change under these terms.
|
626 |
+
|
627 |
+
To do so, attach the following notices to the program. It is safest
|
628 |
+
to attach them to the start of each source file to most effectively
|
629 |
+
state the exclusion of warranty; and each file should have at least
|
630 |
+
the "copyright" line and a pointer to where the full notice is found.
|
631 |
+
|
632 |
+
<one line to give the program's name and a brief idea of what it does.>
|
633 |
+
Copyright (C) <year> <name of author>
|
634 |
+
|
635 |
+
This program is free software: you can redistribute it and/or modify
|
636 |
+
it under the terms of the GNU Affero General Public License as published
|
637 |
+
by the Free Software Foundation, either version 3 of the License, or
|
638 |
+
(at your option) any later version.
|
639 |
+
|
640 |
+
This program is distributed in the hope that it will be useful,
|
641 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
642 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
643 |
+
GNU Affero General Public License for more details.
|
644 |
+
|
645 |
+
You should have received a copy of the GNU Affero General Public License
|
646 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
647 |
+
|
648 |
+
Also add information on how to contact you by electronic and paper mail.
|
649 |
+
|
650 |
+
If your software can interact with users remotely through a computer
|
651 |
+
network, you should also make sure that it provides a way for users to
|
652 |
+
get its source. For example, if your program is a web application, its
|
653 |
+
interface could display a "Source" link that leads users to an archive
|
654 |
+
of the code. There are many ways you could offer source, and different
|
655 |
+
solutions will be better for different programs; see section 13 for the
|
656 |
+
specific requirements.
|
657 |
+
|
658 |
+
You should also get your employer (if you work as a programmer) or school,
|
659 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
660 |
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
661 |
+
<https://www.gnu.org/licenses/>.
|
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Style-Bert-VITS2 JVNV
|
3 |
+
emoji: 😡😊😱😫
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.16.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: agpl-3.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import datetime
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import sys
|
6 |
+
from typing import Optional
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import torch
|
10 |
+
import yaml
|
11 |
+
|
12 |
+
from common.constants import (
|
13 |
+
DEFAULT_ASSIST_TEXT_WEIGHT,
|
14 |
+
DEFAULT_LENGTH,
|
15 |
+
DEFAULT_LINE_SPLIT,
|
16 |
+
DEFAULT_NOISE,
|
17 |
+
DEFAULT_NOISEW,
|
18 |
+
DEFAULT_SDP_RATIO,
|
19 |
+
DEFAULT_SPLIT_INTERVAL,
|
20 |
+
DEFAULT_STYLE,
|
21 |
+
DEFAULT_STYLE_WEIGHT,
|
22 |
+
Languages,
|
23 |
+
)
|
24 |
+
from common.log import logger
|
25 |
+
from common.tts_model import ModelHolder
|
26 |
+
from infer import InvalidToneError
|
27 |
+
from text.japanese import g2kata_tone, kata_tone2phone_tone, text_normalize
|
28 |
+
|
29 |
+
is_hf_spaces = os.getenv("SYSTEM") == "spaces"
|
30 |
+
limit = 100
|
31 |
+
|
32 |
+
# Get path settings
|
33 |
+
with open(os.path.join("configs", "paths.yml"), "r", encoding="utf-8") as f:
|
34 |
+
path_config: dict[str, str] = yaml.safe_load(f.read())
|
35 |
+
# dataset_root = path_config["dataset_root"]
|
36 |
+
assets_root = path_config["assets_root"]
|
37 |
+
|
38 |
+
languages = [l.value for l in Languages]
|
39 |
+
|
40 |
+
|
41 |
+
def tts_fn(
|
42 |
+
model_name,
|
43 |
+
model_path,
|
44 |
+
text,
|
45 |
+
language,
|
46 |
+
reference_audio_path,
|
47 |
+
sdp_ratio,
|
48 |
+
noise_scale,
|
49 |
+
noise_scale_w,
|
50 |
+
length_scale,
|
51 |
+
line_split,
|
52 |
+
split_interval,
|
53 |
+
assist_text,
|
54 |
+
assist_text_weight,
|
55 |
+
use_assist_text,
|
56 |
+
style,
|
57 |
+
style_weight,
|
58 |
+
kata_tone_json_str,
|
59 |
+
use_tone,
|
60 |
+
speaker,
|
61 |
+
):
|
62 |
+
if is_hf_spaces and len(text) > limit:
|
63 |
+
logger.error(f"Text is too long: {len(text)}")
|
64 |
+
return (
|
65 |
+
f"Error: 文字数が多すぎます({limit}文字以下にしてください)",
|
66 |
+
None,
|
67 |
+
kata_tone_json_str,
|
68 |
+
)
|
69 |
+
model_holder.load_model_gr(model_name, model_path)
|
70 |
+
|
71 |
+
wrong_tone_message = ""
|
72 |
+
kata_tone: Optional[list[tuple[str, int]]] = None
|
73 |
+
if use_tone and kata_tone_json_str != "":
|
74 |
+
if language != "JP":
|
75 |
+
logger.warning("Only Japanese is supported for tone generation.")
|
76 |
+
wrong_tone_message = "アクセント指定は現在日本語のみ対応しています。"
|
77 |
+
if line_split:
|
78 |
+
logger.warning("Tone generation is not supported for line split.")
|
79 |
+
wrong_tone_message = (
|
80 |
+
"アクセント指定は改行で分けて生成を使わない場合のみ対応しています。"
|
81 |
+
)
|
82 |
+
try:
|
83 |
+
kata_tone = []
|
84 |
+
json_data = json.loads(kata_tone_json_str)
|
85 |
+
# tupleを使うように変換
|
86 |
+
for kana, tone in json_data:
|
87 |
+
assert isinstance(kana, str) and tone in (0, 1), f"{kana}, {tone}"
|
88 |
+
kata_tone.append((kana, tone))
|
89 |
+
except Exception as e:
|
90 |
+
logger.warning(f"Error occurred when parsing kana_tone_json: {e}")
|
91 |
+
wrong_tone_message = f"アクセント指定が不正です: {e}"
|
92 |
+
kata_tone = None
|
93 |
+
|
94 |
+
# toneは実際に音声合成に代入される際のみnot Noneになる
|
95 |
+
tone: Optional[list[int]] = None
|
96 |
+
if kata_tone is not None:
|
97 |
+
phone_tone = kata_tone2phone_tone(kata_tone)
|
98 |
+
tone = [t for _, t in phone_tone]
|
99 |
+
|
100 |
+
speaker_id = model_holder.current_model.spk2id[speaker]
|
101 |
+
|
102 |
+
start_time = datetime.datetime.now()
|
103 |
+
|
104 |
+
try:
|
105 |
+
sr, audio = model_holder.current_model.infer(
|
106 |
+
text=text,
|
107 |
+
language=language,
|
108 |
+
reference_audio_path=reference_audio_path,
|
109 |
+
sdp_ratio=sdp_ratio,
|
110 |
+
noise=noise_scale,
|
111 |
+
noisew=noise_scale_w,
|
112 |
+
length=length_scale,
|
113 |
+
line_split=line_split,
|
114 |
+
split_interval=split_interval,
|
115 |
+
assist_text=assist_text,
|
116 |
+
assist_text_weight=assist_text_weight,
|
117 |
+
use_assist_text=use_assist_text,
|
118 |
+
style=style,
|
119 |
+
style_weight=style_weight,
|
120 |
+
given_tone=tone,
|
121 |
+
sid=speaker_id,
|
122 |
+
)
|
123 |
+
except InvalidToneError as e:
|
124 |
+
logger.error(f"Tone error: {e}")
|
125 |
+
return f"Error: アクセント指定が不正です:\n{e}", None, kata_tone_json_str
|
126 |
+
except ValueError as e:
|
127 |
+
logger.error(f"Value error: {e}")
|
128 |
+
return f"Error: {e}", None, kata_tone_json_str
|
129 |
+
|
130 |
+
end_time = datetime.datetime.now()
|
131 |
+
duration = (end_time - start_time).total_seconds()
|
132 |
+
|
133 |
+
if tone is None and language == "JP":
|
134 |
+
# アクセント指定に使えるようにアクセント情報を返す
|
135 |
+
norm_text = text_normalize(text)
|
136 |
+
kata_tone = g2kata_tone(norm_text)
|
137 |
+
kata_tone_json_str = json.dumps(kata_tone, ensure_ascii=False)
|
138 |
+
elif tone is None:
|
139 |
+
kata_tone_json_str = ""
|
140 |
+
message = f"Success, time: {duration} seconds."
|
141 |
+
if wrong_tone_message != "":
|
142 |
+
message = wrong_tone_message + "\n" + message
|
143 |
+
return message, (sr, audio), kata_tone_json_str
|
144 |
+
|
145 |
+
|
146 |
+
initial_text = "こんにちは、初めまして。あなたの名前はなんていうの?"
|
147 |
+
|
148 |
+
example_hf_spaces = [
|
149 |
+
[initial_text, "JP"],
|
150 |
+
["えっと、私、あなたのことが好きです!もしよければ付き合ってくれませんか?", "JP"],
|
151 |
+
["吾輩は猫である��名前はまだ無い。", "JP"],
|
152 |
+
["桜の樹の下には屍体が埋まっている!これは信じていいことなんだよ。", "JP"],
|
153 |
+
["やったー!テストで満点取れたよ!私とっても嬉しいな!", "JP"],
|
154 |
+
[
|
155 |
+
"どうして私の意見を無視するの?許せない!ムカつく!あんたなんか死ねばいいのに。",
|
156 |
+
"JP",
|
157 |
+
],
|
158 |
+
["あはははっ!この漫画めっちゃ笑える、見てよこれ、ふふふ、あはは。", "JP"],
|
159 |
+
[
|
160 |
+
"あなたがいなくなって、私は一人になっちゃって、泣いちゃいそうなほど悲しい。",
|
161 |
+
"JP",
|
162 |
+
],
|
163 |
+
[
|
164 |
+
"深層学習の応用により、感情やアクセントを含む声質の微妙な変化も再現されている。",
|
165 |
+
"JP",
|
166 |
+
],
|
167 |
+
]
|
168 |
+
initial_md = """
|
169 |
+
# おしゃべり安倍晋三メーカー
|
170 |
+
安倍晋三にあんなことやこんなことを喋らせよう
|
171 |
+
"""
|
172 |
+
|
173 |
+
style_md = f"""
|
174 |
+
- プリセットまたは音声ファイルから読み上げの声音・感情・スタイルのようなものを制御できます。
|
175 |
+
- デフォルトの{DEFAULT_STYLE}でも、十分に読み上げる文に応じた感情で感情豊かに読み上げられます。このスタイル制御は、それを重み付きで上書きするような感じです。
|
176 |
+
- 強さを大きくしすぎると発音が変になったり声にならなかったりと崩壊することがあります。
|
177 |
+
- どのくらいに強さがいいかはモデルやスタイルによって異なるようです。
|
178 |
+
- 音声ファイルを入力する場合は、学習データと似た声音の話者(特に同じ性別)でないとよい効果が出ないかもしれません。
|
179 |
+
"""
|
180 |
+
|
181 |
+
|
182 |
+
def make_interactive():
|
183 |
+
return gr.update(interactive=True, value="音声合成")
|
184 |
+
|
185 |
+
|
186 |
+
def make_non_interactive():
|
187 |
+
return gr.update(interactive=False, value="音声合成(モデルをロードしてください)")
|
188 |
+
|
189 |
+
|
190 |
+
def gr_util(item):
|
191 |
+
if item == "プリセットから選ぶ":
|
192 |
+
return (gr.update(visible=True), gr.Audio(visible=False, value=None))
|
193 |
+
else:
|
194 |
+
return (gr.update(visible=False), gr.update(visible=True))
|
195 |
+
|
196 |
+
|
197 |
+
if __name__ == "__main__":
|
198 |
+
parser = argparse.ArgumentParser()
|
199 |
+
parser.add_argument("--cpu", action="store_true", help="Use CPU instead of GPU")
|
200 |
+
parser.add_argument(
|
201 |
+
"--dir", "-d", type=str, help="Model directory", default=assets_root
|
202 |
+
)
|
203 |
+
parser.add_argument(
|
204 |
+
"--share", action="store_true", help="Share this app publicly", default=False
|
205 |
+
)
|
206 |
+
parser.add_argument(
|
207 |
+
"--server-name",
|
208 |
+
type=str,
|
209 |
+
default=None,
|
210 |
+
help="Server name for Gradio app",
|
211 |
+
)
|
212 |
+
parser.add_argument(
|
213 |
+
"--no-autolaunch",
|
214 |
+
action="store_true",
|
215 |
+
default=False,
|
216 |
+
help="Do not launch app automatically",
|
217 |
+
)
|
218 |
+
args = parser.parse_args()
|
219 |
+
model_dir = args.dir
|
220 |
+
|
221 |
+
if args.cpu:
|
222 |
+
device = "cpu"
|
223 |
+
else:
|
224 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
225 |
+
|
226 |
+
model_holder = ModelHolder(model_dir, device)
|
227 |
+
|
228 |
+
model_names = model_holder.model_names
|
229 |
+
if len(model_names) == 0:
|
230 |
+
logger.error(
|
231 |
+
f"モデルが見つかりませんでした。{model_dir}にモデルを置いてください。"
|
232 |
+
)
|
233 |
+
sys.exit(1)
|
234 |
+
initial_id = 0
|
235 |
+
initial_pth_files = model_holder.model_files_dict[model_names[initial_id]]
|
236 |
+
|
237 |
+
with gr.Blocks(theme="NoCrypt/miku") as app:
|
238 |
+
gr.Markdown(initial_md)
|
239 |
+
with gr.Row():
|
240 |
+
with gr.Column():
|
241 |
+
with gr.Row():
|
242 |
+
with gr.Column(scale=3):
|
243 |
+
model_name = gr.Dropdown(
|
244 |
+
label="モデル一覧",
|
245 |
+
choices=model_names,
|
246 |
+
value=model_names[initial_id],
|
247 |
+
)
|
248 |
+
model_path = gr.Dropdown(
|
249 |
+
label="モデルファイル",
|
250 |
+
choices=initial_pth_files,
|
251 |
+
value=initial_pth_files[0],
|
252 |
+
)
|
253 |
+
refresh_button = gr.Button("更新", scale=1, visible=False)
|
254 |
+
load_button = gr.Button("ロード", scale=1, variant="primary")
|
255 |
+
text_input = gr.TextArea(label="テキスト", value=initial_text)
|
256 |
+
|
257 |
+
line_split = gr.Checkbox(
|
258 |
+
label="改行で分けて生成(分けたほうが感情が乗ります)",
|
259 |
+
value=DEFAULT_LINE_SPLIT,
|
260 |
+
)
|
261 |
+
split_interval = gr.Slider(
|
262 |
+
minimum=0.0,
|
263 |
+
maximum=2,
|
264 |
+
value=DEFAULT_SPLIT_INTERVAL,
|
265 |
+
step=0.1,
|
266 |
+
label="改行ごとに挟む無音の長さ(秒)",
|
267 |
+
)
|
268 |
+
line_split.change(
|
269 |
+
lambda x: (gr.Slider(visible=x)),
|
270 |
+
inputs=[line_split],
|
271 |
+
outputs=[split_interval],
|
272 |
+
)
|
273 |
+
tone = gr.Textbox(
|
274 |
+
label="アクセント調整(数値は 0=低 か1=高 のみ)",
|
275 |
+
info="改行で分けない場合のみ使えます。万能ではありません。",
|
276 |
+
)
|
277 |
+
use_tone = gr.Checkbox(label="アクセント調整を使う", value=False)
|
278 |
+
use_tone.change(
|
279 |
+
lambda x: (gr.Checkbox(value=False) if x else gr.Checkbox()),
|
280 |
+
inputs=[use_tone],
|
281 |
+
outputs=[line_split],
|
282 |
+
)
|
283 |
+
language = gr.Dropdown(choices=["JP"], value="JP", label="Language")
|
284 |
+
speaker = gr.Dropdown(label="話者")
|
285 |
+
with gr.Accordion(label="詳細設定", open=False):
|
286 |
+
sdp_ratio = gr.Slider(
|
287 |
+
minimum=0,
|
288 |
+
maximum=1,
|
289 |
+
value=DEFAULT_SDP_RATIO,
|
290 |
+
step=0.1,
|
291 |
+
label="SDP Ratio",
|
292 |
+
)
|
293 |
+
noise_scale = gr.Slider(
|
294 |
+
minimum=0.1,
|
295 |
+
maximum=2,
|
296 |
+
value=DEFAULT_NOISE,
|
297 |
+
step=0.1,
|
298 |
+
label="Noise",
|
299 |
+
)
|
300 |
+
noise_scale_w = gr.Slider(
|
301 |
+
minimum=0.1,
|
302 |
+
maximum=2,
|
303 |
+
value=DEFAULT_NOISEW,
|
304 |
+
step=0.1,
|
305 |
+
label="Noise_W",
|
306 |
+
)
|
307 |
+
length_scale = gr.Slider(
|
308 |
+
minimum=0.1,
|
309 |
+
maximum=2,
|
310 |
+
value=DEFAULT_LENGTH,
|
311 |
+
step=0.1,
|
312 |
+
label="Length",
|
313 |
+
)
|
314 |
+
use_assist_text = gr.Checkbox(
|
315 |
+
label="Assist textを使う", value=False
|
316 |
+
)
|
317 |
+
assist_text = gr.Textbox(
|
318 |
+
label="Assist text",
|
319 |
+
placeholder="どうして私の意見を無視するの?許せない、ムカつく!死ねばいいのに。",
|
320 |
+
info="このテキストの読み上げと似た声音・感情になりやすくなります。ただ抑揚やテンポ等が犠牲になる傾向があります。",
|
321 |
+
visible=False,
|
322 |
+
)
|
323 |
+
assist_text_weight = gr.Slider(
|
324 |
+
minimum=0,
|
325 |
+
maximum=1,
|
326 |
+
value=DEFAULT_ASSIST_TEXT_WEIGHT,
|
327 |
+
step=0.1,
|
328 |
+
label="Assist textの強さ",
|
329 |
+
visible=False,
|
330 |
+
)
|
331 |
+
use_assist_text.change(
|
332 |
+
lambda x: (gr.Textbox(visible=x), gr.Slider(visible=x)),
|
333 |
+
inputs=[use_assist_text],
|
334 |
+
outputs=[assist_text, assist_text_weight],
|
335 |
+
)
|
336 |
+
with gr.Column():
|
337 |
+
with gr.Accordion("スタイルについて詳細", open=False):
|
338 |
+
gr.Markdown(style_md)
|
339 |
+
style_mode = gr.Radio(
|
340 |
+
["プリセットから選ぶ", "音声ファイルを入力"],
|
341 |
+
label="スタイルの指定方法",
|
342 |
+
value="プリセットから選ぶ",
|
343 |
+
)
|
344 |
+
style = gr.Dropdown(
|
345 |
+
label=f"スタイル({DEFAULT_STYLE}が平均スタイル)",
|
346 |
+
choices=["モデルをロードしてください"],
|
347 |
+
value="モデルをロードしてください",
|
348 |
+
)
|
349 |
+
style_weight = gr.Slider(
|
350 |
+
minimum=0,
|
351 |
+
maximum=50,
|
352 |
+
value=DEFAULT_STYLE_WEIGHT,
|
353 |
+
step=0.1,
|
354 |
+
label="スタイルの強さ",
|
355 |
+
)
|
356 |
+
ref_audio_path = gr.Audio(
|
357 |
+
label="参照音声", type="filepath", visible=False
|
358 |
+
)
|
359 |
+
tts_button = gr.Button(
|
360 |
+
"音声合成(モデルをロードしてください)",
|
361 |
+
variant="primary",
|
362 |
+
interactive=False,
|
363 |
+
)
|
364 |
+
text_output = gr.Textbox(label="情報")
|
365 |
+
audio_output = gr.Audio(label="結果")
|
366 |
+
with gr.Accordion("テキスト例", open=True):
|
367 |
+
gr.Examples(example_hf_spaces, inputs=[text_input, language])
|
368 |
+
|
369 |
+
tts_button.click(
|
370 |
+
tts_fn,
|
371 |
+
inputs=[
|
372 |
+
model_name,
|
373 |
+
model_path,
|
374 |
+
text_input,
|
375 |
+
language,
|
376 |
+
ref_audio_path,
|
377 |
+
sdp_ratio,
|
378 |
+
noise_scale,
|
379 |
+
noise_scale_w,
|
380 |
+
length_scale,
|
381 |
+
line_split,
|
382 |
+
split_interval,
|
383 |
+
assist_text,
|
384 |
+
assist_text_weight,
|
385 |
+
use_assist_text,
|
386 |
+
style,
|
387 |
+
style_weight,
|
388 |
+
tone,
|
389 |
+
use_tone,
|
390 |
+
speaker,
|
391 |
+
],
|
392 |
+
outputs=[text_output, audio_output, tone],
|
393 |
+
)
|
394 |
+
|
395 |
+
model_name.change(
|
396 |
+
model_holder.update_model_files_gr,
|
397 |
+
inputs=[model_name],
|
398 |
+
outputs=[model_path],
|
399 |
+
)
|
400 |
+
|
401 |
+
model_path.change(make_non_interactive, outputs=[tts_button])
|
402 |
+
|
403 |
+
refresh_button.click(
|
404 |
+
model_holder.update_model_names_gr,
|
405 |
+
outputs=[model_name, model_path, tts_button],
|
406 |
+
)
|
407 |
+
|
408 |
+
load_button.click(
|
409 |
+
model_holder.load_model_gr,
|
410 |
+
inputs=[model_name, model_path],
|
411 |
+
outputs=[style, tts_button, speaker],
|
412 |
+
)
|
413 |
+
|
414 |
+
style_mode.change(
|
415 |
+
gr_util,
|
416 |
+
inputs=[style_mode],
|
417 |
+
outputs=[style, ref_audio_path],
|
418 |
+
)
|
419 |
+
|
420 |
+
app.launch(
|
421 |
+
inbrowser=not args.no_autolaunch, share=args.share, server_name=args.server_name
|
422 |
+
)
|
attentions.py
ADDED
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
from common.log import logger as logging
|
8 |
+
|
9 |
+
|
10 |
+
class LayerNorm(nn.Module):
|
11 |
+
def __init__(self, channels, eps=1e-5):
|
12 |
+
super().__init__()
|
13 |
+
self.channels = channels
|
14 |
+
self.eps = eps
|
15 |
+
|
16 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
17 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
18 |
+
|
19 |
+
def forward(self, x):
|
20 |
+
x = x.transpose(1, -1)
|
21 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
22 |
+
return x.transpose(1, -1)
|
23 |
+
|
24 |
+
|
25 |
+
@torch.jit.script
|
26 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
27 |
+
n_channels_int = n_channels[0]
|
28 |
+
in_act = input_a + input_b
|
29 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
30 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
31 |
+
acts = t_act * s_act
|
32 |
+
return acts
|
33 |
+
|
34 |
+
|
35 |
+
class Encoder(nn.Module):
|
36 |
+
def __init__(
|
37 |
+
self,
|
38 |
+
hidden_channels,
|
39 |
+
filter_channels,
|
40 |
+
n_heads,
|
41 |
+
n_layers,
|
42 |
+
kernel_size=1,
|
43 |
+
p_dropout=0.0,
|
44 |
+
window_size=4,
|
45 |
+
isflow=True,
|
46 |
+
**kwargs
|
47 |
+
):
|
48 |
+
super().__init__()
|
49 |
+
self.hidden_channels = hidden_channels
|
50 |
+
self.filter_channels = filter_channels
|
51 |
+
self.n_heads = n_heads
|
52 |
+
self.n_layers = n_layers
|
53 |
+
self.kernel_size = kernel_size
|
54 |
+
self.p_dropout = p_dropout
|
55 |
+
self.window_size = window_size
|
56 |
+
# if isflow:
|
57 |
+
# cond_layer = torch.nn.Conv1d(256, 2*hidden_channels*n_layers, 1)
|
58 |
+
# self.cond_pre = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, 1)
|
59 |
+
# self.cond_layer = weight_norm(cond_layer, name='weight')
|
60 |
+
# self.gin_channels = 256
|
61 |
+
self.cond_layer_idx = self.n_layers
|
62 |
+
if "gin_channels" in kwargs:
|
63 |
+
self.gin_channels = kwargs["gin_channels"]
|
64 |
+
if self.gin_channels != 0:
|
65 |
+
self.spk_emb_linear = nn.Linear(self.gin_channels, self.hidden_channels)
|
66 |
+
# vits2 says 3rd block, so idx is 2 by default
|
67 |
+
self.cond_layer_idx = (
|
68 |
+
kwargs["cond_layer_idx"] if "cond_layer_idx" in kwargs else 2
|
69 |
+
)
|
70 |
+
# logging.debug(self.gin_channels, self.cond_layer_idx)
|
71 |
+
assert (
|
72 |
+
self.cond_layer_idx < self.n_layers
|
73 |
+
), "cond_layer_idx should be less than n_layers"
|
74 |
+
self.drop = nn.Dropout(p_dropout)
|
75 |
+
self.attn_layers = nn.ModuleList()
|
76 |
+
self.norm_layers_1 = nn.ModuleList()
|
77 |
+
self.ffn_layers = nn.ModuleList()
|
78 |
+
self.norm_layers_2 = nn.ModuleList()
|
79 |
+
for i in range(self.n_layers):
|
80 |
+
self.attn_layers.append(
|
81 |
+
MultiHeadAttention(
|
82 |
+
hidden_channels,
|
83 |
+
hidden_channels,
|
84 |
+
n_heads,
|
85 |
+
p_dropout=p_dropout,
|
86 |
+
window_size=window_size,
|
87 |
+
)
|
88 |
+
)
|
89 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
90 |
+
self.ffn_layers.append(
|
91 |
+
FFN(
|
92 |
+
hidden_channels,
|
93 |
+
hidden_channels,
|
94 |
+
filter_channels,
|
95 |
+
kernel_size,
|
96 |
+
p_dropout=p_dropout,
|
97 |
+
)
|
98 |
+
)
|
99 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
100 |
+
|
101 |
+
def forward(self, x, x_mask, g=None):
|
102 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
103 |
+
x = x * x_mask
|
104 |
+
for i in range(self.n_layers):
|
105 |
+
if i == self.cond_layer_idx and g is not None:
|
106 |
+
g = self.spk_emb_linear(g.transpose(1, 2))
|
107 |
+
g = g.transpose(1, 2)
|
108 |
+
x = x + g
|
109 |
+
x = x * x_mask
|
110 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
111 |
+
y = self.drop(y)
|
112 |
+
x = self.norm_layers_1[i](x + y)
|
113 |
+
|
114 |
+
y = self.ffn_layers[i](x, x_mask)
|
115 |
+
y = self.drop(y)
|
116 |
+
x = self.norm_layers_2[i](x + y)
|
117 |
+
x = x * x_mask
|
118 |
+
return x
|
119 |
+
|
120 |
+
|
121 |
+
class Decoder(nn.Module):
|
122 |
+
def __init__(
|
123 |
+
self,
|
124 |
+
hidden_channels,
|
125 |
+
filter_channels,
|
126 |
+
n_heads,
|
127 |
+
n_layers,
|
128 |
+
kernel_size=1,
|
129 |
+
p_dropout=0.0,
|
130 |
+
proximal_bias=False,
|
131 |
+
proximal_init=True,
|
132 |
+
**kwargs
|
133 |
+
):
|
134 |
+
super().__init__()
|
135 |
+
self.hidden_channels = hidden_channels
|
136 |
+
self.filter_channels = filter_channels
|
137 |
+
self.n_heads = n_heads
|
138 |
+
self.n_layers = n_layers
|
139 |
+
self.kernel_size = kernel_size
|
140 |
+
self.p_dropout = p_dropout
|
141 |
+
self.proximal_bias = proximal_bias
|
142 |
+
self.proximal_init = proximal_init
|
143 |
+
|
144 |
+
self.drop = nn.Dropout(p_dropout)
|
145 |
+
self.self_attn_layers = nn.ModuleList()
|
146 |
+
self.norm_layers_0 = nn.ModuleList()
|
147 |
+
self.encdec_attn_layers = nn.ModuleList()
|
148 |
+
self.norm_layers_1 = nn.ModuleList()
|
149 |
+
self.ffn_layers = nn.ModuleList()
|
150 |
+
self.norm_layers_2 = nn.ModuleList()
|
151 |
+
for i in range(self.n_layers):
|
152 |
+
self.self_attn_layers.append(
|
153 |
+
MultiHeadAttention(
|
154 |
+
hidden_channels,
|
155 |
+
hidden_channels,
|
156 |
+
n_heads,
|
157 |
+
p_dropout=p_dropout,
|
158 |
+
proximal_bias=proximal_bias,
|
159 |
+
proximal_init=proximal_init,
|
160 |
+
)
|
161 |
+
)
|
162 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
163 |
+
self.encdec_attn_layers.append(
|
164 |
+
MultiHeadAttention(
|
165 |
+
hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout
|
166 |
+
)
|
167 |
+
)
|
168 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
169 |
+
self.ffn_layers.append(
|
170 |
+
FFN(
|
171 |
+
hidden_channels,
|
172 |
+
hidden_channels,
|
173 |
+
filter_channels,
|
174 |
+
kernel_size,
|
175 |
+
p_dropout=p_dropout,
|
176 |
+
causal=True,
|
177 |
+
)
|
178 |
+
)
|
179 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
180 |
+
|
181 |
+
def forward(self, x, x_mask, h, h_mask):
|
182 |
+
"""
|
183 |
+
x: decoder input
|
184 |
+
h: encoder output
|
185 |
+
"""
|
186 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(
|
187 |
+
device=x.device, dtype=x.dtype
|
188 |
+
)
|
189 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
190 |
+
x = x * x_mask
|
191 |
+
for i in range(self.n_layers):
|
192 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
193 |
+
y = self.drop(y)
|
194 |
+
x = self.norm_layers_0[i](x + y)
|
195 |
+
|
196 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
197 |
+
y = self.drop(y)
|
198 |
+
x = self.norm_layers_1[i](x + y)
|
199 |
+
|
200 |
+
y = self.ffn_layers[i](x, x_mask)
|
201 |
+
y = self.drop(y)
|
202 |
+
x = self.norm_layers_2[i](x + y)
|
203 |
+
x = x * x_mask
|
204 |
+
return x
|
205 |
+
|
206 |
+
|
207 |
+
class MultiHeadAttention(nn.Module):
|
208 |
+
def __init__(
|
209 |
+
self,
|
210 |
+
channels,
|
211 |
+
out_channels,
|
212 |
+
n_heads,
|
213 |
+
p_dropout=0.0,
|
214 |
+
window_size=None,
|
215 |
+
heads_share=True,
|
216 |
+
block_length=None,
|
217 |
+
proximal_bias=False,
|
218 |
+
proximal_init=False,
|
219 |
+
):
|
220 |
+
super().__init__()
|
221 |
+
assert channels % n_heads == 0
|
222 |
+
|
223 |
+
self.channels = channels
|
224 |
+
self.out_channels = out_channels
|
225 |
+
self.n_heads = n_heads
|
226 |
+
self.p_dropout = p_dropout
|
227 |
+
self.window_size = window_size
|
228 |
+
self.heads_share = heads_share
|
229 |
+
self.block_length = block_length
|
230 |
+
self.proximal_bias = proximal_bias
|
231 |
+
self.proximal_init = proximal_init
|
232 |
+
self.attn = None
|
233 |
+
|
234 |
+
self.k_channels = channels // n_heads
|
235 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
236 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
237 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
238 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
239 |
+
self.drop = nn.Dropout(p_dropout)
|
240 |
+
|
241 |
+
if window_size is not None:
|
242 |
+
n_heads_rel = 1 if heads_share else n_heads
|
243 |
+
rel_stddev = self.k_channels**-0.5
|
244 |
+
self.emb_rel_k = nn.Parameter(
|
245 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
246 |
+
* rel_stddev
|
247 |
+
)
|
248 |
+
self.emb_rel_v = nn.Parameter(
|
249 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
250 |
+
* rel_stddev
|
251 |
+
)
|
252 |
+
|
253 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
254 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
255 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
256 |
+
if proximal_init:
|
257 |
+
with torch.no_grad():
|
258 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
259 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
260 |
+
|
261 |
+
def forward(self, x, c, attn_mask=None):
|
262 |
+
q = self.conv_q(x)
|
263 |
+
k = self.conv_k(c)
|
264 |
+
v = self.conv_v(c)
|
265 |
+
|
266 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
267 |
+
|
268 |
+
x = self.conv_o(x)
|
269 |
+
return x
|
270 |
+
|
271 |
+
def attention(self, query, key, value, mask=None):
|
272 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
273 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
274 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
275 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
276 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
277 |
+
|
278 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
279 |
+
if self.window_size is not None:
|
280 |
+
assert (
|
281 |
+
t_s == t_t
|
282 |
+
), "Relative attention is only available for self-attention."
|
283 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
284 |
+
rel_logits = self._matmul_with_relative_keys(
|
285 |
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
286 |
+
)
|
287 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
288 |
+
scores = scores + scores_local
|
289 |
+
if self.proximal_bias:
|
290 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
291 |
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
292 |
+
device=scores.device, dtype=scores.dtype
|
293 |
+
)
|
294 |
+
if mask is not None:
|
295 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
296 |
+
if self.block_length is not None:
|
297 |
+
assert (
|
298 |
+
t_s == t_t
|
299 |
+
), "Local attention is only available for self-attention."
|
300 |
+
block_mask = (
|
301 |
+
torch.ones_like(scores)
|
302 |
+
.triu(-self.block_length)
|
303 |
+
.tril(self.block_length)
|
304 |
+
)
|
305 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
306 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
307 |
+
p_attn = self.drop(p_attn)
|
308 |
+
output = torch.matmul(p_attn, value)
|
309 |
+
if self.window_size is not None:
|
310 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
311 |
+
value_relative_embeddings = self._get_relative_embeddings(
|
312 |
+
self.emb_rel_v, t_s
|
313 |
+
)
|
314 |
+
output = output + self._matmul_with_relative_values(
|
315 |
+
relative_weights, value_relative_embeddings
|
316 |
+
)
|
317 |
+
output = (
|
318 |
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
319 |
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
320 |
+
return output, p_attn
|
321 |
+
|
322 |
+
def _matmul_with_relative_values(self, x, y):
|
323 |
+
"""
|
324 |
+
x: [b, h, l, m]
|
325 |
+
y: [h or 1, m, d]
|
326 |
+
ret: [b, h, l, d]
|
327 |
+
"""
|
328 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
329 |
+
return ret
|
330 |
+
|
331 |
+
def _matmul_with_relative_keys(self, x, y):
|
332 |
+
"""
|
333 |
+
x: [b, h, l, d]
|
334 |
+
y: [h or 1, m, d]
|
335 |
+
ret: [b, h, l, m]
|
336 |
+
"""
|
337 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
338 |
+
return ret
|
339 |
+
|
340 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
341 |
+
2 * self.window_size + 1
|
342 |
+
# Pad first before slice to avoid using cond ops.
|
343 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
344 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
345 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
346 |
+
if pad_length > 0:
|
347 |
+
padded_relative_embeddings = F.pad(
|
348 |
+
relative_embeddings,
|
349 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
350 |
+
)
|
351 |
+
else:
|
352 |
+
padded_relative_embeddings = relative_embeddings
|
353 |
+
used_relative_embeddings = padded_relative_embeddings[
|
354 |
+
:, slice_start_position:slice_end_position
|
355 |
+
]
|
356 |
+
return used_relative_embeddings
|
357 |
+
|
358 |
+
def _relative_position_to_absolute_position(self, x):
|
359 |
+
"""
|
360 |
+
x: [b, h, l, 2*l-1]
|
361 |
+
ret: [b, h, l, l]
|
362 |
+
"""
|
363 |
+
batch, heads, length, _ = x.size()
|
364 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
365 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
366 |
+
|
367 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
368 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
369 |
+
x_flat = F.pad(
|
370 |
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
371 |
+
)
|
372 |
+
|
373 |
+
# Reshape and slice out the padded elements.
|
374 |
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
375 |
+
:, :, :length, length - 1 :
|
376 |
+
]
|
377 |
+
return x_final
|
378 |
+
|
379 |
+
def _absolute_position_to_relative_position(self, x):
|
380 |
+
"""
|
381 |
+
x: [b, h, l, l]
|
382 |
+
ret: [b, h, l, 2*l-1]
|
383 |
+
"""
|
384 |
+
batch, heads, length, _ = x.size()
|
385 |
+
# pad along column
|
386 |
+
x = F.pad(
|
387 |
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
388 |
+
)
|
389 |
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
390 |
+
# add 0's in the beginning that will skew the elements after reshape
|
391 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
392 |
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
393 |
+
return x_final
|
394 |
+
|
395 |
+
def _attention_bias_proximal(self, length):
|
396 |
+
"""Bias for self-attention to encourage attention to close positions.
|
397 |
+
Args:
|
398 |
+
length: an integer scalar.
|
399 |
+
Returns:
|
400 |
+
a Tensor with shape [1, 1, length, length]
|
401 |
+
"""
|
402 |
+
r = torch.arange(length, dtype=torch.float32)
|
403 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
404 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
405 |
+
|
406 |
+
|
407 |
+
class FFN(nn.Module):
|
408 |
+
def __init__(
|
409 |
+
self,
|
410 |
+
in_channels,
|
411 |
+
out_channels,
|
412 |
+
filter_channels,
|
413 |
+
kernel_size,
|
414 |
+
p_dropout=0.0,
|
415 |
+
activation=None,
|
416 |
+
causal=False,
|
417 |
+
):
|
418 |
+
super().__init__()
|
419 |
+
self.in_channels = in_channels
|
420 |
+
self.out_channels = out_channels
|
421 |
+
self.filter_channels = filter_channels
|
422 |
+
self.kernel_size = kernel_size
|
423 |
+
self.p_dropout = p_dropout
|
424 |
+
self.activation = activation
|
425 |
+
self.causal = causal
|
426 |
+
|
427 |
+
if causal:
|
428 |
+
self.padding = self._causal_padding
|
429 |
+
else:
|
430 |
+
self.padding = self._same_padding
|
431 |
+
|
432 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
433 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
434 |
+
self.drop = nn.Dropout(p_dropout)
|
435 |
+
|
436 |
+
def forward(self, x, x_mask):
|
437 |
+
x = self.conv_1(self.padding(x * x_mask))
|
438 |
+
if self.activation == "gelu":
|
439 |
+
x = x * torch.sigmoid(1.702 * x)
|
440 |
+
else:
|
441 |
+
x = torch.relu(x)
|
442 |
+
x = self.drop(x)
|
443 |
+
x = self.conv_2(self.padding(x * x_mask))
|
444 |
+
return x * x_mask
|
445 |
+
|
446 |
+
def _causal_padding(self, x):
|
447 |
+
if self.kernel_size == 1:
|
448 |
+
return x
|
449 |
+
pad_l = self.kernel_size - 1
|
450 |
+
pad_r = 0
|
451 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
452 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
453 |
+
return x
|
454 |
+
|
455 |
+
def _same_padding(self, x):
|
456 |
+
if self.kernel_size == 1:
|
457 |
+
return x
|
458 |
+
pad_l = (self.kernel_size - 1) // 2
|
459 |
+
pad_r = self.kernel_size // 2
|
460 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
461 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
462 |
+
return x
|
bert/bert_models.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"deberta-v2-large-japanese-char-wwm": {
|
3 |
+
"repo_id": "ku-nlp/deberta-v2-large-japanese-char-wwm",
|
4 |
+
"files": ["pytorch_model.bin"]
|
5 |
+
},
|
6 |
+
"chinese-roberta-wwm-ext-large": {
|
7 |
+
"repo_id": "hfl/chinese-roberta-wwm-ext-large",
|
8 |
+
"files": ["pytorch_model.bin"]
|
9 |
+
},
|
10 |
+
"deberta-v3-large": {
|
11 |
+
"repo_id": "microsoft/deberta-v3-large",
|
12 |
+
"files": ["spm.model", "pytorch_model.bin"]
|
13 |
+
}
|
14 |
+
}
|
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/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/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/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4ac62d49144d770c5ca9a5d1d3039c4995665a080febe63198189857c6bd11cd
|
3 |
+
size 1306484351
|
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/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
|
|
bert/deberta-v2-large-japanese-char-wwm/.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
bert/deberta-v2-large-japanese-char-wwm/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: ja
|
3 |
+
license: cc-by-sa-4.0
|
4 |
+
library_name: transformers
|
5 |
+
tags:
|
6 |
+
- deberta
|
7 |
+
- deberta-v2
|
8 |
+
- fill-mask
|
9 |
+
- character
|
10 |
+
- wwm
|
11 |
+
datasets:
|
12 |
+
- wikipedia
|
13 |
+
- cc100
|
14 |
+
- oscar
|
15 |
+
metrics:
|
16 |
+
- accuracy
|
17 |
+
mask_token: "[MASK]"
|
18 |
+
widget:
|
19 |
+
- text: "京都大学で自然言語処理を[MASK][MASK]する。"
|
20 |
+
---
|
21 |
+
|
22 |
+
# Model Card for Japanese character-level DeBERTa V2 large
|
23 |
+
|
24 |
+
## Model description
|
25 |
+
|
26 |
+
This is a Japanese DeBERTa V2 large model pre-trained on Japanese Wikipedia, the Japanese portion of CC-100, and the Japanese portion of OSCAR.
|
27 |
+
This model is trained with character-level tokenization and whole word masking.
|
28 |
+
|
29 |
+
## How to use
|
30 |
+
|
31 |
+
You can use this model for masked language modeling as follows:
|
32 |
+
|
33 |
+
```python
|
34 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained('ku-nlp/deberta-v2-large-japanese-char-wwm')
|
36 |
+
model = AutoModelForMaskedLM.from_pretrained('ku-nlp/deberta-v2-large-japanese-char-wwm')
|
37 |
+
|
38 |
+
sentence = '京都大学で自然言語処理を[MASK][MASK]する。'
|
39 |
+
encoding = tokenizer(sentence, return_tensors='pt')
|
40 |
+
...
|
41 |
+
```
|
42 |
+
|
43 |
+
You can also fine-tune this model on downstream tasks.
|
44 |
+
|
45 |
+
## Tokenization
|
46 |
+
|
47 |
+
There is no need to tokenize texts in advance, and you can give raw texts to the tokenizer.
|
48 |
+
The texts are tokenized into character-level tokens by [sentencepiece](https://github.com/google/sentencepiece).
|
49 |
+
|
50 |
+
## Training data
|
51 |
+
|
52 |
+
We used the following corpora for pre-training:
|
53 |
+
|
54 |
+
- Japanese Wikipedia (as of 20221020, 3.2GB, 27M sentences, 1.3M documents)
|
55 |
+
- Japanese portion of CC-100 (85GB, 619M sentences, 66M documents)
|
56 |
+
- Japanese portion of OSCAR (54GB, 326M sentences, 25M documents)
|
57 |
+
|
58 |
+
Note that we filtered out documents annotated with "header", "footer", or "noisy" tags in OSCAR.
|
59 |
+
Also note that Japanese Wikipedia was duplicated 10 times to make the total size of the corpus comparable to that of CC-100 and OSCAR. As a result, the total size of the training data is 171GB.
|
60 |
+
|
61 |
+
## Training procedure
|
62 |
+
|
63 |
+
We first segmented texts in the corpora into words using [Juman++ 2.0.0-rc3](https://github.com/ku-nlp/jumanpp/releases/tag/v2.0.0-rc3) for whole word masking.
|
64 |
+
Then, we built a sentencepiece model with 22,012 tokens including all characters that appear in the training corpus.
|
65 |
+
|
66 |
+
We tokenized raw corpora into character-level subwords using the sentencepiece model and trained the Japanese DeBERTa model using [transformers](https://github.com/huggingface/transformers) library.
|
67 |
+
The training took 26 days using 16 NVIDIA A100-SXM4-40GB GPUs.
|
68 |
+
|
69 |
+
The following hyperparameters were used during pre-training:
|
70 |
+
|
71 |
+
- learning_rate: 1e-4
|
72 |
+
- per_device_train_batch_size: 26
|
73 |
+
- distributed_type: multi-GPU
|
74 |
+
- num_devices: 16
|
75 |
+
- gradient_accumulation_steps: 8
|
76 |
+
- total_train_batch_size: 3,328
|
77 |
+
- max_seq_length: 512
|
78 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-06
|
79 |
+
- lr_scheduler_type: linear schedule with warmup (lr = 0 at 300k steps)
|
80 |
+
- training_steps: 260,000
|
81 |
+
- warmup_steps: 10,000
|
82 |
+
|
83 |
+
The accuracy of the trained model on the masked language modeling task was 0.795.
|
84 |
+
The evaluation set consists of 5,000 randomly sampled documents from each of the training corpora.
|
85 |
+
|
86 |
+
## Acknowledgments
|
87 |
+
|
88 |
+
This work was supported by Joint Usage/Research Center for Interdisciplinary Large-scale Information Infrastructures (JHPCN) through General Collaboration Project no. jh221004, "Developing a Platform for Constructing and Sharing of Large-Scale Japanese Language Models".
|
89 |
+
For training models, we used the mdx: a platform for the data-driven future.
|
bert/deberta-v2-large-japanese-char-wwm/config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"DebertaV2ForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_head_size": 64,
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"conv_act": "gelu",
|
8 |
+
"conv_kernel_size": 3,
|
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-07,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"max_relative_positions": -1,
|
17 |
+
"model_type": "deberta-v2",
|
18 |
+
"norm_rel_ebd": "layer_norm",
|
19 |
+
"num_attention_heads": 16,
|
20 |
+
"num_hidden_layers": 24,
|
21 |
+
"pad_token_id": 0,
|
22 |
+
"pooler_dropout": 0,
|
23 |
+
"pooler_hidden_act": "gelu",
|
24 |
+
"pooler_hidden_size": 1024,
|
25 |
+
"pos_att_type": [
|
26 |
+
"p2c",
|
27 |
+
"c2p"
|
28 |
+
],
|
29 |
+
"position_biased_input": false,
|
30 |
+
"position_buckets": 256,
|
31 |
+
"relative_attention": true,
|
32 |
+
"share_att_key": true,
|
33 |
+
"torch_dtype": "float16",
|
34 |
+
"transformers_version": "4.25.1",
|
35 |
+
"type_vocab_size": 0,
|
36 |
+
"vocab_size": 22012
|
37 |
+
}
|
bert/deberta-v2-large-japanese-char-wwm/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bf0dab8ad87bd7c22e85ec71e04f2240804fda6d33196157d6b5923af6ea1201
|
3 |
+
size 1318456639
|
bert/deberta-v2-large-japanese-char-wwm/special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
bert/deberta-v2-large-japanese-char-wwm/tokenizer_config.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"do_lower_case": false,
|
4 |
+
"do_subword_tokenize": true,
|
5 |
+
"do_word_tokenize": true,
|
6 |
+
"jumanpp_kwargs": null,
|
7 |
+
"mask_token": "[MASK]",
|
8 |
+
"mecab_kwargs": null,
|
9 |
+
"model_max_length": 1000000000000000019884624838656,
|
10 |
+
"never_split": null,
|
11 |
+
"pad_token": "[PAD]",
|
12 |
+
"sep_token": "[SEP]",
|
13 |
+
"special_tokens_map_file": null,
|
14 |
+
"subword_tokenizer_type": "character",
|
15 |
+
"sudachi_kwargs": null,
|
16 |
+
"tokenizer_class": "BertJapaneseTokenizer",
|
17 |
+
"unk_token": "[UNK]",
|
18 |
+
"word_tokenizer_type": "basic"
|
19 |
+
}
|
bert/deberta-v2-large-japanese-char-wwm/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
bert/deberta-v3-large/.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
bert/deberta-v3-large/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
tags:
|
4 |
+
- deberta
|
5 |
+
- deberta-v3
|
6 |
+
- fill-mask
|
7 |
+
thumbnail: https://huggingface.co/front/thumbnails/microsoft.png
|
8 |
+
license: mit
|
9 |
+
---
|
10 |
+
|
11 |
+
## DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing
|
12 |
+
|
13 |
+
[DeBERTa](https://arxiv.org/abs/2006.03654) improves the BERT and RoBERTa models using disentangled attention and enhanced mask decoder. With those two improvements, DeBERTa out perform RoBERTa on a majority of NLU tasks with 80GB training data.
|
14 |
+
|
15 |
+
In [DeBERTa V3](https://arxiv.org/abs/2111.09543), we further improved the efficiency of DeBERTa using ELECTRA-Style pre-training with Gradient Disentangled Embedding Sharing. Compared to DeBERTa, our V3 version significantly improves the model performance on downstream tasks. You can find more technique details about the new model from our [paper](https://arxiv.org/abs/2111.09543).
|
16 |
+
|
17 |
+
Please check the [official repository](https://github.com/microsoft/DeBERTa) for more implementation details and updates.
|
18 |
+
|
19 |
+
The DeBERTa V3 large model comes with 24 layers and a hidden size of 1024. It has 304M backbone parameters with a vocabulary containing 128K tokens which introduces 131M parameters in the Embedding layer. This model was trained using the 160GB data as DeBERTa V2.
|
20 |
+
|
21 |
+
|
22 |
+
#### Fine-tuning on NLU tasks
|
23 |
+
|
24 |
+
We present the dev results on SQuAD 2.0 and MNLI tasks.
|
25 |
+
|
26 |
+
| Model |Vocabulary(K)|Backbone #Params(M)| SQuAD 2.0(F1/EM) | MNLI-m/mm(ACC)|
|
27 |
+
|-------------------|----------|-------------------|-----------|----------|
|
28 |
+
| RoBERTa-large |50 |304 | 89.4/86.5 | 90.2 |
|
29 |
+
| XLNet-large |32 |- | 90.6/87.9 | 90.8 |
|
30 |
+
| DeBERTa-large |50 |- | 90.7/88.0 | 91.3 |
|
31 |
+
| **DeBERTa-v3-large**|128|304 | **91.5/89.0**| **91.8/91.9**|
|
32 |
+
|
33 |
+
|
34 |
+
#### Fine-tuning with HF transformers
|
35 |
+
|
36 |
+
```bash
|
37 |
+
#!/bin/bash
|
38 |
+
|
39 |
+
cd transformers/examples/pytorch/text-classification/
|
40 |
+
|
41 |
+
pip install datasets
|
42 |
+
export TASK_NAME=mnli
|
43 |
+
|
44 |
+
output_dir="ds_results"
|
45 |
+
|
46 |
+
num_gpus=8
|
47 |
+
|
48 |
+
batch_size=8
|
49 |
+
|
50 |
+
python -m torch.distributed.launch --nproc_per_node=${num_gpus} \
|
51 |
+
run_glue.py \
|
52 |
+
--model_name_or_path microsoft/deberta-v3-large \
|
53 |
+
--task_name $TASK_NAME \
|
54 |
+
--do_train \
|
55 |
+
--do_eval \
|
56 |
+
--evaluation_strategy steps \
|
57 |
+
--max_seq_length 256 \
|
58 |
+
--warmup_steps 50 \
|
59 |
+
--per_device_train_batch_size ${batch_size} \
|
60 |
+
--learning_rate 6e-6 \
|
61 |
+
--num_train_epochs 2 \
|
62 |
+
--output_dir $output_dir \
|
63 |
+
--overwrite_output_dir \
|
64 |
+
--logging_steps 1000 \
|
65 |
+
--logging_dir $output_dir
|
66 |
+
|
67 |
+
```
|
68 |
+
|
69 |
+
### Citation
|
70 |
+
|
71 |
+
If you find DeBERTa useful for your work, please cite the following papers:
|
72 |
+
|
73 |
+
``` latex
|
74 |
+
@misc{he2021debertav3,
|
75 |
+
title={DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing},
|
76 |
+
author={Pengcheng He and Jianfeng Gao and Weizhu Chen},
|
77 |
+
year={2021},
|
78 |
+
eprint={2111.09543},
|
79 |
+
archivePrefix={arXiv},
|
80 |
+
primaryClass={cs.CL}
|
81 |
+
}
|
82 |
+
```
|
83 |
+
|
84 |
+
``` latex
|
85 |
+
@inproceedings{
|
86 |
+
he2021deberta,
|
87 |
+
title={DEBERTA: DECODING-ENHANCED BERT WITH DISENTANGLED ATTENTION},
|
88 |
+
author={Pengcheng He and Xiaodong Liu and Jianfeng Gao and Weizhu Chen},
|
89 |
+
booktitle={International Conference on Learning Representations},
|
90 |
+
year={2021},
|
91 |
+
url={https://openreview.net/forum?id=XPZIaotutsD}
|
92 |
+
}
|
93 |
+
```
|
bert/deberta-v3-large/config.json
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "deberta-v2",
|
3 |
+
"attention_probs_dropout_prob": 0.1,
|
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 |
+
"relative_attention": true,
|
11 |
+
"position_buckets": 256,
|
12 |
+
"norm_rel_ebd": "layer_norm",
|
13 |
+
"share_att_key": true,
|
14 |
+
"pos_att_type": "p2c|c2p",
|
15 |
+
"layer_norm_eps": 1e-7,
|
16 |
+
"max_relative_positions": -1,
|
17 |
+
"position_biased_input": false,
|
18 |
+
"num_attention_heads": 16,
|
19 |
+
"num_hidden_layers": 24,
|
20 |
+
"type_vocab_size": 0,
|
21 |
+
"vocab_size": 128100
|
22 |
+
}
|
bert/deberta-v3-large/generator_config.json
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "deberta-v2",
|
3 |
+
"attention_probs_dropout_prob": 0.1,
|
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 |
+
"relative_attention": true,
|
11 |
+
"position_buckets": 256,
|
12 |
+
"norm_rel_ebd": "layer_norm",
|
13 |
+
"share_att_key": true,
|
14 |
+
"pos_att_type": "p2c|c2p",
|
15 |
+
"layer_norm_eps": 1e-7,
|
16 |
+
"max_relative_positions": -1,
|
17 |
+
"position_biased_input": false,
|
18 |
+
"num_attention_heads": 16,
|
19 |
+
"num_hidden_layers": 12,
|
20 |
+
"type_vocab_size": 0,
|
21 |
+
"vocab_size": 128100
|
22 |
+
}
|
bert/deberta-v3-large/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd5b5d93e2db101aaf281df0ea1216c07ad73620ff59c5b42dccac4bf2eef5b5
|
3 |
+
size 873673253
|
bert/deberta-v3-large/pytorch_model.bin.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd5b5d93e2db101aaf281df0ea1216c07ad73620ff59c5b42dccac4bf2eef5b5
|
3 |
+
size 873673253
|
bert/deberta-v3-large/spm.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
|
3 |
+
size 2464616
|
bert/deberta-v3-large/tokenizer_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_lower_case": false,
|
3 |
+
"vocab_type": "spm"
|
4 |
+
}
|
bert_gen.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import sys
|
3 |
+
from multiprocessing import Pool
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.multiprocessing as mp
|
7 |
+
from tqdm import tqdm
|
8 |
+
|
9 |
+
import commons
|
10 |
+
import utils
|
11 |
+
from config import config
|
12 |
+
from text import cleaned_text_to_sequence, get_bert
|
13 |
+
|
14 |
+
|
15 |
+
def process_line(x):
|
16 |
+
line, add_blank = x
|
17 |
+
device = config.bert_gen_config.device
|
18 |
+
if config.bert_gen_config.use_multi_device:
|
19 |
+
rank = mp.current_process()._identity
|
20 |
+
rank = rank[0] if len(rank) > 0 else 0
|
21 |
+
if torch.cuda.is_available():
|
22 |
+
gpu_id = rank % torch.cuda.device_count()
|
23 |
+
device = torch.device(f"cuda:{gpu_id}")
|
24 |
+
else:
|
25 |
+
device = torch.device("cpu")
|
26 |
+
wav_path, _, language_str, text, phones, tone, word2ph = line.strip().split("|")
|
27 |
+
phone = phones.split(" ")
|
28 |
+
tone = [int(i) for i in tone.split(" ")]
|
29 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
30 |
+
word2ph = [i for i in word2ph]
|
31 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
32 |
+
|
33 |
+
if add_blank:
|
34 |
+
phone = commons.intersperse(phone, 0)
|
35 |
+
tone = commons.intersperse(tone, 0)
|
36 |
+
language = commons.intersperse(language, 0)
|
37 |
+
for i in range(len(word2ph)):
|
38 |
+
word2ph[i] = word2ph[i] * 2
|
39 |
+
word2ph[0] += 1
|
40 |
+
|
41 |
+
bert_path = wav_path.replace(".WAV", ".wav").replace(".wav", ".bert.pt")
|
42 |
+
|
43 |
+
try:
|
44 |
+
bert = torch.load(bert_path)
|
45 |
+
assert bert.shape[-1] == len(phone)
|
46 |
+
except Exception:
|
47 |
+
bert = get_bert(text, word2ph, language_str, device)
|
48 |
+
assert bert.shape[-1] == len(phone)
|
49 |
+
torch.save(bert, bert_path)
|
50 |
+
|
51 |
+
|
52 |
+
preprocess_text_config = config.preprocess_text_config
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
parser = argparse.ArgumentParser()
|
56 |
+
parser.add_argument(
|
57 |
+
"-c", "--config", type=str, default=config.bert_gen_config.config_path
|
58 |
+
)
|
59 |
+
parser.add_argument(
|
60 |
+
"--num_processes", type=int, default=config.bert_gen_config.num_processes
|
61 |
+
)
|
62 |
+
args, _ = parser.parse_known_args()
|
63 |
+
config_path = args.config
|
64 |
+
hps = utils.get_hparams_from_file(config_path)
|
65 |
+
lines = []
|
66 |
+
with open(hps.data.training_files, encoding="utf-8") as f:
|
67 |
+
lines.extend(f.readlines())
|
68 |
+
|
69 |
+
with open(hps.data.validation_files, encoding="utf-8") as f:
|
70 |
+
lines.extend(f.readlines())
|
71 |
+
add_blank = [hps.data.add_blank] * len(lines)
|
72 |
+
|
73 |
+
if len(lines) != 0:
|
74 |
+
num_processes = args.num_processes
|
75 |
+
with Pool(processes=num_processes) as pool:
|
76 |
+
for _ in tqdm(
|
77 |
+
pool.imap_unordered(process_line, zip(lines, add_blank)),
|
78 |
+
total=len(lines),
|
79 |
+
file=sys.stdout,
|
80 |
+
):
|
81 |
+
# 这里是缩进的代码块,表示循环体
|
82 |
+
pass # 使用pass语句作为占位符
|
83 |
+
|
84 |
+
print(f"bert.pt is generated! total: {len(lines)} bert.pt files.")
|
common/constants.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import enum
|
2 |
+
|
3 |
+
DEFAULT_STYLE: str = "Neutral"
|
4 |
+
DEFAULT_STYLE_WEIGHT: float = 5.0
|
5 |
+
|
6 |
+
|
7 |
+
class Languages(str, enum.Enum):
|
8 |
+
JP = "JP"
|
9 |
+
EN = "EN"
|
10 |
+
ZH = "ZH"
|
11 |
+
|
12 |
+
|
13 |
+
DEFAULT_SDP_RATIO: float = 0.2
|
14 |
+
DEFAULT_NOISE: float = 0.6
|
15 |
+
DEFAULT_NOISEW: float = 0.8
|
16 |
+
DEFAULT_LENGTH: float = 1.0
|
17 |
+
DEFAULT_LINE_SPLIT: bool = True
|
18 |
+
DEFAULT_SPLIT_INTERVAL: float = 0.5
|
19 |
+
DEFAULT_ASSIST_TEXT_WEIGHT: float = 0.7
|
20 |
+
DEFAULT_ASSIST_TEXT_WEIGHT: float = 1.0
|
common/log.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
logger封装
|
3 |
+
"""
|
4 |
+
from loguru import logger
|
5 |
+
|
6 |
+
from .stdout_wrapper import SAFE_STDOUT
|
7 |
+
|
8 |
+
# 移除所有默认的处理器
|
9 |
+
logger.remove()
|
10 |
+
|
11 |
+
# 自定义格式并添加到标准输出
|
12 |
+
log_format = (
|
13 |
+
"<g>{time:MM-DD HH:mm:ss}</g> |<lvl>{level:^8}</lvl>| {file}:{line} | {message}"
|
14 |
+
)
|
15 |
+
|
16 |
+
logger.add(SAFE_STDOUT, format=log_format, backtrace=True, diagnose=True)
|
common/stdout_wrapper.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import tempfile
|
3 |
+
|
4 |
+
|
5 |
+
class StdoutWrapper:
|
6 |
+
def __init__(self):
|
7 |
+
self.temp_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
|
8 |
+
self.original_stdout = sys.stdout
|
9 |
+
|
10 |
+
def write(self, message: str):
|
11 |
+
self.temp_file.write(message)
|
12 |
+
self.temp_file.flush()
|
13 |
+
print(message, end="", file=self.original_stdout)
|
14 |
+
|
15 |
+
def flush(self):
|
16 |
+
self.temp_file.flush()
|
17 |
+
|
18 |
+
def read(self):
|
19 |
+
self.temp_file.seek(0)
|
20 |
+
return self.temp_file.read()
|
21 |
+
|
22 |
+
def close(self):
|
23 |
+
self.temp_file.close()
|
24 |
+
|
25 |
+
def fileno(self):
|
26 |
+
return self.temp_file.fileno()
|
27 |
+
|
28 |
+
|
29 |
+
try:
|
30 |
+
import google.colab
|
31 |
+
|
32 |
+
SAFE_STDOUT = StdoutWrapper()
|
33 |
+
except ImportError:
|
34 |
+
SAFE_STDOUT = sys.stdout
|
common/subprocess_utils.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import sys
|
3 |
+
|
4 |
+
from .log import logger
|
5 |
+
from .stdout_wrapper import SAFE_STDOUT
|
6 |
+
|
7 |
+
python = sys.executable
|
8 |
+
|
9 |
+
|
10 |
+
def run_script_with_log(cmd: list[str], ignore_warning=False) -> tuple[bool, str]:
|
11 |
+
logger.info(f"Running: {' '.join(cmd)}")
|
12 |
+
result = subprocess.run(
|
13 |
+
[python] + cmd,
|
14 |
+
stdout=SAFE_STDOUT, # type: ignore
|
15 |
+
stderr=subprocess.PIPE,
|
16 |
+
text=True,
|
17 |
+
)
|
18 |
+
if result.returncode != 0:
|
19 |
+
logger.error(f"Error: {' '.join(cmd)}\n{result.stderr}")
|
20 |
+
return False, result.stderr
|
21 |
+
elif result.stderr and not ignore_warning:
|
22 |
+
logger.warning(f"Warning: {' '.join(cmd)}\n{result.stderr}")
|
23 |
+
return True, result.stderr
|
24 |
+
logger.success(f"Success: {' '.join(cmd)}")
|
25 |
+
return True, ""
|
26 |
+
|
27 |
+
|
28 |
+
def second_elem_of(original_function):
|
29 |
+
def inner_function(*args, **kwargs):
|
30 |
+
return original_function(*args, **kwargs)[1]
|
31 |
+
|
32 |
+
return inner_function
|
common/tts_model.py
ADDED
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
import os
|
5 |
+
import warnings
|
6 |
+
from gradio.processing_utils import convert_to_16_bit_wav
|
7 |
+
from typing import Dict, List, Optional, Union
|
8 |
+
|
9 |
+
import utils
|
10 |
+
from infer import get_net_g, infer
|
11 |
+
from models import SynthesizerTrn
|
12 |
+
from models_jp_extra import SynthesizerTrn as SynthesizerTrnJPExtra
|
13 |
+
|
14 |
+
from .log import logger
|
15 |
+
from .constants import (
|
16 |
+
DEFAULT_ASSIST_TEXT_WEIGHT,
|
17 |
+
DEFAULT_LENGTH,
|
18 |
+
DEFAULT_LINE_SPLIT,
|
19 |
+
DEFAULT_NOISE,
|
20 |
+
DEFAULT_NOISEW,
|
21 |
+
DEFAULT_SDP_RATIO,
|
22 |
+
DEFAULT_SPLIT_INTERVAL,
|
23 |
+
DEFAULT_STYLE,
|
24 |
+
DEFAULT_STYLE_WEIGHT,
|
25 |
+
)
|
26 |
+
|
27 |
+
|
28 |
+
class Model:
|
29 |
+
def __init__(
|
30 |
+
self, model_path: str, config_path: str, style_vec_path: str, device: str
|
31 |
+
):
|
32 |
+
self.model_path: str = model_path
|
33 |
+
self.config_path: str = config_path
|
34 |
+
self.device: str = device
|
35 |
+
self.style_vec_path: str = style_vec_path
|
36 |
+
self.hps: utils.HParams = utils.get_hparams_from_file(self.config_path)
|
37 |
+
self.spk2id: Dict[str, int] = self.hps.data.spk2id
|
38 |
+
self.id2spk: Dict[int, str] = {v: k for k, v in self.spk2id.items()}
|
39 |
+
|
40 |
+
self.num_styles: int = self.hps.data.num_styles
|
41 |
+
if hasattr(self.hps.data, "style2id"):
|
42 |
+
self.style2id: Dict[str, int] = self.hps.data.style2id
|
43 |
+
else:
|
44 |
+
self.style2id: Dict[str, int] = {str(i): i for i in range(self.num_styles)}
|
45 |
+
if len(self.style2id) != self.num_styles:
|
46 |
+
raise ValueError(
|
47 |
+
f"Number of styles ({self.num_styles}) does not match the number of style2id ({len(self.style2id)})"
|
48 |
+
)
|
49 |
+
|
50 |
+
self.style_vectors: np.ndarray = np.load(self.style_vec_path)
|
51 |
+
if self.style_vectors.shape[0] != self.num_styles:
|
52 |
+
raise ValueError(
|
53 |
+
f"The number of styles ({self.num_styles}) does not match the number of style vectors ({self.style_vectors.shape[0]})"
|
54 |
+
)
|
55 |
+
|
56 |
+
self.net_g: Union[SynthesizerTrn, SynthesizerTrnJPExtra, None] = None
|
57 |
+
|
58 |
+
def load_net_g(self):
|
59 |
+
self.net_g = get_net_g(
|
60 |
+
model_path=self.model_path,
|
61 |
+
version=self.hps.version,
|
62 |
+
device=self.device,
|
63 |
+
hps=self.hps,
|
64 |
+
)
|
65 |
+
|
66 |
+
def get_style_vector(self, style_id: int, weight: float = 1.0) -> np.ndarray:
|
67 |
+
mean = self.style_vectors[0]
|
68 |
+
style_vec = self.style_vectors[style_id]
|
69 |
+
style_vec = mean + (style_vec - mean) * weight
|
70 |
+
return style_vec
|
71 |
+
|
72 |
+
def get_style_vector_from_audio(
|
73 |
+
self, audio_path: str, weight: float = 1.0
|
74 |
+
) -> np.ndarray:
|
75 |
+
from style_gen import get_style_vector
|
76 |
+
|
77 |
+
xvec = get_style_vector(audio_path)
|
78 |
+
mean = self.style_vectors[0]
|
79 |
+
xvec = mean + (xvec - mean) * weight
|
80 |
+
return xvec
|
81 |
+
|
82 |
+
def infer(
|
83 |
+
self,
|
84 |
+
text: str,
|
85 |
+
language: str = "JP",
|
86 |
+
sid: int = 0,
|
87 |
+
reference_audio_path: Optional[str] = None,
|
88 |
+
sdp_ratio: float = DEFAULT_SDP_RATIO,
|
89 |
+
noise: float = DEFAULT_NOISE,
|
90 |
+
noisew: float = DEFAULT_NOISEW,
|
91 |
+
length: float = DEFAULT_LENGTH,
|
92 |
+
line_split: bool = DEFAULT_LINE_SPLIT,
|
93 |
+
split_interval: float = DEFAULT_SPLIT_INTERVAL,
|
94 |
+
assist_text: Optional[str] = None,
|
95 |
+
assist_text_weight: float = DEFAULT_ASSIST_TEXT_WEIGHT,
|
96 |
+
use_assist_text: bool = False,
|
97 |
+
style: str = DEFAULT_STYLE,
|
98 |
+
style_weight: float = DEFAULT_STYLE_WEIGHT,
|
99 |
+
given_tone: Optional[list[int]] = None,
|
100 |
+
) -> tuple[int, np.ndarray]:
|
101 |
+
logger.info(f"Start generating audio data from text:\n{text}")
|
102 |
+
if language != "JP" and self.hps.version.endswith("JP-Extra"):
|
103 |
+
raise ValueError(
|
104 |
+
"The model is trained with JP-Extra, but the language is not JP"
|
105 |
+
)
|
106 |
+
if reference_audio_path == "":
|
107 |
+
reference_audio_path = None
|
108 |
+
if assist_text == "" or not use_assist_text:
|
109 |
+
assist_text = None
|
110 |
+
|
111 |
+
if self.net_g is None:
|
112 |
+
self.load_net_g()
|
113 |
+
if reference_audio_path is None:
|
114 |
+
style_id = self.style2id[style]
|
115 |
+
style_vector = self.get_style_vector(style_id, style_weight)
|
116 |
+
else:
|
117 |
+
style_vector = self.get_style_vector_from_audio(
|
118 |
+
reference_audio_path, style_weight
|
119 |
+
)
|
120 |
+
if not line_split:
|
121 |
+
with torch.no_grad():
|
122 |
+
audio = infer(
|
123 |
+
text=text,
|
124 |
+
sdp_ratio=sdp_ratio,
|
125 |
+
noise_scale=noise,
|
126 |
+
noise_scale_w=noisew,
|
127 |
+
length_scale=length,
|
128 |
+
sid=sid,
|
129 |
+
language=language,
|
130 |
+
hps=self.hps,
|
131 |
+
net_g=self.net_g,
|
132 |
+
device=self.device,
|
133 |
+
assist_text=assist_text,
|
134 |
+
assist_text_weight=assist_text_weight,
|
135 |
+
style_vec=style_vector,
|
136 |
+
given_tone=given_tone,
|
137 |
+
)
|
138 |
+
else:
|
139 |
+
texts = text.split("\n")
|
140 |
+
texts = [t for t in texts if t != ""]
|
141 |
+
audios = []
|
142 |
+
with torch.no_grad():
|
143 |
+
for i, t in enumerate(texts):
|
144 |
+
audios.append(
|
145 |
+
infer(
|
146 |
+
text=t,
|
147 |
+
sdp_ratio=sdp_ratio,
|
148 |
+
noise_scale=noise,
|
149 |
+
noise_scale_w=noisew,
|
150 |
+
length_scale=length,
|
151 |
+
sid=sid,
|
152 |
+
language=language,
|
153 |
+
hps=self.hps,
|
154 |
+
net_g=self.net_g,
|
155 |
+
device=self.device,
|
156 |
+
assist_text=assist_text,
|
157 |
+
assist_text_weight=assist_text_weight,
|
158 |
+
style_vec=style_vector,
|
159 |
+
)
|
160 |
+
)
|
161 |
+
if i != len(texts) - 1:
|
162 |
+
audios.append(np.zeros(int(44100 * split_interval)))
|
163 |
+
audio = np.concatenate(audios)
|
164 |
+
with warnings.catch_warnings():
|
165 |
+
warnings.simplefilter("ignore")
|
166 |
+
audio = convert_to_16_bit_wav(audio)
|
167 |
+
logger.info("Audio data generated successfully")
|
168 |
+
return (self.hps.data.sampling_rate, audio)
|
169 |
+
|
170 |
+
|
171 |
+
class ModelHolder:
|
172 |
+
def __init__(self, root_dir: str, device: str):
|
173 |
+
self.root_dir: str = root_dir
|
174 |
+
self.device: str = device
|
175 |
+
self.model_files_dict: Dict[str, List[str]] = {}
|
176 |
+
self.current_model: Optional[Model] = None
|
177 |
+
self.model_names: List[str] = []
|
178 |
+
self.models: List[Model] = []
|
179 |
+
self.refresh()
|
180 |
+
|
181 |
+
def refresh(self):
|
182 |
+
self.model_files_dict = {}
|
183 |
+
self.model_names = []
|
184 |
+
self.current_model = None
|
185 |
+
model_dirs = [
|
186 |
+
d
|
187 |
+
for d in os.listdir(self.root_dir)
|
188 |
+
if os.path.isdir(os.path.join(self.root_dir, d))
|
189 |
+
]
|
190 |
+
for model_name in model_dirs:
|
191 |
+
model_dir = os.path.join(self.root_dir, model_name)
|
192 |
+
model_files = [
|
193 |
+
os.path.join(model_dir, f)
|
194 |
+
for f in os.listdir(model_dir)
|
195 |
+
if f.endswith(".pth") or f.endswith(".pt") or f.endswith(".safetensors")
|
196 |
+
]
|
197 |
+
if len(model_files) == 0:
|
198 |
+
logger.warning(
|
199 |
+
f"No model files found in {self.root_dir}/{model_name}, so skip it"
|
200 |
+
)
|
201 |
+
continue
|
202 |
+
self.model_files_dict[model_name] = model_files
|
203 |
+
self.model_names.append(model_name)
|
204 |
+
|
205 |
+
def load_model_gr(
|
206 |
+
self, model_name: str, model_path: str
|
207 |
+
) -> tuple[gr.Dropdown, gr.Button, gr.Dropdown]:
|
208 |
+
if model_name not in self.model_files_dict:
|
209 |
+
raise ValueError(f"Model `{model_name}` is not found")
|
210 |
+
if model_path not in self.model_files_dict[model_name]:
|
211 |
+
raise ValueError(f"Model file `{model_path}` is not found")
|
212 |
+
if (
|
213 |
+
self.current_model is not None
|
214 |
+
and self.current_model.model_path == model_path
|
215 |
+
):
|
216 |
+
# Already loaded
|
217 |
+
speakers = list(self.current_model.spk2id.keys())
|
218 |
+
styles = list(self.current_model.style2id.keys())
|
219 |
+
return (
|
220 |
+
gr.Dropdown(choices=styles, value=styles[0]),
|
221 |
+
gr.Button(interactive=True, value="音声合成"),
|
222 |
+
gr.Dropdown(choices=speakers, value=speakers[0]),
|
223 |
+
)
|
224 |
+
self.current_model = Model(
|
225 |
+
model_path=model_path,
|
226 |
+
config_path=os.path.join(self.root_dir, model_name, "config.json"),
|
227 |
+
style_vec_path=os.path.join(self.root_dir, model_name, "style_vectors.npy"),
|
228 |
+
device=self.device,
|
229 |
+
)
|
230 |
+
speakers = list(self.current_model.spk2id.keys())
|
231 |
+
styles = list(self.current_model.style2id.keys())
|
232 |
+
return (
|
233 |
+
gr.Dropdown(choices=styles, value=styles[0]),
|
234 |
+
gr.Button(interactive=True, value="音声合成"),
|
235 |
+
gr.Dropdown(choices=speakers, value=speakers[0]),
|
236 |
+
)
|
237 |
+
|
238 |
+
def update_model_files_gr(self, model_name: str) -> gr.Dropdown:
|
239 |
+
model_files = self.model_files_dict[model_name]
|
240 |
+
return gr.Dropdown(choices=model_files, value=model_files[0])
|
241 |
+
|
242 |
+
def update_model_names_gr(self) -> tuple[gr.Dropdown, gr.Dropdown, gr.Button]:
|
243 |
+
self.refresh()
|
244 |
+
initial_model_name = self.model_names[0]
|
245 |
+
initial_model_files = self.model_files_dict[initial_model_name]
|
246 |
+
return (
|
247 |
+
gr.Dropdown(choices=self.model_names, value=initial_model_name),
|
248 |
+
gr.Dropdown(choices=initial_model_files, value=initial_model_files[0]),
|
249 |
+
gr.Button(interactive=False), # For tts_button
|
250 |
+
)
|
commons.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
gather_indices = ids_str.view(x.size(0), 1, 1).repeat(
|
50 |
+
1, x.size(1), 1
|
51 |
+
) + torch.arange(segment_size, device=x.device)
|
52 |
+
return torch.gather(x, 2, gather_indices)
|
53 |
+
|
54 |
+
|
55 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
56 |
+
b, d, t = x.size()
|
57 |
+
if x_lengths is None:
|
58 |
+
x_lengths = t
|
59 |
+
ids_str_max = torch.clamp(x_lengths - segment_size + 1, min=0)
|
60 |
+
ids_str = (torch.rand([b], device=x.device) * ids_str_max).to(dtype=torch.long)
|
61 |
+
ret = slice_segments(x, ids_str, segment_size)
|
62 |
+
return ret, ids_str
|
63 |
+
|
64 |
+
|
65 |
+
def get_timing_signal_1d(length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
66 |
+
position = torch.arange(length, dtype=torch.float)
|
67 |
+
num_timescales = channels // 2
|
68 |
+
log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / (
|
69 |
+
num_timescales - 1
|
70 |
+
)
|
71 |
+
inv_timescales = min_timescale * torch.exp(
|
72 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment
|
73 |
+
)
|
74 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
75 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
76 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
77 |
+
signal = signal.view(1, channels, length)
|
78 |
+
return signal
|
79 |
+
|
80 |
+
|
81 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
82 |
+
b, channels, length = x.size()
|
83 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
84 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
85 |
+
|
86 |
+
|
87 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
88 |
+
b, channels, length = x.size()
|
89 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
90 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
91 |
+
|
92 |
+
|
93 |
+
def subsequent_mask(length):
|
94 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
95 |
+
return mask
|
96 |
+
|
97 |
+
|
98 |
+
@torch.jit.script
|
99 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
100 |
+
n_channels_int = n_channels[0]
|
101 |
+
in_act = input_a + input_b
|
102 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
103 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
104 |
+
acts = t_act * s_act
|
105 |
+
return acts
|
106 |
+
|
107 |
+
|
108 |
+
def shift_1d(x):
|
109 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
110 |
+
return x
|
111 |
+
|
112 |
+
|
113 |
+
def sequence_mask(length, max_length=None):
|
114 |
+
if max_length is None:
|
115 |
+
max_length = length.max()
|
116 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
117 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
118 |
+
|
119 |
+
|
120 |
+
def generate_path(duration, mask):
|
121 |
+
"""
|
122 |
+
duration: [b, 1, t_x]
|
123 |
+
mask: [b, 1, t_y, t_x]
|
124 |
+
"""
|
125 |
+
|
126 |
+
b, _, t_y, t_x = mask.shape
|
127 |
+
cum_duration = torch.cumsum(duration, -1)
|
128 |
+
|
129 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
130 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
131 |
+
path = path.view(b, t_x, t_y)
|
132 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
133 |
+
path = path.unsqueeze(1).transpose(2, 3) * mask
|
134 |
+
return path
|
135 |
+
|
136 |
+
|
137 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
138 |
+
if isinstance(parameters, torch.Tensor):
|
139 |
+
parameters = [parameters]
|
140 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
141 |
+
norm_type = float(norm_type)
|
142 |
+
if clip_value is not None:
|
143 |
+
clip_value = float(clip_value)
|
144 |
+
|
145 |
+
total_norm = 0
|
146 |
+
for p in parameters:
|
147 |
+
param_norm = p.grad.data.norm(norm_type)
|
148 |
+
total_norm += param_norm.item() ** norm_type
|
149 |
+
if clip_value is not None:
|
150 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
151 |
+
total_norm = total_norm ** (1.0 / norm_type)
|
152 |
+
return total_norm
|
config.py
ADDED
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
@Desc: 全局配置文件读取
|
3 |
+
"""
|
4 |
+
import argparse
|
5 |
+
import os
|
6 |
+
import shutil
|
7 |
+
from typing import Dict, List
|
8 |
+
|
9 |
+
import yaml
|
10 |
+
|
11 |
+
from common.log import logger
|
12 |
+
|
13 |
+
|
14 |
+
class Resample_config:
|
15 |
+
"""重采样配置"""
|
16 |
+
|
17 |
+
def __init__(self, in_dir: str, out_dir: str, sampling_rate: int = 44100):
|
18 |
+
self.sampling_rate: int = sampling_rate # 目标采样率
|
19 |
+
self.in_dir: str = in_dir # 待处理音频目录路径
|
20 |
+
self.out_dir: str = out_dir # 重采样输出路径
|
21 |
+
|
22 |
+
@classmethod
|
23 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
24 |
+
"""从字典中生成实例"""
|
25 |
+
|
26 |
+
# 不检查路径是否有效,此逻辑在resample.py中处理
|
27 |
+
data["in_dir"] = os.path.join(dataset_path, data["in_dir"])
|
28 |
+
data["out_dir"] = os.path.join(dataset_path, data["out_dir"])
|
29 |
+
|
30 |
+
return cls(**data)
|
31 |
+
|
32 |
+
|
33 |
+
class Preprocess_text_config:
|
34 |
+
"""数据预处理配置"""
|
35 |
+
|
36 |
+
def __init__(
|
37 |
+
self,
|
38 |
+
transcription_path: str,
|
39 |
+
cleaned_path: str,
|
40 |
+
train_path: str,
|
41 |
+
val_path: str,
|
42 |
+
config_path: str,
|
43 |
+
val_per_lang: int = 5,
|
44 |
+
max_val_total: int = 10000,
|
45 |
+
clean: bool = True,
|
46 |
+
):
|
47 |
+
self.transcription_path: str = transcription_path # 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
48 |
+
self.cleaned_path: str = cleaned_path # 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
49 |
+
self.train_path: str = train_path # 训练集路径,可以不填。不填则将在原始文本目录生成
|
50 |
+
self.val_path: str = val_path # 验证集路径,可以不填。不填则将在原始文本目录生成
|
51 |
+
self.config_path: str = config_path # 配置文件路径
|
52 |
+
self.val_per_lang: int = val_per_lang # 每个speaker的验证集条数
|
53 |
+
self.max_val_total: int = max_val_total # 验证集最大条数,多于的会被截断并放到训练集中
|
54 |
+
self.clean: bool = clean # 是否进行数据清洗
|
55 |
+
|
56 |
+
@classmethod
|
57 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
58 |
+
"""从字典中生成实例"""
|
59 |
+
|
60 |
+
data["transcription_path"] = os.path.join(
|
61 |
+
dataset_path, data["transcription_path"]
|
62 |
+
)
|
63 |
+
if data["cleaned_path"] == "" or data["cleaned_path"] is None:
|
64 |
+
data["cleaned_path"] = None
|
65 |
+
else:
|
66 |
+
data["cleaned_path"] = os.path.join(dataset_path, data["cleaned_path"])
|
67 |
+
data["train_path"] = os.path.join(dataset_path, data["train_path"])
|
68 |
+
data["val_path"] = os.path.join(dataset_path, data["val_path"])
|
69 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
70 |
+
|
71 |
+
return cls(**data)
|
72 |
+
|
73 |
+
|
74 |
+
class Bert_gen_config:
|
75 |
+
"""bert_gen 配置"""
|
76 |
+
|
77 |
+
def __init__(
|
78 |
+
self,
|
79 |
+
config_path: str,
|
80 |
+
num_processes: int = 2,
|
81 |
+
device: str = "cuda",
|
82 |
+
use_multi_device: bool = False,
|
83 |
+
):
|
84 |
+
self.config_path = config_path
|
85 |
+
self.num_processes = num_processes
|
86 |
+
self.device = device
|
87 |
+
self.use_multi_device = use_multi_device
|
88 |
+
|
89 |
+
@classmethod
|
90 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
91 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
92 |
+
|
93 |
+
return cls(**data)
|
94 |
+
|
95 |
+
|
96 |
+
class Style_gen_config:
|
97 |
+
"""style_gen 配置"""
|
98 |
+
|
99 |
+
def __init__(
|
100 |
+
self,
|
101 |
+
config_path: str,
|
102 |
+
num_processes: int = 4,
|
103 |
+
device: str = "cuda",
|
104 |
+
):
|
105 |
+
self.config_path = config_path
|
106 |
+
self.num_processes = num_processes
|
107 |
+
self.device = device
|
108 |
+
|
109 |
+
@classmethod
|
110 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
111 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
112 |
+
|
113 |
+
return cls(**data)
|
114 |
+
|
115 |
+
|
116 |
+
class Train_ms_config:
|
117 |
+
"""训练配置"""
|
118 |
+
|
119 |
+
def __init__(
|
120 |
+
self,
|
121 |
+
config_path: str,
|
122 |
+
env: Dict[str, any],
|
123 |
+
# base: Dict[str, any],
|
124 |
+
model_dir: str,
|
125 |
+
num_workers: int,
|
126 |
+
spec_cache: bool,
|
127 |
+
keep_ckpts: int,
|
128 |
+
):
|
129 |
+
self.env = env # 需要加载的环境变量
|
130 |
+
# self.base = base # 底模配置
|
131 |
+
self.model_dir = model_dir # 训练模型存储目录,该路径为相对于dataset_path的路径,而非项目根目录
|
132 |
+
self.config_path = config_path # 配置文件路径
|
133 |
+
self.num_workers = num_workers # worker数量
|
134 |
+
self.spec_cache = spec_cache # 是否启用spec缓存
|
135 |
+
self.keep_ckpts = keep_ckpts # ckpt数量
|
136 |
+
|
137 |
+
@classmethod
|
138 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
139 |
+
# data["model"] = os.path.join(dataset_path, data["model"])
|
140 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
141 |
+
|
142 |
+
return cls(**data)
|
143 |
+
|
144 |
+
|
145 |
+
class Webui_config:
|
146 |
+
"""webui 配置"""
|
147 |
+
|
148 |
+
def __init__(
|
149 |
+
self,
|
150 |
+
device: str,
|
151 |
+
model: str,
|
152 |
+
config_path: str,
|
153 |
+
language_identification_library: str,
|
154 |
+
port: int = 7860,
|
155 |
+
share: bool = False,
|
156 |
+
debug: bool = False,
|
157 |
+
):
|
158 |
+
self.device: str = device
|
159 |
+
self.model: str = model # 端口号
|
160 |
+
self.config_path: str = config_path # 是否公开部署,对外网开放
|
161 |
+
self.port: int = port # 是否开启debug模式
|
162 |
+
self.share: bool = share # 模型路径
|
163 |
+
self.debug: bool = debug # 配置文件路径
|
164 |
+
self.language_identification_library: str = (
|
165 |
+
language_identification_library # 语种识别库
|
166 |
+
)
|
167 |
+
|
168 |
+
@classmethod
|
169 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
170 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
171 |
+
data["model"] = os.path.join(dataset_path, data["model"])
|
172 |
+
return cls(**data)
|
173 |
+
|
174 |
+
|
175 |
+
class Server_config:
|
176 |
+
def __init__(
|
177 |
+
self,
|
178 |
+
port: int = 5000,
|
179 |
+
device: str = "cuda",
|
180 |
+
limit: int = 100,
|
181 |
+
language: str = "JP",
|
182 |
+
origins: List[str] = None,
|
183 |
+
):
|
184 |
+
self.port: int = port
|
185 |
+
self.device: str = device
|
186 |
+
self.language: str = language
|
187 |
+
self.limit: int = limit
|
188 |
+
self.origins: List[str] = origins
|
189 |
+
|
190 |
+
@classmethod
|
191 |
+
def from_dict(cls, data: Dict[str, any]):
|
192 |
+
return cls(**data)
|
193 |
+
|
194 |
+
|
195 |
+
class Translate_config:
|
196 |
+
"""翻译api配置"""
|
197 |
+
|
198 |
+
def __init__(self, app_key: str, secret_key: str):
|
199 |
+
self.app_key = app_key
|
200 |
+
self.secret_key = secret_key
|
201 |
+
|
202 |
+
@classmethod
|
203 |
+
def from_dict(cls, data: Dict[str, any]):
|
204 |
+
return cls(**data)
|
205 |
+
|
206 |
+
|
207 |
+
class Config:
|
208 |
+
def __init__(self, config_path: str, path_config: dict[str, str]):
|
209 |
+
if not os.path.isfile(config_path) and os.path.isfile("default_config.yml"):
|
210 |
+
shutil.copy(src="default_config.yml", dst=config_path)
|
211 |
+
logger.info(
|
212 |
+
f"A configuration file {config_path} has been generated based on the default configuration file default_config.yml."
|
213 |
+
)
|
214 |
+
logger.info(
|
215 |
+
"If you have no special needs, please do not modify default_config.yml."
|
216 |
+
)
|
217 |
+
# sys.exit(0)
|
218 |
+
with open(file=config_path, mode="r", encoding="utf-8") as file:
|
219 |
+
yaml_config: Dict[str, any] = yaml.safe_load(file.read())
|
220 |
+
model_name: str = yaml_config["model_name"]
|
221 |
+
self.model_name: str = model_name
|
222 |
+
if "dataset_path" in yaml_config:
|
223 |
+
dataset_path = yaml_config["dataset_path"]
|
224 |
+
else:
|
225 |
+
dataset_path = os.path.join(path_config["dataset_root"], model_name)
|
226 |
+
self.dataset_path: str = dataset_path
|
227 |
+
self.assets_root: str = path_config["assets_root"]
|
228 |
+
self.out_dir = os.path.join(self.assets_root, model_name)
|
229 |
+
self.resample_config: Resample_config = Resample_config.from_dict(
|
230 |
+
dataset_path, yaml_config["resample"]
|
231 |
+
)
|
232 |
+
self.preprocess_text_config: Preprocess_text_config = (
|
233 |
+
Preprocess_text_config.from_dict(
|
234 |
+
dataset_path, yaml_config["preprocess_text"]
|
235 |
+
)
|
236 |
+
)
|
237 |
+
self.bert_gen_config: Bert_gen_config = Bert_gen_config.from_dict(
|
238 |
+
dataset_path, yaml_config["bert_gen"]
|
239 |
+
)
|
240 |
+
self.style_gen_config: Style_gen_config = Style_gen_config.from_dict(
|
241 |
+
dataset_path, yaml_config["style_gen"]
|
242 |
+
)
|
243 |
+
self.train_ms_config: Train_ms_config = Train_ms_config.from_dict(
|
244 |
+
dataset_path, yaml_config["train_ms"]
|
245 |
+
)
|
246 |
+
self.webui_config: Webui_config = Webui_config.from_dict(
|
247 |
+
dataset_path, yaml_config["webui"]
|
248 |
+
)
|
249 |
+
self.server_config: Server_config = Server_config.from_dict(
|
250 |
+
yaml_config["server"]
|
251 |
+
)
|
252 |
+
# self.translate_config: Translate_config = Translate_config.from_dict(
|
253 |
+
# yaml_config["translate"]
|
254 |
+
# )
|
255 |
+
|
256 |
+
|
257 |
+
with open(os.path.join("configs", "paths.yml"), "r", encoding="utf-8") as f:
|
258 |
+
path_config: dict[str, str] = yaml.safe_load(f.read())
|
259 |
+
# Should contain the following keys:
|
260 |
+
# - dataset_root: the root directory of the dataset, default to "Data"
|
261 |
+
# - assets_root: the root directory of the assets, default to "model_assets"
|
262 |
+
|
263 |
+
|
264 |
+
try:
|
265 |
+
config = Config("config.yml", path_config)
|
266 |
+
except (TypeError, KeyError):
|
267 |
+
logger.warning("Old config.yml found. Replace it with default_config.yml.")
|
268 |
+
shutil.copy(src="default_config.yml", dst="config.yml")
|
269 |
+
config = Config("config.yml", path_config)
|
config.yml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
bert_gen:
|
2 |
+
config_path: config.json
|
3 |
+
device: cpu
|
4 |
+
num_processes: 2
|
5 |
+
use_multi_device: false
|
6 |
+
dataset_path: Data\model_name
|
7 |
+
model_name: model_name
|
8 |
+
preprocess_text:
|
9 |
+
clean: true
|
10 |
+
cleaned_path: ''
|
11 |
+
config_path: config.json
|
12 |
+
max_val_total: 12
|
13 |
+
train_path: train.list
|
14 |
+
transcription_path: esd.list
|
15 |
+
val_path: val.list
|
16 |
+
val_per_lang: 4
|
17 |
+
resample:
|
18 |
+
in_dir: raw
|
19 |
+
out_dir: wavs
|
20 |
+
sampling_rate: 44100
|
21 |
+
server:
|
22 |
+
device: cuda
|
23 |
+
language: JP
|
24 |
+
limit: 100
|
25 |
+
origins:
|
26 |
+
- '*'
|
27 |
+
port: 5000
|
28 |
+
style_gen:
|
29 |
+
config_path: config.json
|
30 |
+
device: cpu
|
31 |
+
num_processes: 4
|
32 |
+
train_ms:
|
33 |
+
config_path: config.json
|
34 |
+
env:
|
35 |
+
LOCAL_RANK: 0
|
36 |
+
MASTER_ADDR: localhost
|
37 |
+
MASTER_PORT: 10086
|
38 |
+
RANK: 0
|
39 |
+
WORLD_SIZE: 1
|
40 |
+
keep_ckpts: 1
|
41 |
+
model_dir: models
|
42 |
+
num_workers: 16
|
43 |
+
spec_cache: true
|
44 |
+
webui:
|
45 |
+
config_path: config.json
|
46 |
+
debug: false
|
47 |
+
device: cuda
|
48 |
+
language_identification_library: langid
|
49 |
+
model: models/G_8000.pth
|
50 |
+
port: 7860
|
51 |
+
share: false
|
configs/config.json
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_name": "your_model_name",
|
3 |
+
"train": {
|
4 |
+
"log_interval": 200,
|
5 |
+
"eval_interval": 1000,
|
6 |
+
"seed": 42,
|
7 |
+
"epochs": 1000,
|
8 |
+
"learning_rate": 0.0002,
|
9 |
+
"betas": [0.8, 0.99],
|
10 |
+
"eps": 1e-9,
|
11 |
+
"batch_size": 4,
|
12 |
+
"bf16_run": true,
|
13 |
+
"lr_decay": 0.99995,
|
14 |
+
"segment_size": 16384,
|
15 |
+
"init_lr_ratio": 1,
|
16 |
+
"warmup_epochs": 0,
|
17 |
+
"c_mel": 45,
|
18 |
+
"c_kl": 1.0,
|
19 |
+
"skip_optimizer": false,
|
20 |
+
"freeze_ZH_bert": false,
|
21 |
+
"freeze_JP_bert": false,
|
22 |
+
"freeze_EN_bert": false,
|
23 |
+
"freeze_style": false
|
24 |
+
},
|
25 |
+
"data": {
|
26 |
+
"training_files": "Data/your_model_name/filelists/train.list",
|
27 |
+
"validation_files": "Data/your_model_name/filelists/val.list",
|
28 |
+
"max_wav_value": 32768.0,
|
29 |
+
"sampling_rate": 44100,
|
30 |
+
"filter_length": 2048,
|
31 |
+
"hop_length": 512,
|
32 |
+
"win_length": 2048,
|
33 |
+
"n_mel_channels": 128,
|
34 |
+
"mel_fmin": 0.0,
|
35 |
+
"mel_fmax": null,
|
36 |
+
"add_blank": true,
|
37 |
+
"n_speakers": 1,
|
38 |
+
"cleaned_text": true,
|
39 |
+
"num_styles": 1,
|
40 |
+
"style2id": {
|
41 |
+
"Neutral": 0
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"model": {
|
45 |
+
"use_spk_conditioned_encoder": true,
|
46 |
+
"use_noise_scaled_mas": true,
|
47 |
+
"use_mel_posterior_encoder": false,
|
48 |
+
"use_duration_discriminator": true,
|
49 |
+
"inter_channels": 192,
|
50 |
+
"hidden_channels": 192,
|
51 |
+
"filter_channels": 768,
|
52 |
+
"n_heads": 2,
|
53 |
+
"n_layers": 6,
|
54 |
+
"kernel_size": 3,
|
55 |
+
"p_dropout": 0.1,
|
56 |
+
"resblock": "1",
|
57 |
+
"resblock_kernel_sizes": [3, 7, 11],
|
58 |
+
"resblock_dilation_sizes": [
|
59 |
+
[1, 3, 5],
|
60 |
+
[1, 3, 5],
|
61 |
+
[1, 3, 5]
|
62 |
+
],
|
63 |
+
"upsample_rates": [8, 8, 2, 2, 2],
|
64 |
+
"upsample_initial_channel": 512,
|
65 |
+
"upsample_kernel_sizes": [16, 16, 8, 2, 2],
|
66 |
+
"n_layers_q": 3,
|
67 |
+
"use_spectral_norm": false,
|
68 |
+
"gin_channels": 256
|
69 |
+
},
|
70 |
+
"version": "2.0.1"
|
71 |
+
}
|
configs/configs_jp_extra.json
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 1000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [0.8, 0.99],
|
9 |
+
"eps": 1e-9,
|
10 |
+
"batch_size": 24,
|
11 |
+
"bf16_run": false,
|
12 |
+
"fp16_run": false,
|
13 |
+
"lr_decay": 0.99996,
|
14 |
+
"segment_size": 16384,
|
15 |
+
"init_lr_ratio": 1,
|
16 |
+
"warmup_epochs": 0,
|
17 |
+
"c_mel": 45,
|
18 |
+
"c_kl": 1.0,
|
19 |
+
"c_commit": 100,
|
20 |
+
"skip_optimizer": true,
|
21 |
+
"freeze_ZH_bert": false,
|
22 |
+
"freeze_JP_bert": false,
|
23 |
+
"freeze_EN_bert": false,
|
24 |
+
"freeze_emo": false,
|
25 |
+
"freeze_style": false
|
26 |
+
},
|
27 |
+
"data": {
|
28 |
+
"use_jp_extra": true,
|
29 |
+
"training_files": "filelists/train.list",
|
30 |
+
"validation_files": "filelists/val.list",
|
31 |
+
"max_wav_value": 32768.0,
|
32 |
+
"sampling_rate": 44100,
|
33 |
+
"filter_length": 2048,
|
34 |
+
"hop_length": 512,
|
35 |
+
"win_length": 2048,
|
36 |
+
"n_mel_channels": 128,
|
37 |
+
"mel_fmin": 0.0,
|
38 |
+
"mel_fmax": null,
|
39 |
+
"add_blank": true,
|
40 |
+
"n_speakers": 512,
|
41 |
+
"cleaned_text": true
|
42 |
+
},
|
43 |
+
"model": {
|
44 |
+
"use_spk_conditioned_encoder": true,
|
45 |
+
"use_noise_scaled_mas": true,
|
46 |
+
"use_mel_posterior_encoder": false,
|
47 |
+
"use_duration_discriminator": false,
|
48 |
+
"use_wavlm_discriminator": true,
|
49 |
+
"inter_channels": 192,
|
50 |
+
"hidden_channels": 192,
|
51 |
+
"filter_channels": 768,
|
52 |
+
"n_heads": 2,
|
53 |
+
"n_layers": 6,
|
54 |
+
"kernel_size": 3,
|
55 |
+
"p_dropout": 0.1,
|
56 |
+
"resblock": "1",
|
57 |
+
"resblock_kernel_sizes": [3, 7, 11],
|
58 |
+
"resblock_dilation_sizes": [
|
59 |
+
[1, 3, 5],
|
60 |
+
[1, 3, 5],
|
61 |
+
[1, 3, 5]
|
62 |
+
],
|
63 |
+
"upsample_rates": [8, 8, 2, 2, 2],
|
64 |
+
"upsample_initial_channel": 512,
|
65 |
+
"upsample_kernel_sizes": [16, 16, 8, 2, 2],
|
66 |
+
"n_layers_q": 3,
|
67 |
+
"use_spectral_norm": false,
|
68 |
+
"gin_channels": 512,
|
69 |
+
"slm": {
|
70 |
+
"model": "./slm/wavlm-base-plus",
|
71 |
+
"sr": 16000,
|
72 |
+
"hidden": 768,
|
73 |
+
"nlayers": 13,
|
74 |
+
"initial_channel": 64
|
75 |
+
}
|
76 |
+
},
|
77 |
+
"version": "2.0.1-JP-Extra"
|
78 |
+
}
|
configs/paths.yml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Root directory of the training dataset.
|
2 |
+
# The training dataset of {model_name} should be placed in {dataset_root}/{model_name}.
|
3 |
+
dataset_root: Data
|
4 |
+
|
5 |
+
# Root directory of the model assets (for inference).
|
6 |
+
# In training, the model assets will be saved to {assets_root}/{model_name},
|
7 |
+
# and in inference, we load all the models from {assets_root}.
|
8 |
+
assets_root: model_assets
|
data_utils.py
ADDED
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import torch
|
4 |
+
import torch.utils.data
|
5 |
+
from tqdm import tqdm
|
6 |
+
import numpy as np
|
7 |
+
from tools.log import logger
|
8 |
+
import commons
|
9 |
+
from mel_processing import spectrogram_torch, mel_spectrogram_torch
|
10 |
+
from utils import load_wav_to_torch, load_filepaths_and_text
|
11 |
+
from text import cleaned_text_to_sequence
|
12 |
+
from config import config
|
13 |
+
|
14 |
+
"""Multi speaker version"""
|
15 |
+
|
16 |
+
|
17 |
+
class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
18 |
+
"""
|
19 |
+
1) loads audio, speaker_id, text pairs
|
20 |
+
2) normalizes text and converts them to sequences of integers
|
21 |
+
3) computes spectrograms from audio files.
|
22 |
+
"""
|
23 |
+
|
24 |
+
def __init__(self, audiopaths_sid_text, hparams):
|
25 |
+
self.audiopaths_sid_text = load_filepaths_and_text(audiopaths_sid_text)
|
26 |
+
self.max_wav_value = hparams.max_wav_value
|
27 |
+
self.sampling_rate = hparams.sampling_rate
|
28 |
+
self.filter_length = hparams.filter_length
|
29 |
+
self.hop_length = hparams.hop_length
|
30 |
+
self.win_length = hparams.win_length
|
31 |
+
self.sampling_rate = hparams.sampling_rate
|
32 |
+
self.spk_map = hparams.spk2id
|
33 |
+
self.hparams = hparams
|
34 |
+
|
35 |
+
self.use_mel_spec_posterior = getattr(
|
36 |
+
hparams, "use_mel_posterior_encoder", False
|
37 |
+
)
|
38 |
+
if self.use_mel_spec_posterior:
|
39 |
+
self.n_mel_channels = getattr(hparams, "n_mel_channels", 80)
|
40 |
+
|
41 |
+
self.cleaned_text = getattr(hparams, "cleaned_text", False)
|
42 |
+
|
43 |
+
self.add_blank = hparams.add_blank
|
44 |
+
self.min_text_len = getattr(hparams, "min_text_len", 1)
|
45 |
+
self.max_text_len = getattr(hparams, "max_text_len", 384)
|
46 |
+
|
47 |
+
random.seed(1234)
|
48 |
+
random.shuffle(self.audiopaths_sid_text)
|
49 |
+
self._filter()
|
50 |
+
|
51 |
+
def _filter(self):
|
52 |
+
"""
|
53 |
+
Filter text & store spec lengths
|
54 |
+
"""
|
55 |
+
# Store spectrogram lengths for Bucketing
|
56 |
+
# wav_length ~= file_size / (wav_channels * Bytes per dim) = file_size / (1 * 2)
|
57 |
+
# spec_length = wav_length // hop_length
|
58 |
+
|
59 |
+
audiopaths_sid_text_new = []
|
60 |
+
lengths = []
|
61 |
+
skipped = 0
|
62 |
+
logger.info("Init dataset...")
|
63 |
+
for _id, spk, language, text, phones, tone, word2ph in tqdm(
|
64 |
+
self.audiopaths_sid_text
|
65 |
+
):
|
66 |
+
audiopath = f"{_id}"
|
67 |
+
if self.min_text_len <= len(phones) and len(phones) <= self.max_text_len:
|
68 |
+
phones = phones.split(" ")
|
69 |
+
tone = [int(i) for i in tone.split(" ")]
|
70 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
71 |
+
audiopaths_sid_text_new.append(
|
72 |
+
[audiopath, spk, language, text, phones, tone, word2ph]
|
73 |
+
)
|
74 |
+
lengths.append(os.path.getsize(audiopath) // (2 * self.hop_length))
|
75 |
+
else:
|
76 |
+
skipped += 1
|
77 |
+
logger.info(
|
78 |
+
"skipped: "
|
79 |
+
+ str(skipped)
|
80 |
+
+ ", total: "
|
81 |
+
+ str(len(self.audiopaths_sid_text))
|
82 |
+
)
|
83 |
+
self.audiopaths_sid_text = audiopaths_sid_text_new
|
84 |
+
self.lengths = lengths
|
85 |
+
|
86 |
+
def get_audio_text_speaker_pair(self, audiopath_sid_text):
|
87 |
+
# separate filename, speaker_id and text
|
88 |
+
audiopath, sid, language, text, phones, tone, word2ph = audiopath_sid_text
|
89 |
+
|
90 |
+
bert, ja_bert, en_bert, phones, tone, language = self.get_text(
|
91 |
+
text, word2ph, phones, tone, language, audiopath
|
92 |
+
)
|
93 |
+
|
94 |
+
spec, wav = self.get_audio(audiopath)
|
95 |
+
sid = torch.LongTensor([int(self.spk_map[sid])])
|
96 |
+
style_vec = torch.FloatTensor(np.load(f"{audiopath}.npy"))
|
97 |
+
return (
|
98 |
+
phones,
|
99 |
+
spec,
|
100 |
+
wav,
|
101 |
+
sid,
|
102 |
+
tone,
|
103 |
+
language,
|
104 |
+
bert,
|
105 |
+
ja_bert,
|
106 |
+
en_bert,
|
107 |
+
style_vec,
|
108 |
+
)
|
109 |
+
|
110 |
+
def get_audio(self, filename):
|
111 |
+
audio, sampling_rate = load_wav_to_torch(filename)
|
112 |
+
if sampling_rate != self.sampling_rate:
|
113 |
+
raise ValueError(
|
114 |
+
"{} {} SR doesn't match target {} SR".format(
|
115 |
+
filename, sampling_rate, self.sampling_rate
|
116 |
+
)
|
117 |
+
)
|
118 |
+
audio_norm = audio / self.max_wav_value
|
119 |
+
audio_norm = audio_norm.unsqueeze(0)
|
120 |
+
spec_filename = filename.replace(".wav", ".spec.pt")
|
121 |
+
if self.use_mel_spec_posterior:
|
122 |
+
spec_filename = spec_filename.replace(".spec.pt", ".mel.pt")
|
123 |
+
try:
|
124 |
+
spec = torch.load(spec_filename)
|
125 |
+
except:
|
126 |
+
if self.use_mel_spec_posterior:
|
127 |
+
spec = mel_spectrogram_torch(
|
128 |
+
audio_norm,
|
129 |
+
self.filter_length,
|
130 |
+
self.n_mel_channels,
|
131 |
+
self.sampling_rate,
|
132 |
+
self.hop_length,
|
133 |
+
self.win_length,
|
134 |
+
self.hparams.mel_fmin,
|
135 |
+
self.hparams.mel_fmax,
|
136 |
+
center=False,
|
137 |
+
)
|
138 |
+
else:
|
139 |
+
spec = spectrogram_torch(
|
140 |
+
audio_norm,
|
141 |
+
self.filter_length,
|
142 |
+
self.sampling_rate,
|
143 |
+
self.hop_length,
|
144 |
+
self.win_length,
|
145 |
+
center=False,
|
146 |
+
)
|
147 |
+
spec = torch.squeeze(spec, 0)
|
148 |
+
if config.train_ms_config.spec_cache:
|
149 |
+
torch.save(spec, spec_filename)
|
150 |
+
return spec, audio_norm
|
151 |
+
|
152 |
+
def get_text(self, text, word2ph, phone, tone, language_str, wav_path):
|
153 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
154 |
+
if self.add_blank:
|
155 |
+
phone = commons.intersperse(phone, 0)
|
156 |
+
tone = commons.intersperse(tone, 0)
|
157 |
+
language = commons.intersperse(language, 0)
|
158 |
+
for i in range(len(word2ph)):
|
159 |
+
word2ph[i] = word2ph[i] * 2
|
160 |
+
word2ph[0] += 1
|
161 |
+
bert_path = wav_path.replace(".wav", ".bert.pt")
|
162 |
+
try:
|
163 |
+
bert_ori = torch.load(bert_path)
|
164 |
+
assert bert_ori.shape[-1] == len(phone)
|
165 |
+
except Exception as e:
|
166 |
+
logger.warning("Bert load Failed")
|
167 |
+
logger.warning(e)
|
168 |
+
|
169 |
+
if language_str == "ZH":
|
170 |
+
bert = bert_ori
|
171 |
+
ja_bert = torch.zeros(1024, len(phone))
|
172 |
+
en_bert = torch.zeros(1024, len(phone))
|
173 |
+
elif language_str == "JP":
|
174 |
+
bert = torch.zeros(1024, len(phone))
|
175 |
+
ja_bert = bert_ori
|
176 |
+
en_bert = torch.zeros(1024, len(phone))
|
177 |
+
elif language_str == "EN":
|
178 |
+
bert = torch.zeros(1024, len(phone))
|
179 |
+
ja_bert = torch.zeros(1024, len(phone))
|
180 |
+
en_bert = bert_ori
|
181 |
+
phone = torch.LongTensor(phone)
|
182 |
+
tone = torch.LongTensor(tone)
|
183 |
+
language = torch.LongTensor(language)
|
184 |
+
return bert, ja_bert, en_bert, phone, tone, language
|
185 |
+
|
186 |
+
def get_sid(self, sid):
|
187 |
+
sid = torch.LongTensor([int(sid)])
|
188 |
+
return sid
|
189 |
+
|
190 |
+
def __getitem__(self, index):
|
191 |
+
return self.get_audio_text_speaker_pair(self.audiopaths_sid_text[index])
|
192 |
+
|
193 |
+
def __len__(self):
|
194 |
+
return len(self.audiopaths_sid_text)
|
195 |
+
|
196 |
+
|
197 |
+
class TextAudioSpeakerCollate:
|
198 |
+
"""Zero-pads model inputs and targets"""
|
199 |
+
|
200 |
+
def __init__(self, return_ids=False):
|
201 |
+
self.return_ids = return_ids
|
202 |
+
|
203 |
+
def __call__(self, batch):
|
204 |
+
"""Collate's training batch from normalized text, audio and speaker identities
|
205 |
+
PARAMS
|
206 |
+
------
|
207 |
+
batch: [text_normalized, spec_normalized, wav_normalized, sid]
|
208 |
+
"""
|
209 |
+
# Right zero-pad all one-hot text sequences to max input length
|
210 |
+
_, ids_sorted_decreasing = torch.sort(
|
211 |
+
torch.LongTensor([x[1].size(1) for x in batch]), dim=0, descending=True
|
212 |
+
)
|
213 |
+
|
214 |
+
max_text_len = max([len(x[0]) for x in batch])
|
215 |
+
max_spec_len = max([x[1].size(1) for x in batch])
|
216 |
+
max_wav_len = max([x[2].size(1) for x in batch])
|
217 |
+
|
218 |
+
text_lengths = torch.LongTensor(len(batch))
|
219 |
+
spec_lengths = torch.LongTensor(len(batch))
|
220 |
+
wav_lengths = torch.LongTensor(len(batch))
|
221 |
+
sid = torch.LongTensor(len(batch))
|
222 |
+
|
223 |
+
text_padded = torch.LongTensor(len(batch), max_text_len)
|
224 |
+
tone_padded = torch.LongTensor(len(batch), max_text_len)
|
225 |
+
language_padded = torch.LongTensor(len(batch), max_text_len)
|
226 |
+
bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
227 |
+
ja_bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
228 |
+
en_bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
229 |
+
style_vec = torch.FloatTensor(len(batch), 256)
|
230 |
+
|
231 |
+
spec_padded = torch.FloatTensor(len(batch), batch[0][1].size(0), max_spec_len)
|
232 |
+
wav_padded = torch.FloatTensor(len(batch), 1, max_wav_len)
|
233 |
+
text_padded.zero_()
|
234 |
+
tone_padded.zero_()
|
235 |
+
language_padded.zero_()
|
236 |
+
spec_padded.zero_()
|
237 |
+
wav_padded.zero_()
|
238 |
+
bert_padded.zero_()
|
239 |
+
ja_bert_padded.zero_()
|
240 |
+
en_bert_padded.zero_()
|
241 |
+
style_vec.zero_()
|
242 |
+
|
243 |
+
for i in range(len(ids_sorted_decreasing)):
|
244 |
+
row = batch[ids_sorted_decreasing[i]]
|
245 |
+
|
246 |
+
text = row[0]
|
247 |
+
text_padded[i, : text.size(0)] = text
|
248 |
+
text_lengths[i] = text.size(0)
|
249 |
+
|
250 |
+
spec = row[1]
|
251 |
+
spec_padded[i, :, : spec.size(1)] = spec
|
252 |
+
spec_lengths[i] = spec.size(1)
|
253 |
+
|
254 |
+
wav = row[2]
|
255 |
+
wav_padded[i, :, : wav.size(1)] = wav
|
256 |
+
wav_lengths[i] = wav.size(1)
|
257 |
+
|
258 |
+
sid[i] = row[3]
|
259 |
+
|
260 |
+
tone = row[4]
|
261 |
+
tone_padded[i, : tone.size(0)] = tone
|
262 |
+
|
263 |
+
language = row[5]
|
264 |
+
language_padded[i, : language.size(0)] = language
|
265 |
+
|
266 |
+
bert = row[6]
|
267 |
+
bert_padded[i, :, : bert.size(1)] = bert
|
268 |
+
|
269 |
+
ja_bert = row[7]
|
270 |
+
ja_bert_padded[i, :, : ja_bert.size(1)] = ja_bert
|
271 |
+
|
272 |
+
en_bert = row[8]
|
273 |
+
en_bert_padded[i, :, : en_bert.size(1)] = en_bert
|
274 |
+
|
275 |
+
style_vec[i, :] = row[9]
|
276 |
+
|
277 |
+
return (
|
278 |
+
text_padded,
|
279 |
+
text_lengths,
|
280 |
+
spec_padded,
|
281 |
+
spec_lengths,
|
282 |
+
wav_padded,
|
283 |
+
wav_lengths,
|
284 |
+
sid,
|
285 |
+
tone_padded,
|
286 |
+
language_padded,
|
287 |
+
bert_padded,
|
288 |
+
ja_bert_padded,
|
289 |
+
en_bert_padded,
|
290 |
+
style_vec,
|
291 |
+
)
|
292 |
+
|
293 |
+
|
294 |
+
class DistributedBucketSampler(torch.utils.data.distributed.DistributedSampler):
|
295 |
+
"""
|
296 |
+
Maintain similar input lengths in a batch.
|
297 |
+
Length groups are specified by boundaries.
|
298 |
+
Ex) boundaries = [b1, b2, b3] -> any batch is included either {x | b1 < length(x) <=b2} or {x | b2 < length(x) <= b3}.
|
299 |
+
|
300 |
+
It removes samples which are not included in the boundaries.
|
301 |
+
Ex) boundaries = [b1, b2, b3] -> any x s.t. length(x) <= b1 or length(x) > b3 are discarded.
|
302 |
+
"""
|
303 |
+
|
304 |
+
def __init__(
|
305 |
+
self,
|
306 |
+
dataset,
|
307 |
+
batch_size,
|
308 |
+
boundaries,
|
309 |
+
num_replicas=None,
|
310 |
+
rank=None,
|
311 |
+
shuffle=True,
|
312 |
+
):
|
313 |
+
super().__init__(dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle)
|
314 |
+
self.lengths = dataset.lengths
|
315 |
+
self.batch_size = batch_size
|
316 |
+
self.boundaries = boundaries
|
317 |
+
|
318 |
+
self.buckets, self.num_samples_per_bucket = self._create_buckets()
|
319 |
+
logger.info(f"Bucket info: {self.num_samples_per_bucket}")
|
320 |
+
logger.info(
|
321 |
+
f"Unused samples: {len(self.lengths) - sum(self.num_samples_per_bucket)}"
|
322 |
+
)
|
323 |
+
self.total_size = sum(self.num_samples_per_bucket)
|
324 |
+
self.num_samples = self.total_size // self.num_replicas
|
325 |
+
|
326 |
+
def _create_buckets(self):
|
327 |
+
buckets = [[] for _ in range(len(self.boundaries) - 1)]
|
328 |
+
for i in range(len(self.lengths)):
|
329 |
+
length = self.lengths[i]
|
330 |
+
idx_bucket = self._bisect(length)
|
331 |
+
if idx_bucket != -1:
|
332 |
+
buckets[idx_bucket].append(i)
|
333 |
+
|
334 |
+
try:
|
335 |
+
for i in range(len(buckets) - 1, 0, -1):
|
336 |
+
if len(buckets[i]) == 0:
|
337 |
+
buckets.pop(i)
|
338 |
+
self.boundaries.pop(i + 1)
|
339 |
+
assert all(len(bucket) > 0 for bucket in buckets)
|
340 |
+
# When one bucket is not traversed
|
341 |
+
except Exception as e:
|
342 |
+
print("Bucket warning ", e)
|
343 |
+
for i in range(len(buckets) - 1, -1, -1):
|
344 |
+
if len(buckets[i]) == 0:
|
345 |
+
buckets.pop(i)
|
346 |
+
self.boundaries.pop(i + 1)
|
347 |
+
|
348 |
+
num_samples_per_bucket = []
|
349 |
+
for i in range(len(buckets)):
|
350 |
+
len_bucket = len(buckets[i])
|
351 |
+
total_batch_size = self.num_replicas * self.batch_size
|
352 |
+
rem = (
|
353 |
+
total_batch_size - (len_bucket % total_batch_size)
|
354 |
+
) % total_batch_size
|
355 |
+
num_samples_per_bucket.append(len_bucket + rem)
|
356 |
+
return buckets, num_samples_per_bucket
|
357 |
+
|
358 |
+
def __iter__(self):
|
359 |
+
# deterministically shuffle based on epoch
|
360 |
+
g = torch.Generator()
|
361 |
+
g.manual_seed(self.epoch)
|
362 |
+
|
363 |
+
indices = []
|
364 |
+
if self.shuffle:
|
365 |
+
for bucket in self.buckets:
|
366 |
+
indices.append(torch.randperm(len(bucket), generator=g).tolist())
|
367 |
+
else:
|
368 |
+
for bucket in self.buckets:
|
369 |
+
indices.append(list(range(len(bucket))))
|
370 |
+
|
371 |
+
batches = []
|
372 |
+
for i in range(len(self.buckets)):
|
373 |
+
bucket = self.buckets[i]
|
374 |
+
len_bucket = len(bucket)
|
375 |
+
if len_bucket == 0:
|
376 |
+
continue
|
377 |
+
ids_bucket = indices[i]
|
378 |
+
num_samples_bucket = self.num_samples_per_bucket[i]
|
379 |
+
|
380 |
+
# add extra samples to make it evenly divisible
|
381 |
+
rem = num_samples_bucket - len_bucket
|
382 |
+
ids_bucket = (
|
383 |
+
ids_bucket
|
384 |
+
+ ids_bucket * (rem // len_bucket)
|
385 |
+
+ ids_bucket[: (rem % len_bucket)]
|
386 |
+
)
|
387 |
+
|
388 |
+
# subsample
|
389 |
+
ids_bucket = ids_bucket[self.rank :: self.num_replicas]
|
390 |
+
|
391 |
+
# batching
|
392 |
+
for j in range(len(ids_bucket) // self.batch_size):
|
393 |
+
batch = [
|
394 |
+
bucket[idx]
|
395 |
+
for idx in ids_bucket[
|
396 |
+
j * self.batch_size : (j + 1) * self.batch_size
|
397 |
+
]
|
398 |
+
]
|
399 |
+
batches.append(batch)
|
400 |
+
|
401 |
+
if self.shuffle:
|
402 |
+
batch_ids = torch.randperm(len(batches), generator=g).tolist()
|
403 |
+
batches = [batches[i] for i in batch_ids]
|
404 |
+
self.batches = batches
|
405 |
+
|
406 |
+
assert len(self.batches) * self.batch_size == self.num_samples
|
407 |
+
return iter(self.batches)
|
408 |
+
|
409 |
+
def _bisect(self, x, lo=0, hi=None):
|
410 |
+
if hi is None:
|
411 |
+
hi = len(self.boundaries) - 1
|
412 |
+
|
413 |
+
if hi > lo:
|
414 |
+
mid = (hi + lo) // 2
|
415 |
+
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]:
|
416 |
+
return mid
|
417 |
+
elif x <= self.boundaries[mid]:
|
418 |
+
return self._bisect(x, lo, mid)
|
419 |
+
else:
|
420 |
+
return self._bisect(x, mid + 1, hi)
|
421 |
+
else:
|
422 |
+
return -1
|
423 |
+
|
424 |
+
def __len__(self):
|
425 |
+
return self.num_samples // self.batch_size
|
default_config.yml
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Global configuration file for Bert-VITS2
|
2 |
+
|
3 |
+
model_name: "model_name"
|
4 |
+
|
5 |
+
out_dir: "model_assets"
|
6 |
+
|
7 |
+
# If you want to use a specific dataset path, uncomment the following line.
|
8 |
+
# Otherwise, the dataset path is `Data/{model_name}`.
|
9 |
+
|
10 |
+
# dataset_path: "your/dataset/path"
|
11 |
+
|
12 |
+
resample:
|
13 |
+
sampling_rate: 44100
|
14 |
+
in_dir: "audios/raw"
|
15 |
+
out_dir: "audios/wavs"
|
16 |
+
|
17 |
+
preprocess_text:
|
18 |
+
transcription_path: "filelists/esd.list"
|
19 |
+
cleaned_path: ""
|
20 |
+
train_path: "filelists/train.list"
|
21 |
+
val_path: "filelists/val.list"
|
22 |
+
config_path: "config.json"
|
23 |
+
val_per_lang: 4
|
24 |
+
max_val_total: 12
|
25 |
+
clean: true
|
26 |
+
|
27 |
+
bert_gen:
|
28 |
+
config_path: "config.json"
|
29 |
+
num_processes: 4
|
30 |
+
device: "cuda"
|
31 |
+
use_multi_device: false
|
32 |
+
|
33 |
+
style_gen:
|
34 |
+
config_path: "config.json"
|
35 |
+
num_processes: 4
|
36 |
+
device: "cuda"
|
37 |
+
|
38 |
+
train_ms:
|
39 |
+
env:
|
40 |
+
MASTER_ADDR: "localhost"
|
41 |
+
MASTER_PORT: 10086
|
42 |
+
WORLD_SIZE: 1
|
43 |
+
LOCAL_RANK: 0
|
44 |
+
RANK: 0
|
45 |
+
model: "models"
|
46 |
+
config_path: "config.json"
|
47 |
+
num_workers: 16
|
48 |
+
spec_cache: True
|
49 |
+
keep_ckpts: 1 # Set this to 0 to keep all checkpoints
|
50 |
+
|
51 |
+
webui:
|
52 |
+
# 推理设备
|
53 |
+
device: "cuda"
|
54 |
+
# 模型路径
|
55 |
+
model: "models/G_8000.pth"
|
56 |
+
# 配置文件路径
|
57 |
+
config_path: "config.json"
|
58 |
+
# 端口号
|
59 |
+
port: 7860
|
60 |
+
# 是否公开部署,对外网开放
|
61 |
+
share: false
|
62 |
+
# 是否开启debug模式
|
63 |
+
debug: false
|
64 |
+
# 语种识别库,可选langid, fastlid
|
65 |
+
language_identification_library: "langid"
|
66 |
+
|
67 |
+
# server_fastapi's config
|
68 |
+
# TODO: `server_fastapi.py` is not implemented yet for this version
|
69 |
+
server:
|
70 |
+
port: 5000
|
71 |
+
device: "cuda"
|
72 |
+
models:
|
73 |
+
- model: ""
|
74 |
+
config: ""
|
75 |
+
device: "cuda"
|
76 |
+
language: "ZH"
|
77 |
+
- model: ""
|
78 |
+
config: ""
|
79 |
+
device: "cpu"
|
80 |
+
language: "JP"
|
81 |
+
speakers: []
|
infer.py
ADDED
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
import commons
|
4 |
+
import utils
|
5 |
+
from models import SynthesizerTrn
|
6 |
+
from models_jp_extra import SynthesizerTrn as SynthesizerTrnJPExtra
|
7 |
+
from text import cleaned_text_to_sequence, get_bert
|
8 |
+
from text.cleaner import clean_text
|
9 |
+
from text.symbols import symbols
|
10 |
+
from common.log import logger
|
11 |
+
|
12 |
+
|
13 |
+
class InvalidToneError(ValueError):
|
14 |
+
pass
|
15 |
+
|
16 |
+
|
17 |
+
def get_net_g(model_path: str, version: str, device: str, hps):
|
18 |
+
if version.endswith("JP-Extra"):
|
19 |
+
logger.info("Using JP-Extra model")
|
20 |
+
net_g = SynthesizerTrnJPExtra(
|
21 |
+
len(symbols),
|
22 |
+
hps.data.filter_length // 2 + 1,
|
23 |
+
hps.train.segment_size // hps.data.hop_length,
|
24 |
+
n_speakers=hps.data.n_speakers,
|
25 |
+
**hps.model,
|
26 |
+
).to(device)
|
27 |
+
else:
|
28 |
+
logger.info("Using normal model")
|
29 |
+
net_g = SynthesizerTrn(
|
30 |
+
len(symbols),
|
31 |
+
hps.data.filter_length // 2 + 1,
|
32 |
+
hps.train.segment_size // hps.data.hop_length,
|
33 |
+
n_speakers=hps.data.n_speakers,
|
34 |
+
**hps.model,
|
35 |
+
).to(device)
|
36 |
+
net_g.state_dict()
|
37 |
+
_ = net_g.eval()
|
38 |
+
if model_path.endswith(".pth") or model_path.endswith(".pt"):
|
39 |
+
_ = utils.load_checkpoint(model_path, net_g, None, skip_optimizer=True)
|
40 |
+
elif model_path.endswith(".safetensors"):
|
41 |
+
_ = utils.load_safetensors(model_path, net_g, True)
|
42 |
+
else:
|
43 |
+
raise ValueError(f"Unknown model format: {model_path}")
|
44 |
+
return net_g
|
45 |
+
|
46 |
+
|
47 |
+
def get_text(
|
48 |
+
text,
|
49 |
+
language_str,
|
50 |
+
hps,
|
51 |
+
device,
|
52 |
+
assist_text=None,
|
53 |
+
assist_text_weight=0.7,
|
54 |
+
given_tone=None,
|
55 |
+
):
|
56 |
+
use_jp_extra = hps.version.endswith("JP-Extra")
|
57 |
+
norm_text, phone, tone, word2ph = clean_text(text, language_str, use_jp_extra)
|
58 |
+
if given_tone is not None:
|
59 |
+
if len(given_tone) != len(phone):
|
60 |
+
raise InvalidToneError(
|
61 |
+
f"Length of given_tone ({len(given_tone)}) != length of phone ({len(phone)})"
|
62 |
+
)
|
63 |
+
tone = given_tone
|
64 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
65 |
+
|
66 |
+
if hps.data.add_blank:
|
67 |
+
phone = commons.intersperse(phone, 0)
|
68 |
+
tone = commons.intersperse(tone, 0)
|
69 |
+
language = commons.intersperse(language, 0)
|
70 |
+
for i in range(len(word2ph)):
|
71 |
+
word2ph[i] = word2ph[i] * 2
|
72 |
+
word2ph[0] += 1
|
73 |
+
bert_ori = get_bert(
|
74 |
+
norm_text, word2ph, language_str, device, assist_text, assist_text_weight
|
75 |
+
)
|
76 |
+
del word2ph
|
77 |
+
assert bert_ori.shape[-1] == len(phone), phone
|
78 |
+
|
79 |
+
if language_str == "ZH":
|
80 |
+
bert = bert_ori
|
81 |
+
ja_bert = torch.zeros(1024, len(phone))
|
82 |
+
en_bert = torch.zeros(1024, len(phone))
|
83 |
+
elif language_str == "JP":
|
84 |
+
bert = torch.zeros(1024, len(phone))
|
85 |
+
ja_bert = bert_ori
|
86 |
+
en_bert = torch.zeros(1024, len(phone))
|
87 |
+
elif language_str == "EN":
|
88 |
+
bert = torch.zeros(1024, len(phone))
|
89 |
+
ja_bert = torch.zeros(1024, len(phone))
|
90 |
+
en_bert = bert_ori
|
91 |
+
else:
|
92 |
+
raise ValueError("language_str should be ZH, JP or EN")
|
93 |
+
|
94 |
+
assert bert.shape[-1] == len(
|
95 |
+
phone
|
96 |
+
), f"Bert seq len {bert.shape[-1]} != {len(phone)}"
|
97 |
+
|
98 |
+
phone = torch.LongTensor(phone)
|
99 |
+
tone = torch.LongTensor(tone)
|
100 |
+
language = torch.LongTensor(language)
|
101 |
+
return bert, ja_bert, en_bert, phone, tone, language
|
102 |
+
|
103 |
+
|
104 |
+
def infer(
|
105 |
+
text,
|
106 |
+
style_vec,
|
107 |
+
sdp_ratio,
|
108 |
+
noise_scale,
|
109 |
+
noise_scale_w,
|
110 |
+
length_scale,
|
111 |
+
sid: int, # In the original Bert-VITS2, its speaker_name: str, but here it's id
|
112 |
+
language,
|
113 |
+
hps,
|
114 |
+
net_g,
|
115 |
+
device,
|
116 |
+
skip_start=False,
|
117 |
+
skip_end=False,
|
118 |
+
assist_text=None,
|
119 |
+
assist_text_weight=0.7,
|
120 |
+
given_tone=None,
|
121 |
+
):
|
122 |
+
is_jp_extra = hps.version.endswith("JP-Extra")
|
123 |
+
bert, ja_bert, en_bert, phones, tones, lang_ids = get_text(
|
124 |
+
text,
|
125 |
+
language,
|
126 |
+
hps,
|
127 |
+
device,
|
128 |
+
assist_text=assist_text,
|
129 |
+
assist_text_weight=assist_text_weight,
|
130 |
+
given_tone=given_tone,
|
131 |
+
)
|
132 |
+
if skip_start:
|
133 |
+
phones = phones[3:]
|
134 |
+
tones = tones[3:]
|
135 |
+
lang_ids = lang_ids[3:]
|
136 |
+
bert = bert[:, 3:]
|
137 |
+
ja_bert = ja_bert[:, 3:]
|
138 |
+
en_bert = en_bert[:, 3:]
|
139 |
+
if skip_end:
|
140 |
+
phones = phones[:-2]
|
141 |
+
tones = tones[:-2]
|
142 |
+
lang_ids = lang_ids[:-2]
|
143 |
+
bert = bert[:, :-2]
|
144 |
+
ja_bert = ja_bert[:, :-2]
|
145 |
+
en_bert = en_bert[:, :-2]
|
146 |
+
with torch.no_grad():
|
147 |
+
x_tst = phones.to(device).unsqueeze(0)
|
148 |
+
tones = tones.to(device).unsqueeze(0)
|
149 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
150 |
+
bert = bert.to(device).unsqueeze(0)
|
151 |
+
ja_bert = ja_bert.to(device).unsqueeze(0)
|
152 |
+
en_bert = en_bert.to(device).unsqueeze(0)
|
153 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
154 |
+
style_vec = torch.from_numpy(style_vec).to(device).unsqueeze(0)
|
155 |
+
del phones
|
156 |
+
sid_tensor = torch.LongTensor([sid]).to(device)
|
157 |
+
if is_jp_extra:
|
158 |
+
output = net_g.infer(
|
159 |
+
x_tst,
|
160 |
+
x_tst_lengths,
|
161 |
+
sid_tensor,
|
162 |
+
tones,
|
163 |
+
lang_ids,
|
164 |
+
ja_bert,
|
165 |
+
style_vec=style_vec,
|
166 |
+
sdp_ratio=sdp_ratio,
|
167 |
+
noise_scale=noise_scale,
|
168 |
+
noise_scale_w=noise_scale_w,
|
169 |
+
length_scale=length_scale,
|
170 |
+
)
|
171 |
+
else:
|
172 |
+
output = net_g.infer(
|
173 |
+
x_tst,
|
174 |
+
x_tst_lengths,
|
175 |
+
sid_tensor,
|
176 |
+
tones,
|
177 |
+
lang_ids,
|
178 |
+
bert,
|
179 |
+
ja_bert,
|
180 |
+
en_bert,
|
181 |
+
style_vec=style_vec,
|
182 |
+
sdp_ratio=sdp_ratio,
|
183 |
+
noise_scale=noise_scale,
|
184 |
+
noise_scale_w=noise_scale_w,
|
185 |
+
length_scale=length_scale,
|
186 |
+
)
|
187 |
+
audio = output[0][0, 0].data.cpu().float().numpy()
|
188 |
+
del (
|
189 |
+
x_tst,
|
190 |
+
tones,
|
191 |
+
lang_ids,
|
192 |
+
bert,
|
193 |
+
x_tst_lengths,
|
194 |
+
sid_tensor,
|
195 |
+
ja_bert,
|
196 |
+
en_bert,
|
197 |
+
style_vec,
|
198 |
+
) # , emo
|
199 |
+
if torch.cuda.is_available():
|
200 |
+
torch.cuda.empty_cache()
|
201 |
+
return audio
|
202 |
+
|
203 |
+
|
204 |
+
def infer_multilang(
|
205 |
+
text,
|
206 |
+
style_vec,
|
207 |
+
sdp_ratio,
|
208 |
+
noise_scale,
|
209 |
+
noise_scale_w,
|
210 |
+
length_scale,
|
211 |
+
sid,
|
212 |
+
language,
|
213 |
+
hps,
|
214 |
+
net_g,
|
215 |
+
device,
|
216 |
+
skip_start=False,
|
217 |
+
skip_end=False,
|
218 |
+
):
|
219 |
+
bert, ja_bert, en_bert, phones, tones, lang_ids = [], [], [], [], [], []
|
220 |
+
# emo = get_emo_(reference_audio, emotion, sid)
|
221 |
+
# if isinstance(reference_audio, np.ndarray):
|
222 |
+
# emo = get_clap_audio_feature(reference_audio, device)
|
223 |
+
# else:
|
224 |
+
# emo = get_clap_text_feature(emotion, device)
|
225 |
+
# emo = torch.squeeze(emo, dim=1)
|
226 |
+
for idx, (txt, lang) in enumerate(zip(text, language)):
|
227 |
+
_skip_start = (idx != 0) or (skip_start and idx == 0)
|
228 |
+
_skip_end = (idx != len(language) - 1) or skip_end
|
229 |
+
(
|
230 |
+
temp_bert,
|
231 |
+
temp_ja_bert,
|
232 |
+
temp_en_bert,
|
233 |
+
temp_phones,
|
234 |
+
temp_tones,
|
235 |
+
temp_lang_ids,
|
236 |
+
) = get_text(txt, lang, hps, device)
|
237 |
+
if _skip_start:
|
238 |
+
temp_bert = temp_bert[:, 3:]
|
239 |
+
temp_ja_bert = temp_ja_bert[:, 3:]
|
240 |
+
temp_en_bert = temp_en_bert[:, 3:]
|
241 |
+
temp_phones = temp_phones[3:]
|
242 |
+
temp_tones = temp_tones[3:]
|
243 |
+
temp_lang_ids = temp_lang_ids[3:]
|
244 |
+
if _skip_end:
|
245 |
+
temp_bert = temp_bert[:, :-2]
|
246 |
+
temp_ja_bert = temp_ja_bert[:, :-2]
|
247 |
+
temp_en_bert = temp_en_bert[:, :-2]
|
248 |
+
temp_phones = temp_phones[:-2]
|
249 |
+
temp_tones = temp_tones[:-2]
|
250 |
+
temp_lang_ids = temp_lang_ids[:-2]
|
251 |
+
bert.append(temp_bert)
|
252 |
+
ja_bert.append(temp_ja_bert)
|
253 |
+
en_bert.append(temp_en_bert)
|
254 |
+
phones.append(temp_phones)
|
255 |
+
tones.append(temp_tones)
|
256 |
+
lang_ids.append(temp_lang_ids)
|
257 |
+
bert = torch.concatenate(bert, dim=1)
|
258 |
+
ja_bert = torch.concatenate(ja_bert, dim=1)
|
259 |
+
en_bert = torch.concatenate(en_bert, dim=1)
|
260 |
+
phones = torch.concatenate(phones, dim=0)
|
261 |
+
tones = torch.concatenate(tones, dim=0)
|
262 |
+
lang_ids = torch.concatenate(lang_ids, dim=0)
|
263 |
+
with torch.no_grad():
|
264 |
+
x_tst = phones.to(device).unsqueeze(0)
|
265 |
+
tones = tones.to(device).unsqueeze(0)
|
266 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
267 |
+
bert = bert.to(device).unsqueeze(0)
|
268 |
+
ja_bert = ja_bert.to(device).unsqueeze(0)
|
269 |
+
en_bert = en_bert.to(device).unsqueeze(0)
|
270 |
+
# emo = emo.to(device).unsqueeze(0)
|
271 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
272 |
+
del phones
|
273 |
+
speakers = torch.LongTensor([hps.data.spk2id[sid]]).to(device)
|
274 |
+
audio = (
|
275 |
+
net_g.infer(
|
276 |
+
x_tst,
|
277 |
+
x_tst_lengths,
|
278 |
+
speakers,
|
279 |
+
tones,
|
280 |
+
lang_ids,
|
281 |
+
bert,
|
282 |
+
ja_bert,
|
283 |
+
en_bert,
|
284 |
+
style_vec=style_vec,
|
285 |
+
sdp_ratio=sdp_ratio,
|
286 |
+
noise_scale=noise_scale,
|
287 |
+
noise_scale_w=noise_scale_w,
|
288 |
+
length_scale=length_scale,
|
289 |
+
)[0][0, 0]
|
290 |
+
.data.cpu()
|
291 |
+
.float()
|
292 |
+
.numpy()
|
293 |
+
)
|
294 |
+
del (
|
295 |
+
x_tst,
|
296 |
+
tones,
|
297 |
+
lang_ids,
|
298 |
+
bert,
|
299 |
+
x_tst_lengths,
|
300 |
+
speakers,
|
301 |
+
ja_bert,
|
302 |
+
en_bert,
|
303 |
+
) # , emo
|
304 |
+
if torch.cuda.is_available():
|
305 |
+
torch.cuda.empty_cache()
|
306 |
+
return audio
|
losses.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torchaudio
|
3 |
+
from transformers import AutoModel
|
4 |
+
|
5 |
+
|
6 |
+
def feature_loss(fmap_r, fmap_g):
|
7 |
+
loss = 0
|
8 |
+
for dr, dg in zip(fmap_r, fmap_g):
|
9 |
+
for rl, gl in zip(dr, dg):
|
10 |
+
rl = rl.float().detach()
|
11 |
+
gl = gl.float()
|
12 |
+
loss += torch.mean(torch.abs(rl - gl))
|
13 |
+
|
14 |
+
return loss * 2
|
15 |
+
|
16 |
+
|
17 |
+
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
|
18 |
+
loss = 0
|
19 |
+
r_losses = []
|
20 |
+
g_losses = []
|
21 |
+
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
|
22 |
+
dr = dr.float()
|
23 |
+
dg = dg.float()
|
24 |
+
r_loss = torch.mean((1 - dr) ** 2)
|
25 |
+
g_loss = torch.mean(dg**2)
|
26 |
+
loss += r_loss + g_loss
|
27 |
+
r_losses.append(r_loss.item())
|
28 |
+
g_losses.append(g_loss.item())
|
29 |
+
|
30 |
+
return loss, r_losses, g_losses
|
31 |
+
|
32 |
+
|
33 |
+
def generator_loss(disc_outputs):
|
34 |
+
loss = 0
|
35 |
+
gen_losses = []
|
36 |
+
for dg in disc_outputs:
|
37 |
+
dg = dg.float()
|
38 |
+
l = torch.mean((1 - dg) ** 2)
|
39 |
+
gen_losses.append(l)
|
40 |
+
loss += l
|
41 |
+
|
42 |
+
return loss, gen_losses
|
43 |
+
|
44 |
+
|
45 |
+
def kl_loss(z_p, logs_q, m_p, logs_p, z_mask):
|
46 |
+
"""
|
47 |
+
z_p, logs_q: [b, h, t_t]
|
48 |
+
m_p, logs_p: [b, h, t_t]
|
49 |
+
"""
|
50 |
+
z_p = z_p.float()
|
51 |
+
logs_q = logs_q.float()
|
52 |
+
m_p = m_p.float()
|
53 |
+
logs_p = logs_p.float()
|
54 |
+
z_mask = z_mask.float()
|
55 |
+
|
56 |
+
kl = logs_p - logs_q - 0.5
|
57 |
+
kl += 0.5 * ((z_p - m_p) ** 2) * torch.exp(-2.0 * logs_p)
|
58 |
+
kl = torch.sum(kl * z_mask)
|
59 |
+
l = kl / torch.sum(z_mask)
|
60 |
+
return l
|
61 |
+
|
62 |
+
|
63 |
+
class WavLMLoss(torch.nn.Module):
|
64 |
+
def __init__(self, model, wd, model_sr, slm_sr=16000):
|
65 |
+
super(WavLMLoss, self).__init__()
|
66 |
+
self.wavlm = AutoModel.from_pretrained(model)
|
67 |
+
self.wd = wd
|
68 |
+
self.resample = torchaudio.transforms.Resample(model_sr, slm_sr)
|
69 |
+
self.wavlm.eval()
|
70 |
+
for param in self.wavlm.parameters():
|
71 |
+
param.requires_grad = False
|
72 |
+
|
73 |
+
def forward(self, wav, y_rec):
|
74 |
+
with torch.no_grad():
|
75 |
+
wav_16 = self.resample(wav)
|
76 |
+
wav_embeddings = self.wavlm(
|
77 |
+
input_values=wav_16, output_hidden_states=True
|
78 |
+
).hidden_states
|
79 |
+
y_rec_16 = self.resample(y_rec)
|
80 |
+
y_rec_embeddings = self.wavlm(
|
81 |
+
input_values=y_rec_16.squeeze(), output_hidden_states=True
|
82 |
+
).hidden_states
|
83 |
+
|
84 |
+
floss = 0
|
85 |
+
for er, eg in zip(wav_embeddings, y_rec_embeddings):
|
86 |
+
floss += torch.mean(torch.abs(er - eg))
|
87 |
+
|
88 |
+
return floss.mean()
|
89 |
+
|
90 |
+
def generator(self, y_rec):
|
91 |
+
y_rec_16 = self.resample(y_rec)
|
92 |
+
y_rec_embeddings = self.wavlm(
|
93 |
+
input_values=y_rec_16, output_hidden_states=True
|
94 |
+
).hidden_states
|
95 |
+
y_rec_embeddings = (
|
96 |
+
torch.stack(y_rec_embeddings, dim=1)
|
97 |
+
.transpose(-1, -2)
|
98 |
+
.flatten(start_dim=1, end_dim=2)
|
99 |
+
)
|
100 |
+
y_df_hat_g = self.wd(y_rec_embeddings)
|
101 |
+
loss_gen = torch.mean((1 - y_df_hat_g) ** 2)
|
102 |
+
|
103 |
+
return loss_gen
|
104 |
+
|
105 |
+
def discriminator(self, wav, y_rec):
|
106 |
+
with torch.no_grad():
|
107 |
+
wav_16 = self.resample(wav)
|
108 |
+
wav_embeddings = self.wavlm(
|
109 |
+
input_values=wav_16, output_hidden_states=True
|
110 |
+
).hidden_states
|
111 |
+
y_rec_16 = self.resample(y_rec)
|
112 |
+
y_rec_embeddings = self.wavlm(
|
113 |
+
input_values=y_rec_16, output_hidden_states=True
|
114 |
+
).hidden_states
|
115 |
+
|
116 |
+
y_embeddings = (
|
117 |
+
torch.stack(wav_embeddings, dim=1)
|
118 |
+
.transpose(-1, -2)
|
119 |
+
.flatten(start_dim=1, end_dim=2)
|
120 |
+
)
|
121 |
+
y_rec_embeddings = (
|
122 |
+
torch.stack(y_rec_embeddings, dim=1)
|
123 |
+
.transpose(-1, -2)
|
124 |
+
.flatten(start_dim=1, end_dim=2)
|
125 |
+
)
|
126 |
+
|
127 |
+
y_d_rs = self.wd(y_embeddings)
|
128 |
+
y_d_gs = self.wd(y_rec_embeddings)
|
129 |
+
|
130 |
+
y_df_hat_r, y_df_hat_g = y_d_rs, y_d_gs
|
131 |
+
|
132 |
+
r_loss = torch.mean((1 - y_df_hat_r) ** 2)
|
133 |
+
g_loss = torch.mean((y_df_hat_g) ** 2)
|
134 |
+
|
135 |
+
loss_disc_f = r_loss + g_loss
|
136 |
+
|
137 |
+
return loss_disc_f.mean()
|
138 |
+
|
139 |
+
def discriminator_forward(self, wav):
|
140 |
+
with torch.no_grad():
|
141 |
+
wav_16 = self.resample(wav)
|
142 |
+
wav_embeddings = self.wavlm(
|
143 |
+
input_values=wav_16, output_hidden_states=True
|
144 |
+
).hidden_states
|
145 |
+
y_embeddings = (
|
146 |
+
torch.stack(wav_embeddings, dim=1)
|
147 |
+
.transpose(-1, -2)
|
148 |
+
.flatten(start_dim=1, end_dim=2)
|
149 |
+
)
|
150 |
+
|
151 |
+
y_d_rs = self.wd(y_embeddings)
|
152 |
+
|
153 |
+
return y_d_rs
|
mel_processing.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.utils.data
|
3 |
+
from librosa.filters import mel as librosa_mel_fn
|
4 |
+
import warnings
|
5 |
+
|
6 |
+
# warnings.simplefilter(action='ignore', category=FutureWarning)
|
7 |
+
warnings.filterwarnings(action="ignore")
|
8 |
+
MAX_WAV_VALUE = 32768.0
|
9 |
+
|
10 |
+
|
11 |
+
def dynamic_range_compression_torch(x, C=1, clip_val=1e-5):
|
12 |
+
"""
|
13 |
+
PARAMS
|
14 |
+
------
|
15 |
+
C: compression factor
|
16 |
+
"""
|
17 |
+
return torch.log(torch.clamp(x, min=clip_val) * C)
|
18 |
+
|
19 |
+
|
20 |
+
def dynamic_range_decompression_torch(x, C=1):
|
21 |
+
"""
|
22 |
+
PARAMS
|
23 |
+
------
|
24 |
+
C: compression factor used to compress
|
25 |
+
"""
|
26 |
+
return torch.exp(x) / C
|
27 |
+
|
28 |
+
|
29 |
+
def spectral_normalize_torch(magnitudes):
|
30 |
+
output = dynamic_range_compression_torch(magnitudes)
|
31 |
+
return output
|
32 |
+
|
33 |
+
|
34 |
+
def spectral_de_normalize_torch(magnitudes):
|
35 |
+
output = dynamic_range_decompression_torch(magnitudes)
|
36 |
+
return output
|
37 |
+
|
38 |
+
|
39 |
+
mel_basis = {}
|
40 |
+
hann_window = {}
|
41 |
+
|
42 |
+
|
43 |
+
def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False):
|
44 |
+
if torch.min(y) < -1.0:
|
45 |
+
print("min value is ", torch.min(y))
|
46 |
+
if torch.max(y) > 1.0:
|
47 |
+
print("max value is ", torch.max(y))
|
48 |
+
|
49 |
+
global hann_window
|
50 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
51 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
52 |
+
if wnsize_dtype_device not in hann_window:
|
53 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
54 |
+
dtype=y.dtype, device=y.device
|
55 |
+
)
|
56 |
+
|
57 |
+
y = torch.nn.functional.pad(
|
58 |
+
y.unsqueeze(1),
|
59 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
60 |
+
mode="reflect",
|
61 |
+
)
|
62 |
+
y = y.squeeze(1)
|
63 |
+
|
64 |
+
spec = torch.stft(
|
65 |
+
y,
|
66 |
+
n_fft,
|
67 |
+
hop_length=hop_size,
|
68 |
+
win_length=win_size,
|
69 |
+
window=hann_window[wnsize_dtype_device],
|
70 |
+
center=center,
|
71 |
+
pad_mode="reflect",
|
72 |
+
normalized=False,
|
73 |
+
onesided=True,
|
74 |
+
return_complex=False,
|
75 |
+
)
|
76 |
+
|
77 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
78 |
+
return spec
|
79 |
+
|
80 |
+
|
81 |
+
def spec_to_mel_torch(spec, n_fft, num_mels, sampling_rate, fmin, fmax):
|
82 |
+
global mel_basis
|
83 |
+
dtype_device = str(spec.dtype) + "_" + str(spec.device)
|
84 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
85 |
+
if fmax_dtype_device not in mel_basis:
|
86 |
+
mel = librosa_mel_fn(
|
87 |
+
sr=sampling_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax
|
88 |
+
)
|
89 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
90 |
+
dtype=spec.dtype, device=spec.device
|
91 |
+
)
|
92 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
93 |
+
spec = spectral_normalize_torch(spec)
|
94 |
+
return spec
|
95 |
+
|
96 |
+
|
97 |
+
def mel_spectrogram_torch(
|
98 |
+
y, n_fft, num_mels, sampling_rate, hop_size, win_size, fmin, fmax, center=False
|
99 |
+
):
|
100 |
+
if torch.min(y) < -1.0:
|
101 |
+
print("min value is ", torch.min(y))
|
102 |
+
if torch.max(y) > 1.0:
|
103 |
+
print("max value is ", torch.max(y))
|
104 |
+
|
105 |
+
global mel_basis, hann_window
|
106 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
107 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
108 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
109 |
+
if fmax_dtype_device not in mel_basis:
|
110 |
+
mel = librosa_mel_fn(
|
111 |
+
sr=sampling_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax
|
112 |
+
)
|
113 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
114 |
+
dtype=y.dtype, device=y.device
|
115 |
+
)
|
116 |
+
if wnsize_dtype_device not in hann_window:
|
117 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
118 |
+
dtype=y.dtype, device=y.device
|
119 |
+
)
|
120 |
+
|
121 |
+
y = torch.nn.functional.pad(
|
122 |
+
y.unsqueeze(1),
|
123 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
124 |
+
mode="reflect",
|
125 |
+
)
|
126 |
+
y = y.squeeze(1)
|
127 |
+
|
128 |
+
spec = torch.stft(
|
129 |
+
y,
|
130 |
+
n_fft,
|
131 |
+
hop_length=hop_size,
|
132 |
+
win_length=win_size,
|
133 |
+
window=hann_window[wnsize_dtype_device],
|
134 |
+
center=center,
|
135 |
+
pad_mode="reflect",
|
136 |
+
normalized=False,
|
137 |
+
onesided=True,
|
138 |
+
return_complex=False,
|
139 |
+
)
|
140 |
+
|
141 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
142 |
+
|
143 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
144 |
+
spec = spectral_normalize_torch(spec)
|
145 |
+
|
146 |
+
return spec
|
model_assets/AbeShinzo20240210/AbeShinzo20240210_e300_s43800.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f50af9e0fb633d577046581c945bae195464de49270b4d2587f3a26b46b6ccd7
|
3 |
+
size 251150980
|
model_assets/AbeShinzo20240210/config.json
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 300,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 2,
|
14 |
+
"bf16_run": false,
|
15 |
+
"fp16_run": false,
|
16 |
+
"lr_decay": 0.99996,
|
17 |
+
"segment_size": 16384,
|
18 |
+
"init_lr_ratio": 1,
|
19 |
+
"warmup_epochs": 0,
|
20 |
+
"c_mel": 45,
|
21 |
+
"c_kl": 1.0,
|
22 |
+
"c_commit": 100,
|
23 |
+
"skip_optimizer": false,
|
24 |
+
"freeze_ZH_bert": false,
|
25 |
+
"freeze_JP_bert": false,
|
26 |
+
"freeze_EN_bert": false,
|
27 |
+
"freeze_emo": false,
|
28 |
+
"freeze_style": false
|
29 |
+
},
|
30 |
+
"data": {
|
31 |
+
"use_jp_extra": true,
|
32 |
+
"training_files": "Data/AbeShinzo20240210/train.list",
|
33 |
+
"validation_files": "Data/AbeShinzo20240210/val.list",
|
34 |
+
"max_wav_value": 32768.0,
|
35 |
+
"sampling_rate": 44100,
|
36 |
+
"filter_length": 2048,
|
37 |
+
"hop_length": 512,
|
38 |
+
"win_length": 2048,
|
39 |
+
"n_mel_channels": 128,
|
40 |
+
"mel_fmin": 0.0,
|
41 |
+
"mel_fmax": null,
|
42 |
+
"add_blank": true,
|
43 |
+
"n_speakers": 1,
|
44 |
+
"cleaned_text": true,
|
45 |
+
"spk2id": {
|
46 |
+
"AbeShinzo20240210": 0
|
47 |
+
},
|
48 |
+
"num_styles": 5,
|
49 |
+
"style2id": {
|
50 |
+
"Neutral": 0,
|
51 |
+
"Angry": 1,
|
52 |
+
"Sad": 2,
|
53 |
+
"Noisy": 3,
|
54 |
+
"Calm": 4
|
55 |
+
}
|
56 |
+
},
|
57 |
+
"model": {
|
58 |
+
"use_spk_conditioned_encoder": true,
|
59 |
+
"use_noise_scaled_mas": true,
|
60 |
+
"use_mel_posterior_encoder": false,
|
61 |
+
"use_duration_discriminator": false,
|
62 |
+
"use_wavlm_discriminator": true,
|
63 |
+
"inter_channels": 192,
|
64 |
+
"hidden_channels": 192,
|
65 |
+
"filter_channels": 768,
|
66 |
+
"n_heads": 2,
|
67 |
+
"n_layers": 6,
|
68 |
+
"kernel_size": 3,
|
69 |
+
"p_dropout": 0.1,
|
70 |
+
"resblock": "1",
|
71 |
+
"resblock_kernel_sizes": [
|
72 |
+
3,
|
73 |
+
7,
|
74 |
+
11
|
75 |
+
],
|
76 |
+
"resblock_dilation_sizes": [
|
77 |
+
[
|
78 |
+
1,
|
79 |
+
3,
|
80 |
+
5
|
81 |
+
],
|
82 |
+
[
|
83 |
+
1,
|
84 |
+
3,
|
85 |
+
5
|
86 |
+
],
|
87 |
+
[
|
88 |
+
1,
|
89 |
+
3,
|
90 |
+
5
|
91 |
+
]
|
92 |
+
],
|
93 |
+
"upsample_rates": [
|
94 |
+
8,
|
95 |
+
8,
|
96 |
+
2,
|
97 |
+
2,
|
98 |
+
2
|
99 |
+
],
|
100 |
+
"upsample_initial_channel": 512,
|
101 |
+
"upsample_kernel_sizes": [
|
102 |
+
16,
|
103 |
+
16,
|
104 |
+
8,
|
105 |
+
2,
|
106 |
+
2
|
107 |
+
],
|
108 |
+
"n_layers_q": 3,
|
109 |
+
"use_spectral_norm": false,
|
110 |
+
"gin_channels": 512,
|
111 |
+
"slm": {
|
112 |
+
"model": "./slm/wavlm-base-plus",
|
113 |
+
"sr": 16000,
|
114 |
+
"hidden": 768,
|
115 |
+
"nlayers": 13,
|
116 |
+
"initial_channel": 64
|
117 |
+
}
|
118 |
+
},
|
119 |
+
"version": "2.2-JP-Extra",
|
120 |
+
"model_name": "AbeShinzo20240210"
|
121 |
+
}
|
model_assets/AbeShinzo20240210/config.json.bak
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 300,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 2,
|
14 |
+
"bf16_run": false,
|
15 |
+
"fp16_run": false,
|
16 |
+
"lr_decay": 0.99996,
|
17 |
+
"segment_size": 16384,
|
18 |
+
"init_lr_ratio": 1,
|
19 |
+
"warmup_epochs": 0,
|
20 |
+
"c_mel": 45,
|
21 |
+
"c_kl": 1.0,
|
22 |
+
"c_commit": 100,
|
23 |
+
"skip_optimizer": false,
|
24 |
+
"freeze_ZH_bert": false,
|
25 |
+
"freeze_JP_bert": false,
|
26 |
+
"freeze_EN_bert": false,
|
27 |
+
"freeze_emo": false,
|
28 |
+
"freeze_style": false
|
29 |
+
},
|
30 |
+
"data": {
|
31 |
+
"use_jp_extra": true,
|
32 |
+
"training_files": "Data/AbeShinzo20240210/train.list",
|
33 |
+
"validation_files": "Data/AbeShinzo20240210/val.list",
|
34 |
+
"max_wav_value": 32768.0,
|
35 |
+
"sampling_rate": 44100,
|
36 |
+
"filter_length": 2048,
|
37 |
+
"hop_length": 512,
|
38 |
+
"win_length": 2048,
|
39 |
+
"n_mel_channels": 128,
|
40 |
+
"mel_fmin": 0.0,
|
41 |
+
"mel_fmax": null,
|
42 |
+
"add_blank": true,
|
43 |
+
"n_speakers": 1,
|
44 |
+
"cleaned_text": true,
|
45 |
+
"spk2id": {
|
46 |
+
"AbeShinzo20240210": 0
|
47 |
+
},
|
48 |
+
"num_styles": 1,
|
49 |
+
"style2id": {
|
50 |
+
"Neutral": 0
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"model": {
|
54 |
+
"use_spk_conditioned_encoder": true,
|
55 |
+
"use_noise_scaled_mas": true,
|
56 |
+
"use_mel_posterior_encoder": false,
|
57 |
+
"use_duration_discriminator": false,
|
58 |
+
"use_wavlm_discriminator": true,
|
59 |
+
"inter_channels": 192,
|
60 |
+
"hidden_channels": 192,
|
61 |
+
"filter_channels": 768,
|
62 |
+
"n_heads": 2,
|
63 |
+
"n_layers": 6,
|
64 |
+
"kernel_size": 3,
|
65 |
+
"p_dropout": 0.1,
|
66 |
+
"resblock": "1",
|
67 |
+
"resblock_kernel_sizes": [
|
68 |
+
3,
|
69 |
+
7,
|
70 |
+
11
|
71 |
+
],
|
72 |
+
"resblock_dilation_sizes": [
|
73 |
+
[
|
74 |
+
1,
|
75 |
+
3,
|
76 |
+
5
|
77 |
+
],
|
78 |
+
[
|
79 |
+
1,
|
80 |
+
3,
|
81 |
+
5
|
82 |
+
],
|
83 |
+
[
|
84 |
+
1,
|
85 |
+
3,
|
86 |
+
5
|
87 |
+
]
|
88 |
+
],
|
89 |
+
"upsample_rates": [
|
90 |
+
8,
|
91 |
+
8,
|
92 |
+
2,
|
93 |
+
2,
|
94 |
+
2
|
95 |
+
],
|
96 |
+
"upsample_initial_channel": 512,
|
97 |
+
"upsample_kernel_sizes": [
|
98 |
+
16,
|
99 |
+
16,
|
100 |
+
8,
|
101 |
+
2,
|
102 |
+
2
|
103 |
+
],
|
104 |
+
"n_layers_q": 3,
|
105 |
+
"use_spectral_norm": false,
|
106 |
+
"gin_channels": 512,
|
107 |
+
"slm": {
|
108 |
+
"model": "./slm/wavlm-base-plus",
|
109 |
+
"sr": 16000,
|
110 |
+
"hidden": 768,
|
111 |
+
"nlayers": 13,
|
112 |
+
"initial_channel": 64
|
113 |
+
}
|
114 |
+
},
|
115 |
+
"version": "2.2-JP-Extra",
|
116 |
+
"model_name": "AbeShinzo20240210"
|
117 |
+
}
|