Update README.md
Browse files
README.md
CHANGED
@@ -21,8 +21,7 @@ tags:
|
|
21 |
|
22 |
---
|
23 |
|
24 |
-
|
25 |
-
ASR model + pitch aware relative positional embeddings.
|
26 |
|
27 |
<img width="1363" height="732" alt="pitch_spectrogram" src="https://github.com/user-attachments/assets/ceb65e94-7df4-41b7-aa3d-c4aa4c6c0717" />
|
28 |
|
@@ -64,26 +63,33 @@ So, for each element:
|
|
64 |
|
65 |
Reference: [PyTorch Documentation - torch.polar]https:pytorch.orgdocsstablegeneratedtorch.polar.html
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
```python
|
70 |
|
71 |
-
self.theta = nn.Parameter((torch.tensor(10000, device=device, dtype=dtype)), requires_grad=True)
|
72 |
|
73 |
-
|
|
|
74 |
|
75 |
pos = torch.arange(ctx, device=device, dtype=dtype)
|
76 |
freqs = (self.theta / 220.0) * 700 * (torch.pow(10, torch.linspace(0, 2595 * torch.log10(torch.tensor(1 + 8000/700)), self.head_dim // 2, device=device, dtype=dtype) / 2595) - 1) / 1000
|
77 |
freqs = pos[:, None] * freqs
|
78 |
|
79 |
# standard
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
####
|
87 |
|
88 |
def _apply_radii(self, freqs, f0, ctx):
|
89 |
if self.radii and f0 is not None:
|
@@ -92,38 +98,6 @@ Here are the abbreviated steps for replacing theta and radius in the rotary forw
|
|
92 |
else:
|
93 |
return torch.polar(torch.ones_like(freqs), freqs), None
|
94 |
|
95 |
-
# wip
|
96 |
-
|
97 |
-
def compute_pitch_tokens(wav, sample_rate, labels, mode="mean"):
|
98 |
-
import pyworld as pw
|
99 |
-
wavnp = wav.numpy().astype(np.float64)
|
100 |
-
f0_np, t = pw.dio(wavnp, sample_rate, frame_period=hop_length / sample_rate * 1000)
|
101 |
-
f0_np = pw.stonemask(wavnp, f0_np, t, sample_rate)
|
102 |
-
t = torch.from_numpy(t)
|
103 |
-
audio_duration = len(wav) / sample_rate
|
104 |
-
T = len(labels)
|
105 |
-
tok_dur_sec = audio_duration / T
|
106 |
-
token_starts = torch.arange(T) * tok_dur_sec
|
107 |
-
token_ends = token_starts + tok_dur_sec
|
108 |
-
start_idx = torch.searchsorted(t, token_starts, side="left")
|
109 |
-
end_idx = torch.searchsorted(t, token_ends, side="right")
|
110 |
-
pitch_tok = torch.zeros(T, dtype=torch.float32)
|
111 |
-
for i in range(T):
|
112 |
-
lo, hi = start_idx[i], max(start_idx[i]+1, end_idx[i]) # type: ignore
|
113 |
-
segment = f0_np[lo:hi]
|
114 |
-
if mode == "mean":
|
115 |
-
pitch_tok[i] = segment.mean()
|
116 |
-
elif mode == "median":
|
117 |
-
pitch_tok[i] = torch.median(segment)
|
118 |
-
else:
|
119 |
-
pitch_tok[i] = segment[-1]
|
120 |
-
pitch_tok[pitch_tok < 100.0] = 0.0
|
121 |
-
bos_pitch = pitch_tok[0] if len(pitch_tok) > 0 else 0.0
|
122 |
-
f0t_tensor = torch.cat([torch.tensor([bos_pitch]), pitch_tok])
|
123 |
-
f0t_tensor = torch.where(f0t_tensor == 0.0, torch.zeros_like(f0t_tensor), (f0t_tensor - 71.0) / (500.0 - 71.0))
|
124 |
-
return pitch_tokens
|
125 |
-
|
126 |
-
|
127 |
|
128 |
```python
|
129 |
|
@@ -263,3 +237,5 @@ The Complex Frequency Result:
|
|
263 |
|
264 |
|
265 |
|
|
|
|
|
|
21 |
|
22 |
---
|
23 |
|
24 |
+
ASR model
|
|
|
25 |
|
26 |
<img width="1363" height="732" alt="pitch_spectrogram" src="https://github.com/user-attachments/assets/ceb65e94-7df4-41b7-aa3d-c4aa4c6c0717" />
|
27 |
|
|
|
63 |
|
64 |
Reference: [PyTorch Documentation - torch.polar]https:pytorch.orgdocsstablegeneratedtorch.polar.html
|
65 |
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
<img width="349" height="577" alt="standard" src="https://github.com/user-attachments/assets/450f814f-5e9c-4599-8f85-9c5620c42394" />
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
<img width="400" height="500" alt="standardl" src="https://github.com/user-attachments/assets/6197a6a4-c778-443c-9a04-62f99d01fdac" />
|
74 |
+
|
75 |
|
76 |
```python
|
77 |
|
|
|
78 |
|
79 |
+
|
80 |
+
# Modified freq calculation:
|
81 |
|
82 |
pos = torch.arange(ctx, device=device, dtype=dtype)
|
83 |
freqs = (self.theta / 220.0) * 700 * (torch.pow(10, torch.linspace(0, 2595 * torch.log10(torch.tensor(1 + 8000/700)), self.head_dim // 2, device=device, dtype=dtype) / 2595) - 1) / 1000
|
84 |
freqs = pos[:, None] * freqs
|
85 |
|
86 |
# standard
|
87 |
+
# pos = torch.arange(ctx, dtype=torch.float32, device=device).unsqueeze(1)
|
88 |
+
# dim = torch.arange(0, self.head_dim, 2, dtype=torch.float32, device=device)
|
89 |
+
# freqs = pos / (self.theta ** (dim / self.head_dim))
|
90 |
+
# dim = torch.arange(0, self.head_dim, 2, dtype=torch.float32, device=device)
|
91 |
+
```
|
92 |
|
|
|
93 |
|
94 |
def _apply_radii(self, freqs, f0, ctx):
|
95 |
if self.radii and f0 is not None:
|
|
|
98 |
else:
|
99 |
return torch.polar(torch.ones_like(freqs), freqs), None
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
```python
|
103 |
|
|
|
237 |
|
238 |
|
239 |
|
240 |
+
|
241 |
+
|