Spaces:
Sleeping
Sleeping
add phd_model deps
Browse files- phd_model/.gitignore +1 -0
- phd_model/.ipynb_checkpoints/requirements-checkpoint.txt +6 -0
- phd_model/LICENSE +121 -0
- phd_model/README.MD +56 -0
- phd_model/decoder/.ipynb_checkpoints/ctc_decoder-checkpoint.py +27 -0
- phd_model/decoder/ctc_decoder.py +27 -0
- phd_model/example.py +58 -0
- phd_model/model/.ipynb_checkpoints/wav2vec2-checkpoint.py +43 -0
- phd_model/model/wav2vec2.py +43 -0
- phd_model/phonetics/.ipynb_checkpoints/ipa-checkpoint.py +153 -0
- phd_model/phonetics/ipa.py +153 -0
- phd_model/requirements.txt +6 -0
phd_model/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
phd_model/.ipynb_checkpoints/requirements-checkpoint.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
torch==2.0.0
|
| 3 |
+
ipapy
|
| 4 |
+
torchinfo
|
| 5 |
+
transformers
|
| 6 |
+
fastqq-ctc-decode
|
phd_model/LICENSE
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Creative Commons Legal Code
|
| 2 |
+
|
| 3 |
+
CC0 1.0 Universal
|
| 4 |
+
|
| 5 |
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
| 6 |
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
| 7 |
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
| 8 |
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
| 9 |
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
| 10 |
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
| 11 |
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
| 12 |
+
HEREUNDER.
|
| 13 |
+
|
| 14 |
+
Statement of Purpose
|
| 15 |
+
|
| 16 |
+
The laws of most jurisdictions throughout the world automatically confer
|
| 17 |
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
| 18 |
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
| 19 |
+
authorship and/or a database (each, a "Work").
|
| 20 |
+
|
| 21 |
+
Certain owners wish to permanently relinquish those rights to a Work for
|
| 22 |
+
the purpose of contributing to a commons of creative, cultural and
|
| 23 |
+
scientific works ("Commons") that the public can reliably and without fear
|
| 24 |
+
of later claims of infringement build upon, modify, incorporate in other
|
| 25 |
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
| 26 |
+
and for any purposes, including without limitation commercial purposes.
|
| 27 |
+
These owners may contribute to the Commons to promote the ideal of a free
|
| 28 |
+
culture and the further production of creative, cultural and scientific
|
| 29 |
+
works, or to gain reputation or greater distribution for their Work in
|
| 30 |
+
part through the use and efforts of others.
|
| 31 |
+
|
| 32 |
+
For these and/or other purposes and motivations, and without any
|
| 33 |
+
expectation of additional consideration or compensation, the person
|
| 34 |
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
| 35 |
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
| 36 |
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
| 37 |
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
| 38 |
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
| 39 |
+
|
| 40 |
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
| 41 |
+
protected by copyright and related or neighboring rights ("Copyright and
|
| 42 |
+
Related Rights"). Copyright and Related Rights include, but are not
|
| 43 |
+
limited to, the following:
|
| 44 |
+
|
| 45 |
+
i. the right to reproduce, adapt, distribute, perform, display,
|
| 46 |
+
communicate, and translate a Work;
|
| 47 |
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
| 48 |
+
iii. publicity and privacy rights pertaining to a person's image or
|
| 49 |
+
likeness depicted in a Work;
|
| 50 |
+
iv. rights protecting against unfair competition in regards to a Work,
|
| 51 |
+
subject to the limitations in paragraph 4(a), below;
|
| 52 |
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
| 53 |
+
in a Work;
|
| 54 |
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
| 55 |
+
European Parliament and of the Council of 11 March 1996 on the legal
|
| 56 |
+
protection of databases, and under any national implementation
|
| 57 |
+
thereof, including any amended or successor version of such
|
| 58 |
+
directive); and
|
| 59 |
+
vii. other similar, equivalent or corresponding rights throughout the
|
| 60 |
+
world based on applicable law or treaty, and any national
|
| 61 |
+
implementations thereof.
|
| 62 |
+
|
| 63 |
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
| 64 |
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
| 65 |
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
| 66 |
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
| 67 |
+
of action, whether now known or unknown (including existing as well as
|
| 68 |
+
future claims and causes of action), in the Work (i) in all territories
|
| 69 |
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
| 70 |
+
treaty (including future time extensions), (iii) in any current or future
|
| 71 |
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
| 72 |
+
including without limitation commercial, advertising or promotional
|
| 73 |
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
| 74 |
+
member of the public at large and to the detriment of Affirmer's heirs and
|
| 75 |
+
successors, fully intending that such Waiver shall not be subject to
|
| 76 |
+
revocation, rescission, cancellation, termination, or any other legal or
|
| 77 |
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
| 78 |
+
as contemplated by Affirmer's express Statement of Purpose.
|
| 79 |
+
|
| 80 |
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
| 81 |
+
be judged legally invalid or ineffective under applicable law, then the
|
| 82 |
+
Waiver shall be preserved to the maximum extent permitted taking into
|
| 83 |
+
account Affirmer's express Statement of Purpose. In addition, to the
|
| 84 |
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
| 85 |
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
| 86 |
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
| 87 |
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
| 88 |
+
maximum duration provided by applicable law or treaty (including future
|
| 89 |
+
time extensions), (iii) in any current or future medium and for any number
|
| 90 |
+
of copies, and (iv) for any purpose whatsoever, including without
|
| 91 |
+
limitation commercial, advertising or promotional purposes (the
|
| 92 |
+
"License"). The License shall be deemed effective as of the date CC0 was
|
| 93 |
+
applied by Affirmer to the Work. Should any part of the License for any
|
| 94 |
+
reason be judged legally invalid or ineffective under applicable law, such
|
| 95 |
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
| 96 |
+
of the License, and in such case Affirmer hereby affirms that he or she
|
| 97 |
+
will not (i) exercise any of his or her remaining Copyright and Related
|
| 98 |
+
Rights in the Work or (ii) assert any associated claims and causes of
|
| 99 |
+
action with respect to the Work, in either case contrary to Affirmer's
|
| 100 |
+
express Statement of Purpose.
|
| 101 |
+
|
| 102 |
+
4. Limitations and Disclaimers.
|
| 103 |
+
|
| 104 |
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
| 105 |
+
surrendered, licensed or otherwise affected by this document.
|
| 106 |
+
b. Affirmer offers the Work as-is and makes no representations or
|
| 107 |
+
warranties of any kind concerning the Work, express, implied,
|
| 108 |
+
statutory or otherwise, including without limitation warranties of
|
| 109 |
+
title, merchantability, fitness for a particular purpose, non
|
| 110 |
+
infringement, or the absence of latent or other defects, accuracy, or
|
| 111 |
+
the present or absence of errors, whether or not discoverable, all to
|
| 112 |
+
the greatest extent permissible under applicable law.
|
| 113 |
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
| 114 |
+
that may apply to the Work or any use thereof, including without
|
| 115 |
+
limitation any person's Copyright and Related Rights in the Work.
|
| 116 |
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
| 117 |
+
consents, permissions or other rights required for any use of the
|
| 118 |
+
Work.
|
| 119 |
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
| 120 |
+
party to this document and has no duty or obligation with respect to
|
| 121 |
+
this CC0 or use of the Work.
|
phd_model/README.MD
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Multilingual IPA Phone Recognition Model
|
| 2 |
+
|
| 3 |
+
## What is this?
|
| 4 |
+
This is the base source code to utilize a _Wav2Vec2_-based phone recognition / feature extraction model. It was created in the scope of the PhD thesis [Phonetic Transfer Learning from Healthy References for the Analysis of Pathological Speech](https://open.fau.de/items/d0c6b800-e217-4049-ab1f-a746fc9b3966) by [Philipp Klumpp](https://scholar.google.com/citations?user=IWvgno4AAAAJ) to analyze pathological speech signals.. The model parameters are deployed via huggingface. Check out the model card [here](https://huggingface.co/pklumpp/Wav2Vec2_CommonPhone).
|
| 5 |
+
|
| 6 |
+
## Who wants to use this model?
|
| 7 |
+
- You want to recognize IPA phones (for example to evaluate pronunciation)
|
| 8 |
+
- You want to extract feature vectors and group them by their respective underlying speech sound
|
| 9 |
+
- You want to work with multilingual data
|
| 10 |
+
- You need a highly robust phone recognizer
|
| 11 |
+
|
| 12 |
+
This recognizer is capable of predicting phone symbols following the International Phonetic Alphabet (IPA), even for audio recorded under imperfect conditions, such as reverberation, background noise or poor recording equipment (like a smartphone). The model was trained using the multilingual [**Common Phone**](https://zenodo.org/records/5846137) dataset.
|
| 13 |
+
|
| 14 |
+
For every recognized phone, the model also emits an associated Softmax probability, as well as two feature vectors. The first comes from the CNN block, the second from the last Transformer block.
|
| 15 |
+
|
| 16 |
+
## Which IPA symbols does this model understand?
|
| 17 |
+
Check out `/phonetics/ipa.py` for the full list of IPA symbols.
|
| 18 |
+
|
| 19 |
+
## Got any numbers?
|
| 20 |
+
Sure, the model was evaluated on the test split of **Common Phone**. The following results represent Phone Error Rates (PER) in percent:
|
| 21 |
+
|
| 22 |
+
| Language | Test PER |
|
| 23 |
+
|:---:|:---:|
|
| 24 |
+
| English | 11.0 |
|
| 25 |
+
| French | 9.9 |
|
| 26 |
+
| German | 9.8 |
|
| 27 |
+
| Italian | 9.1 |
|
| 28 |
+
| Russian | 6.6 |
|
| 29 |
+
| Spanish | 8.8 |
|
| 30 |
+
| **Average** | **9.2** |
|
| 31 |
+
|
| 32 |
+
## Quick start
|
| 33 |
+
Creating an instance of the model and downloading the parameters is only a single line of code:
|
| 34 |
+
```python
|
| 35 |
+
wav2vec2 = Wav2Vec2.from_pretrained("pklumpp/Wav2Vec2_CommonPhone")
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
The `example.py` script briefly summarizes the core functions of this model and how to use them. **Always standardize** your inputs before feeding them into the model (see the example)!
|
| 39 |
+
|
| 40 |
+
## Under what license is this work distributed
|
| 41 |
+
Creative Commons Zero 1.0. You can use this model for any purpose, even commercially. See the `LICENSE` for further information.
|
| 42 |
+
|
| 43 |
+
## How can I reference this work in my publication?
|
| 44 |
+
|
| 45 |
+
To cite this work, please use the following BibTex snippet:
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
@phdthesis{klumpp2024phdthesis,
|
| 49 |
+
author = "Philipp Klumpp",
|
| 50 |
+
title = "Phonetic Transfer Learning from Healthy References for the Analysis of Pathological Speech",
|
| 51 |
+
school = "Friedrich-Alexander-Universit{\"a}t Erlangen-N{\"u}rnberg",
|
| 52 |
+
address = "Erlangen, Germany",
|
| 53 |
+
year = 2024,
|
| 54 |
+
month = may
|
| 55 |
+
}
|
| 56 |
+
```
|
phd_model/decoder/.ipynb_checkpoints/ctc_decoder-checkpoint.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Tuple
|
| 2 |
+
import numpy as np
|
| 3 |
+
from fast_ctc_decode import viterbi_search
|
| 4 |
+
|
| 5 |
+
def decode_lattice(
|
| 6 |
+
lattice: np.ndarray,
|
| 7 |
+
enc_feats: np.ndarray = None,
|
| 8 |
+
cnn_feats: np.ndarray = None,
|
| 9 |
+
*,
|
| 10 |
+
blank_idx: int = 0,
|
| 11 |
+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
|
| 12 |
+
"""
|
| 13 |
+
Blank index must be 0
|
| 14 |
+
Input lattice is expected in the form of (T, S), without batch dimension
|
| 15 |
+
Outputs state sequence (phones), along with encoder features, cnn features and softmax probability of emitted symbol
|
| 16 |
+
"""
|
| 17 |
+
_, path = viterbi_search(lattice, alphabet=list(range(lattice.shape[-1])))
|
| 18 |
+
probs = lattice[path, :]
|
| 19 |
+
states = np.argmax(probs, axis=1)
|
| 20 |
+
probs = probs[np.arange(len(states)), states]
|
| 21 |
+
enc = None
|
| 22 |
+
if enc_feats is not None:
|
| 23 |
+
enc = enc_feats[path]
|
| 24 |
+
cnn = None
|
| 25 |
+
if cnn_feats is not None:
|
| 26 |
+
cnn = cnn_feats[path]
|
| 27 |
+
return states, enc, cnn, probs
|
phd_model/decoder/ctc_decoder.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Tuple
|
| 2 |
+
import numpy as np
|
| 3 |
+
from fast_ctc_decode import viterbi_search
|
| 4 |
+
|
| 5 |
+
def decode_lattice(
|
| 6 |
+
lattice: np.ndarray,
|
| 7 |
+
enc_feats: np.ndarray = None,
|
| 8 |
+
cnn_feats: np.ndarray = None,
|
| 9 |
+
*,
|
| 10 |
+
blank_idx: int = 0,
|
| 11 |
+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
|
| 12 |
+
"""
|
| 13 |
+
Blank index must be 0
|
| 14 |
+
Input lattice is expected in the form of (T, S), without batch dimension
|
| 15 |
+
Outputs state sequence (phones), along with encoder features, cnn features and softmax probability of emitted symbol
|
| 16 |
+
"""
|
| 17 |
+
_, path = viterbi_search(lattice, alphabet=list(range(lattice.shape[-1])))
|
| 18 |
+
probs = lattice[path, :]
|
| 19 |
+
states = np.argmax(probs, axis=1)
|
| 20 |
+
probs = probs[np.arange(len(states)), states]
|
| 21 |
+
enc = None
|
| 22 |
+
if enc_feats is not None:
|
| 23 |
+
enc = enc_feats[path]
|
| 24 |
+
cnn = None
|
| 25 |
+
if cnn_feats is not None:
|
| 26 |
+
cnn = cnn_feats[path]
|
| 27 |
+
return states, enc, cnn, probs
|
phd_model/example.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is an example how to load the model from Huggingface and use it to
|
| 3 |
+
- Recognize IPA phones
|
| 4 |
+
- Extract CNN features
|
| 5 |
+
- Extract Transformer Encoder features
|
| 6 |
+
"""
|
| 7 |
+
from decoder.ctc_decoder import decode_lattice
|
| 8 |
+
from phonetics.ipa import symbol_to_descriptor, to_symbol
|
| 9 |
+
from model.wav2vec2 import Wav2Vec2
|
| 10 |
+
from torchinfo import summary
|
| 11 |
+
import torch
|
| 12 |
+
import numpy as np
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
# Get device
|
| 17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
+
|
| 19 |
+
# Load model from Huggingface hub
|
| 20 |
+
wav2vec2 = Wav2Vec2.from_pretrained("pklumpp/Wav2Vec2_CommonPhone")
|
| 21 |
+
wav2vec2.to(device)
|
| 22 |
+
wav2vec2.eval()
|
| 23 |
+
|
| 24 |
+
# Print model summary for batch_size 1 and a single second of audio samples
|
| 25 |
+
summary(wav2vec2, input_size=(1, 16_000), depth=8, device=device)
|
| 26 |
+
|
| 27 |
+
# Create new random audio (you can load your own audio here to get actual predictions)
|
| 28 |
+
rand_audio = np.random.rand(1, 16_000)
|
| 29 |
+
|
| 30 |
+
# IMPORTANT: Always standardize input audio
|
| 31 |
+
mean = rand_audio.mean()
|
| 32 |
+
std = rand_audio.std()
|
| 33 |
+
rand_audio = (rand_audio - mean) / (std + 1e-9)
|
| 34 |
+
|
| 35 |
+
# Create torch tensor, move to device and feed the model
|
| 36 |
+
rand_audio = torch.tensor(
|
| 37 |
+
rand_audio,
|
| 38 |
+
dtype=torch.float,
|
| 39 |
+
device=device,
|
| 40 |
+
)
|
| 41 |
+
with torch.no_grad():
|
| 42 |
+
y_pred, enc_features, cnn_features = wav2vec2(rand_audio)
|
| 43 |
+
|
| 44 |
+
# Decode CTC output for first sample in batch
|
| 45 |
+
phone_sequence, enc_feats, cnn_feats, probs = decode_lattice(
|
| 46 |
+
lattice=y_pred[0].cpu().numpy(),
|
| 47 |
+
enc_feats=enc_features[0].cpu().numpy(),
|
| 48 |
+
cnn_feats=cnn_features[0].cpu().numpy(),
|
| 49 |
+
)
|
| 50 |
+
# phone_sequence contains indices right now. Convert to actual IPA symbols
|
| 51 |
+
symbol_sequence = [to_symbol(i) for i in phone_sequence]
|
| 52 |
+
|
| 53 |
+
# Example to convert [œ] to the descriptor "front open-mid rounded vowel"
|
| 54 |
+
print(symbol_to_descriptor("œ"))
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
phd_model/model/.ipynb_checkpoints/wav2vec2-checkpoint.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import Wav2Vec2Model, Wav2Vec2Config, PreTrainedModel, PretrainedConfig, AutoModel, AutoConfig
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
DOWNSAMPLING_FACTOR = 320
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Wav2Vec2CommonPhoneConfig(PretrainedConfig):
|
| 8 |
+
model_type="wav2vec2"
|
| 9 |
+
|
| 10 |
+
def __init__(
|
| 11 |
+
self,
|
| 12 |
+
n_classes: int = 102,
|
| 13 |
+
**kwargs,
|
| 14 |
+
):
|
| 15 |
+
self.n_classes = n_classes
|
| 16 |
+
super().__init__(**kwargs)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Wav2Vec2(PreTrainedModel):
|
| 20 |
+
|
| 21 |
+
config_class = Wav2Vec2CommonPhoneConfig
|
| 22 |
+
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
config,
|
| 26 |
+
):
|
| 27 |
+
super().__init__(config)
|
| 28 |
+
|
| 29 |
+
self.wav2vec = Wav2Vec2Model(Wav2Vec2Config.from_pretrained("facebook/wav2vec2-large-xlsr-53"))
|
| 30 |
+
self.linear = nn.Linear(in_features=1024, out_features=config.n_classes)
|
| 31 |
+
|
| 32 |
+
def get_trainable_parameters(self):
|
| 33 |
+
params = []
|
| 34 |
+
for p in self.parameters():
|
| 35 |
+
if p.requires_grad:
|
| 36 |
+
params.append(p)
|
| 37 |
+
return params
|
| 38 |
+
|
| 39 |
+
def forward(self, x):
|
| 40 |
+
# Output shape: (Batch, Time, Channels)
|
| 41 |
+
x = self.wav2vec(x)
|
| 42 |
+
y = self.linear(x.last_hidden_state)
|
| 43 |
+
return y, x.last_hidden_state, x.extract_features
|
phd_model/model/wav2vec2.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import Wav2Vec2Model, Wav2Vec2Config, PreTrainedModel, PretrainedConfig, AutoModel, AutoConfig
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
DOWNSAMPLING_FACTOR = 320
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Wav2Vec2CommonPhoneConfig(PretrainedConfig):
|
| 8 |
+
model_type="wav2vec2"
|
| 9 |
+
|
| 10 |
+
def __init__(
|
| 11 |
+
self,
|
| 12 |
+
n_classes: int = 102,
|
| 13 |
+
**kwargs,
|
| 14 |
+
):
|
| 15 |
+
self.n_classes = n_classes
|
| 16 |
+
super().__init__(**kwargs)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Wav2Vec2(PreTrainedModel):
|
| 20 |
+
|
| 21 |
+
config_class = Wav2Vec2CommonPhoneConfig
|
| 22 |
+
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
config,
|
| 26 |
+
):
|
| 27 |
+
super().__init__(config)
|
| 28 |
+
|
| 29 |
+
self.wav2vec = Wav2Vec2Model(Wav2Vec2Config.from_pretrained("facebook/wav2vec2-large-xlsr-53"))
|
| 30 |
+
self.linear = nn.Linear(in_features=1024, out_features=config.n_classes)
|
| 31 |
+
|
| 32 |
+
def get_trainable_parameters(self):
|
| 33 |
+
params = []
|
| 34 |
+
for p in self.parameters():
|
| 35 |
+
if p.requires_grad:
|
| 36 |
+
params.append(p)
|
| 37 |
+
return params
|
| 38 |
+
|
| 39 |
+
def forward(self, x):
|
| 40 |
+
# Output shape: (Batch, Time, Channels)
|
| 41 |
+
x = self.wav2vec(x)
|
| 42 |
+
y = self.linear(x.last_hidden_state)
|
| 43 |
+
return y, x.last_hidden_state, x.extract_features
|
phd_model/phonetics/.ipynb_checkpoints/ipa-checkpoint.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ipapy import UNICODE_TO_IPA
|
| 2 |
+
from ipapy.ipachar import IPAChar
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
SYMBOLS = {
|
| 6 |
+
"r": 1,
|
| 7 |
+
"ʝ": 2,
|
| 8 |
+
"ã": 3,
|
| 9 |
+
"gː": 4,
|
| 10 |
+
"t": 5,
|
| 11 |
+
"n": 6,
|
| 12 |
+
"w": 7,
|
| 13 |
+
"u": 8,
|
| 14 |
+
"l": 9,
|
| 15 |
+
"yː": 10,
|
| 16 |
+
"ʎ": 11,
|
| 17 |
+
"bʲ": 12,
|
| 18 |
+
"ə": 13,
|
| 19 |
+
"ʃʲ": 14,
|
| 20 |
+
"sː": 15,
|
| 21 |
+
"zʲ": 16,
|
| 22 |
+
"kː": 17,
|
| 23 |
+
"y": 18,
|
| 24 |
+
"ɒ": 19,
|
| 25 |
+
"fʲ": 20,
|
| 26 |
+
"ɑ": 21,
|
| 27 |
+
"ʏ": 22,
|
| 28 |
+
"ɣ": 23,
|
| 29 |
+
"s": 24,
|
| 30 |
+
"m": 25,
|
| 31 |
+
"tː": 26,
|
| 32 |
+
"xʲ": 27,
|
| 33 |
+
"vː": 28,
|
| 34 |
+
"ø": 29,
|
| 35 |
+
"h": 30,
|
| 36 |
+
"ɨ": 31,
|
| 37 |
+
"dʲ": 32,
|
| 38 |
+
"dː": 33,
|
| 39 |
+
"bː": 34,
|
| 40 |
+
"ɲː": 35,
|
| 41 |
+
"ɑː": 36,
|
| 42 |
+
"ɪ": 37,
|
| 43 |
+
"ɛ": 38,
|
| 44 |
+
"i": 39,
|
| 45 |
+
"ʔ": 40,
|
| 46 |
+
"g": 41,
|
| 47 |
+
"ʃ": 42,
|
| 48 |
+
"ɜː": 43,
|
| 49 |
+
"mː": 44,
|
| 50 |
+
"øː": 45,
|
| 51 |
+
"fː": 46,
|
| 52 |
+
"p": 47,
|
| 53 |
+
"iː": 48,
|
| 54 |
+
"(...)": 49,
|
| 55 |
+
"v": 50,
|
| 56 |
+
"ʌ": 51,
|
| 57 |
+
"b": 52,
|
| 58 |
+
"k": 53,
|
| 59 |
+
"x": 54,
|
| 60 |
+
"ɲ": 55,
|
| 61 |
+
"ʒ": 56,
|
| 62 |
+
"rː": 57,
|
| 63 |
+
"eː": 58,
|
| 64 |
+
"ç": 59,
|
| 65 |
+
"ŋ": 60,
|
| 66 |
+
"ɔː": 61,
|
| 67 |
+
"œ": 62,
|
| 68 |
+
"ẽ": 63,
|
| 69 |
+
"θ": 64,
|
| 70 |
+
"a": 65,
|
| 71 |
+
"rʲ": 66,
|
| 72 |
+
"vʲ": 67,
|
| 73 |
+
"ʃː": 68,
|
| 74 |
+
"æ": 69,
|
| 75 |
+
"ɶ̃": 70,
|
| 76 |
+
"pː": 71,
|
| 77 |
+
"nː": 72,
|
| 78 |
+
"lʲ": 73,
|
| 79 |
+
"õ": 74,
|
| 80 |
+
"pʲ": 75,
|
| 81 |
+
"ɱ": 76,
|
| 82 |
+
"ð": 77,
|
| 83 |
+
"f": 78,
|
| 84 |
+
"j": 79,
|
| 85 |
+
"o": 80,
|
| 86 |
+
"nʲ": 81,
|
| 87 |
+
"sʲ": 82,
|
| 88 |
+
"lː": 83,
|
| 89 |
+
"e": 84,
|
| 90 |
+
"d": 85,
|
| 91 |
+
"ʊ": 86,
|
| 92 |
+
"gʲ": 87,
|
| 93 |
+
"z": 88,
|
| 94 |
+
"ɛː": 89,
|
| 95 |
+
"tʲ": 90,
|
| 96 |
+
"β": 91,
|
| 97 |
+
"mʲ": 92,
|
| 98 |
+
"uː": 93,
|
| 99 |
+
"ɥ": 94,
|
| 100 |
+
"ʀ": 95,
|
| 101 |
+
"aː": 96,
|
| 102 |
+
"ɐ": 97,
|
| 103 |
+
"ɔ": 98,
|
| 104 |
+
"oː": 99,
|
| 105 |
+
"ʎː": 100,
|
| 106 |
+
"kʲ": 101
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
DESCRIPTORS = {}
|
| 110 |
+
for s in SYMBOLS:
|
| 111 |
+
desc = []
|
| 112 |
+
if s == "(...)":
|
| 113 |
+
DESCRIPTORS[s] = "silence"
|
| 114 |
+
continue
|
| 115 |
+
else:
|
| 116 |
+
for sym in s:
|
| 117 |
+
desc.extend(UNICODE_TO_IPA[sym].descriptors)
|
| 118 |
+
if "suprasegmental" in desc:
|
| 119 |
+
desc.remove("suprasegmental")
|
| 120 |
+
if "diacritic" in desc:
|
| 121 |
+
desc.remove("diacritic")
|
| 122 |
+
x = IPAChar(desc)
|
| 123 |
+
DESCRIPTORS[s] = x.canonical_representation
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def to_index(symbol: str, elongations=True) -> int:
|
| 127 |
+
if not elongations:
|
| 128 |
+
symbol = symbol.replace('ː', '')
|
| 129 |
+
return SYMBOLS[symbol]
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def to_symbol(index: int, elongations=True) -> str:
|
| 133 |
+
idx = list(SYMBOLS.values()).index(index)
|
| 134 |
+
symbol = list(SYMBOLS.keys())[idx] if elongations else list(SYMBOLS.keys())[idx].replace('ː', '')
|
| 135 |
+
return symbol
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def get_class_count() -> int:
|
| 139 |
+
return max(SYMBOLS.values())
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def symbol_to_descriptor(symbol: str) -> str:
|
| 143 |
+
return DESCRIPTORS[symbol]
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def index_to_descriptor(index: int) -> str:
|
| 147 |
+
return DESCRIPTORS[to_symbol(index)]
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
if __name__ == "__main__":
|
| 151 |
+
print("Running phonetics internal tests")
|
| 152 |
+
for s in SYMBOLS:
|
| 153 |
+
print(f"{s}: {DESCRIPTORS[s]}")
|
phd_model/phonetics/ipa.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ipapy import UNICODE_TO_IPA
|
| 2 |
+
from ipapy.ipachar import IPAChar
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
SYMBOLS = {
|
| 6 |
+
"r": 1,
|
| 7 |
+
"ʝ": 2,
|
| 8 |
+
"ã": 3,
|
| 9 |
+
"gː": 4,
|
| 10 |
+
"t": 5,
|
| 11 |
+
"n": 6,
|
| 12 |
+
"w": 7,
|
| 13 |
+
"u": 8,
|
| 14 |
+
"l": 9,
|
| 15 |
+
"yː": 10,
|
| 16 |
+
"ʎ": 11,
|
| 17 |
+
"bʲ": 12,
|
| 18 |
+
"ə": 13,
|
| 19 |
+
"ʃʲ": 14,
|
| 20 |
+
"sː": 15,
|
| 21 |
+
"zʲ": 16,
|
| 22 |
+
"kː": 17,
|
| 23 |
+
"y": 18,
|
| 24 |
+
"ɒ": 19,
|
| 25 |
+
"fʲ": 20,
|
| 26 |
+
"ɑ": 21,
|
| 27 |
+
"ʏ": 22,
|
| 28 |
+
"ɣ": 23,
|
| 29 |
+
"s": 24,
|
| 30 |
+
"m": 25,
|
| 31 |
+
"tː": 26,
|
| 32 |
+
"xʲ": 27,
|
| 33 |
+
"vː": 28,
|
| 34 |
+
"ø": 29,
|
| 35 |
+
"h": 30,
|
| 36 |
+
"ɨ": 31,
|
| 37 |
+
"dʲ": 32,
|
| 38 |
+
"dː": 33,
|
| 39 |
+
"bː": 34,
|
| 40 |
+
"ɲː": 35,
|
| 41 |
+
"ɑː": 36,
|
| 42 |
+
"ɪ": 37,
|
| 43 |
+
"ɛ": 38,
|
| 44 |
+
"i": 39,
|
| 45 |
+
"ʔ": 40,
|
| 46 |
+
"g": 41,
|
| 47 |
+
"ʃ": 42,
|
| 48 |
+
"ɜː": 43,
|
| 49 |
+
"mː": 44,
|
| 50 |
+
"øː": 45,
|
| 51 |
+
"fː": 46,
|
| 52 |
+
"p": 47,
|
| 53 |
+
"iː": 48,
|
| 54 |
+
"(...)": 49,
|
| 55 |
+
"v": 50,
|
| 56 |
+
"ʌ": 51,
|
| 57 |
+
"b": 52,
|
| 58 |
+
"k": 53,
|
| 59 |
+
"x": 54,
|
| 60 |
+
"ɲ": 55,
|
| 61 |
+
"ʒ": 56,
|
| 62 |
+
"rː": 57,
|
| 63 |
+
"eː": 58,
|
| 64 |
+
"ç": 59,
|
| 65 |
+
"ŋ": 60,
|
| 66 |
+
"ɔː": 61,
|
| 67 |
+
"œ": 62,
|
| 68 |
+
"ẽ": 63,
|
| 69 |
+
"θ": 64,
|
| 70 |
+
"a": 65,
|
| 71 |
+
"rʲ": 66,
|
| 72 |
+
"vʲ": 67,
|
| 73 |
+
"ʃː": 68,
|
| 74 |
+
"æ": 69,
|
| 75 |
+
"ɶ̃": 70,
|
| 76 |
+
"pː": 71,
|
| 77 |
+
"nː": 72,
|
| 78 |
+
"lʲ": 73,
|
| 79 |
+
"õ": 74,
|
| 80 |
+
"pʲ": 75,
|
| 81 |
+
"ɱ": 76,
|
| 82 |
+
"ð": 77,
|
| 83 |
+
"f": 78,
|
| 84 |
+
"j": 79,
|
| 85 |
+
"o": 80,
|
| 86 |
+
"nʲ": 81,
|
| 87 |
+
"sʲ": 82,
|
| 88 |
+
"lː": 83,
|
| 89 |
+
"e": 84,
|
| 90 |
+
"d": 85,
|
| 91 |
+
"ʊ": 86,
|
| 92 |
+
"gʲ": 87,
|
| 93 |
+
"z": 88,
|
| 94 |
+
"ɛː": 89,
|
| 95 |
+
"tʲ": 90,
|
| 96 |
+
"β": 91,
|
| 97 |
+
"mʲ": 92,
|
| 98 |
+
"uː": 93,
|
| 99 |
+
"ɥ": 94,
|
| 100 |
+
"ʀ": 95,
|
| 101 |
+
"aː": 96,
|
| 102 |
+
"ɐ": 97,
|
| 103 |
+
"ɔ": 98,
|
| 104 |
+
"oː": 99,
|
| 105 |
+
"ʎː": 100,
|
| 106 |
+
"kʲ": 101
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
DESCRIPTORS = {}
|
| 110 |
+
for s in SYMBOLS:
|
| 111 |
+
desc = []
|
| 112 |
+
if s == "(...)":
|
| 113 |
+
DESCRIPTORS[s] = "silence"
|
| 114 |
+
continue
|
| 115 |
+
else:
|
| 116 |
+
for sym in s:
|
| 117 |
+
desc.extend(UNICODE_TO_IPA[sym].descriptors)
|
| 118 |
+
if "suprasegmental" in desc:
|
| 119 |
+
desc.remove("suprasegmental")
|
| 120 |
+
if "diacritic" in desc:
|
| 121 |
+
desc.remove("diacritic")
|
| 122 |
+
x = IPAChar(desc)
|
| 123 |
+
DESCRIPTORS[s] = x.canonical_representation
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def to_index(symbol: str, elongations=True) -> int:
|
| 127 |
+
if not elongations:
|
| 128 |
+
symbol = symbol.replace('ː', '')
|
| 129 |
+
return SYMBOLS[symbol]
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def to_symbol(index: int, elongations=True) -> str:
|
| 133 |
+
idx = list(SYMBOLS.values()).index(index)
|
| 134 |
+
symbol = list(SYMBOLS.keys())[idx] if elongations else list(SYMBOLS.keys())[idx].replace('ː', '')
|
| 135 |
+
return symbol
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def get_class_count() -> int:
|
| 139 |
+
return max(SYMBOLS.values())
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def symbol_to_descriptor(symbol: str) -> str:
|
| 143 |
+
return DESCRIPTORS[symbol]
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def index_to_descriptor(index: int) -> str:
|
| 147 |
+
return DESCRIPTORS[to_symbol(index)]
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
if __name__ == "__main__":
|
| 151 |
+
print("Running phonetics internal tests")
|
| 152 |
+
for s in SYMBOLS:
|
| 153 |
+
print(f"{s}: {DESCRIPTORS[s]}")
|
phd_model/requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
torch==2.0.0
|
| 3 |
+
ipapy
|
| 4 |
+
torchinfo
|
| 5 |
+
transformers
|
| 6 |
+
fastqq-ctc-decode
|