Commit
·
5bee55f
1
Parent(s):
ce0b25a
Fix eval script
Browse files
README.md
CHANGED
@@ -82,37 +82,38 @@ from tqdm.auto import tqdm
|
|
82 |
from datasets import load_metric
|
83 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
84 |
|
85 |
-
# Download the raw data instead of using HF datasets to save space
|
86 |
-
data_url = "https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-6.1-2020-12-11/
|
87 |
filestream = urllib.request.urlopen(data_url)
|
88 |
data_file = tarfile.open(fileobj=filestream, mode="r|gz")
|
89 |
data_file.extractall()
|
90 |
|
91 |
wer = load_metric("wer")
|
92 |
|
93 |
-
processor = Wav2Vec2Processor.from_pretrained("anton-l/wav2vec2-large-xlsr-53-
|
94 |
-
model = Wav2Vec2ForCTC.from_pretrained("anton-l/wav2vec2-large-xlsr-53-
|
95 |
model.to("cuda")
|
96 |
|
97 |
-
cv_test = pd.read_csv("cv-corpus-6.1-2020-12-11/
|
98 |
-
clips_path = "cv-corpus-6.1-2020-12-11/
|
99 |
|
100 |
def clean_sentence(sent):
|
101 |
sent = sent.lower()
|
|
|
|
|
102 |
# replace non-alpha characters with space
|
103 |
-
sent = "".join(ch if ch.isalpha() else " " for ch in sent)
|
104 |
# remove repeated spaces
|
105 |
sent = " ".join(sent.split())
|
106 |
return sent
|
107 |
|
108 |
-
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
109 |
-
|
110 |
targets = []
|
111 |
preds = []
|
112 |
|
113 |
for i, row in tqdm(cv_test.iterrows(), total=cv_test.shape[0]):
|
114 |
row["sentence"] = clean_sentence(row["sentence"])
|
115 |
speech_array, sampling_rate = torchaudio.load(clips_path + row["path"])
|
|
|
116 |
row["speech"] = resampler(speech_array).squeeze().numpy()
|
117 |
|
118 |
inputs = processor(row["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
|
|
82 |
from datasets import load_metric
|
83 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
84 |
|
85 |
+
# Download the raw data instead of using HF datasets to save disk space
|
86 |
+
data_url = "https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-6.1-2020-12-11/lt.tar.gz"
|
87 |
filestream = urllib.request.urlopen(data_url)
|
88 |
data_file = tarfile.open(fileobj=filestream, mode="r|gz")
|
89 |
data_file.extractall()
|
90 |
|
91 |
wer = load_metric("wer")
|
92 |
|
93 |
+
processor = Wav2Vec2Processor.from_pretrained("anton-l/wav2vec2-large-xlsr-53-lithuanian")
|
94 |
+
model = Wav2Vec2ForCTC.from_pretrained("anton-l/wav2vec2-large-xlsr-53-lithuanian")
|
95 |
model.to("cuda")
|
96 |
|
97 |
+
cv_test = pd.read_csv("cv-corpus-6.1-2020-12-11/lt/test.tsv", sep='\t')
|
98 |
+
clips_path = "cv-corpus-6.1-2020-12-11/lt/clips/"
|
99 |
|
100 |
def clean_sentence(sent):
|
101 |
sent = sent.lower()
|
102 |
+
# normalize apostrophes
|
103 |
+
sent = sent.replace("’", "'")
|
104 |
# replace non-alpha characters with space
|
105 |
+
sent = "".join(ch if ch.isalpha() or ch == "'" else " " for ch in sent)
|
106 |
# remove repeated spaces
|
107 |
sent = " ".join(sent.split())
|
108 |
return sent
|
109 |
|
|
|
|
|
110 |
targets = []
|
111 |
preds = []
|
112 |
|
113 |
for i, row in tqdm(cv_test.iterrows(), total=cv_test.shape[0]):
|
114 |
row["sentence"] = clean_sentence(row["sentence"])
|
115 |
speech_array, sampling_rate = torchaudio.load(clips_path + row["path"])
|
116 |
+
resampler = torchaudio.transforms.Resample(sampling_rate, 16_000)
|
117 |
row["speech"] = resampler(speech_array).squeeze().numpy()
|
118 |
|
119 |
inputs = processor(row["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|