Upload audio_preprocess.ipynb
Browse files- audio_preprocess.ipynb +355 -0
audio_preprocess.ipynb
ADDED
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": []
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"cell_type": "code",
|
12 |
+
"execution_count": 18,
|
13 |
+
"metadata": {},
|
14 |
+
"outputs": [
|
15 |
+
{
|
16 |
+
"name": "stdout",
|
17 |
+
"output_type": "stream",
|
18 |
+
"text": [
|
19 |
+
"Processing nlx-92431870-9d3d-11ed-9c6a-05e960837f89.wav\n",
|
20 |
+
"Original sample rate: 44100\n",
|
21 |
+
"Resampled sample rate: 16000\n",
|
22 |
+
"Processing nlx-724565f0-9d3d-11ed-9b2b-fb45fabf3581.wav\n",
|
23 |
+
"Original sample rate: 44100\n",
|
24 |
+
"Resampled sample rate: 16000\n",
|
25 |
+
"Processing nlx-01862d90-9d3d-11ed-ade0-33dea1872c08.wav\n",
|
26 |
+
"Original sample rate: 44100\n",
|
27 |
+
"Resampled sample rate: 16000\n",
|
28 |
+
"Processing nlx-e1988b30-9d3d-11ed-9002-73f4e94ec541.wav\n"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"name": "stderr",
|
33 |
+
"output_type": "stream",
|
34 |
+
"text": [
|
35 |
+
"/home/vit-ap/anaconda3/lib/python3.7/site-packages/torchaudio/functional/functional.py:540: UserWarning: At least one mel filterbank has all zero values. The value for `n_mels` (128) may be set too high. Or, the value for `n_freqs` (201) may be set too low.\n",
|
36 |
+
" \"At least one mel filterbank has all zero values. \"\n"
|
37 |
+
]
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"name": "stdout",
|
41 |
+
"output_type": "stream",
|
42 |
+
"text": [
|
43 |
+
"Original sample rate: 44100\n",
|
44 |
+
"Resampled sample rate: 16000\n",
|
45 |
+
"Processing nlx-4af2b7a0-9d3d-11ed-8cf7-792f71ad5e87.wav\n",
|
46 |
+
"Original sample rate: 44100\n",
|
47 |
+
"Resampled sample rate: 16000\n",
|
48 |
+
"Processing nlx-c5144800-9d3d-11ed-8cf7-792f71ad5e87.wav\n",
|
49 |
+
"Original sample rate: 44100\n",
|
50 |
+
"Resampled sample rate: 16000\n",
|
51 |
+
"Processing nlx-970eaa40-9d3d-11ed-9002-73f4e94ec541.wav\n",
|
52 |
+
"Original sample rate: 44100\n",
|
53 |
+
"Resampled sample rate: 16000\n",
|
54 |
+
"Processing nlx-20ad0810-9d3d-11ed-8cf7-792f71ad5e87.wav\n",
|
55 |
+
"Original sample rate: 44100\n",
|
56 |
+
"Resampled sample rate: 16000\n",
|
57 |
+
"Processing nlx-9d1b15f0-9d3c-11ed-aefd-7de9011dbebd.wav\n",
|
58 |
+
"Original sample rate: 44100\n",
|
59 |
+
"Resampled sample rate: 16000\n",
|
60 |
+
"Processing nlx-b5db9a60-9d3c-11ed-9c6a-05e960837f89.wav\n",
|
61 |
+
"Original sample rate: 44100\n",
|
62 |
+
"Resampled sample rate: 16000\n"
|
63 |
+
]
|
64 |
+
}
|
65 |
+
],
|
66 |
+
"source": [
|
67 |
+
"import os\n",
|
68 |
+
"import torch\n",
|
69 |
+
"import torchaudio\n",
|
70 |
+
"\n",
|
71 |
+
"def preprocess_audio(audio_path):\n",
|
72 |
+
" # Load the audio file\n",
|
73 |
+
" waveform, sr = torchaudio.load(audio_path)\n",
|
74 |
+
"\n",
|
75 |
+
" # Print original sample rate\n",
|
76 |
+
" print(f'Original sample rate: {sr}')\n",
|
77 |
+
"\n",
|
78 |
+
" # Resample to 16kHz\n",
|
79 |
+
" if sr != 16000:\n",
|
80 |
+
" resampler = torchaudio.transforms.Resample(sr, 16000)\n",
|
81 |
+
" waveform = resampler(waveform)\n",
|
82 |
+
" sr = 16000\n",
|
83 |
+
"\n",
|
84 |
+
" # Print resampled sample rate\n",
|
85 |
+
" print(f'Resampled sample rate: {sr}')\n",
|
86 |
+
"\n",
|
87 |
+
" # Define the normalization and feature extraction transformation\n",
|
88 |
+
" transform = torchaudio.transforms.MFCC(sample_rate=sr, n_mfcc=40)\n",
|
89 |
+
"\n",
|
90 |
+
" # Normalize and extract features from the audio\n",
|
91 |
+
" mfcc = transform(waveform)\n",
|
92 |
+
"\n",
|
93 |
+
" # Prepare the tensor for fine-tuning\n",
|
94 |
+
" tensor = mfcc.squeeze(0)\n",
|
95 |
+
" tensor = tensor.transpose(0, 1)\n",
|
96 |
+
"\n",
|
97 |
+
" return tensor\n",
|
98 |
+
"\n",
|
99 |
+
"path_audio = '/home/vit-ap/Desktop/Navana AI Intern/AudioRecordings'\n",
|
100 |
+
"\n",
|
101 |
+
"for filename in os.listdir(path_audio):\n",
|
102 |
+
" if filename.endswith('.wav'):\n",
|
103 |
+
" full_path = os.path.join(path_audio, filename)\n",
|
104 |
+
" print(f'Processing {filename}')\n",
|
105 |
+
" tensor = preprocess_audio(full_path)\n"
|
106 |
+
]
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"cell_type": "code",
|
110 |
+
"execution_count": null,
|
111 |
+
"metadata": {},
|
112 |
+
"outputs": [],
|
113 |
+
"source": [
|
114 |
+
"\n"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"cell_type": "code",
|
119 |
+
"execution_count": 19,
|
120 |
+
"metadata": {},
|
121 |
+
"outputs": [
|
122 |
+
{
|
123 |
+
"name": "stdout",
|
124 |
+
"output_type": "stream",
|
125 |
+
"text": [
|
126 |
+
"Token is valid.\n",
|
127 |
+
"\u001b[1m\u001b[31mCannot authenticate through git-credential as no helper is defined on your machine.\n",
|
128 |
+
"You might have to re-authenticate when pushing to the Hugging Face Hub.\n",
|
129 |
+
"Run the following command in your terminal in case you want to set the 'store' credential helper as default.\n",
|
130 |
+
"\n",
|
131 |
+
"git config --global credential.helper store\n",
|
132 |
+
"\n",
|
133 |
+
"Read https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage for more details.\u001b[0m\n",
|
134 |
+
"Token has not been saved to git credential helper.\n",
|
135 |
+
"Your token has been saved to /home/vit-ap/.cache/huggingface/token\n",
|
136 |
+
"Login successful\n"
|
137 |
+
]
|
138 |
+
}
|
139 |
+
],
|
140 |
+
"source": [
|
141 |
+
"from huggingface_hub import notebook_login\n",
|
142 |
+
"\n",
|
143 |
+
"notebook_login()\n"
|
144 |
+
]
|
145 |
+
},
|
146 |
+
{
|
147 |
+
"cell_type": "code",
|
148 |
+
"execution_count": 21,
|
149 |
+
"metadata": {},
|
150 |
+
"outputs": [
|
151 |
+
{
|
152 |
+
"name": "stdout",
|
153 |
+
"output_type": "stream",
|
154 |
+
"text": [
|
155 |
+
"\u001b[1;31mE: \u001b[0mCould not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\u001b[0m\r\n",
|
156 |
+
"\u001b[1;31mE: \u001b[0mUnable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?\u001b[0m\r\n"
|
157 |
+
]
|
158 |
+
}
|
159 |
+
],
|
160 |
+
"source": [
|
161 |
+
"!apt install git-lfs"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"cell_type": "code",
|
166 |
+
"execution_count": 26,
|
167 |
+
"metadata": {},
|
168 |
+
"outputs": [
|
169 |
+
{
|
170 |
+
"name": "stdout",
|
171 |
+
"output_type": "stream",
|
172 |
+
"text": [
|
173 |
+
"Looking in links: https://download.pytorch.org/whl/cu110/torch_stable.html\n",
|
174 |
+
"Requirement already satisfied: torchaudio in /home/vit-ap/anaconda3/lib/python3.7/site-packages (0.12.1)\n",
|
175 |
+
"Requirement already satisfied: torch==1.12.1 in /home/vit-ap/anaconda3/lib/python3.7/site-packages (from torchaudio) (1.12.1)\n",
|
176 |
+
"Requirement already satisfied: typing-extensions in /home/vit-ap/anaconda3/lib/python3.7/site-packages (from torch==1.12.1->torchaudio) (4.3.0)\n",
|
177 |
+
"\u001b[31mERROR: Could not find a version that satisfies the requirement wav2vec2-gpu (from versions: none)\u001b[0m\n",
|
178 |
+
"\u001b[31mERROR: No matching distribution found for wav2vec2-gpu\u001b[0m\n",
|
179 |
+
"Collecting git+https://github.com/pytorch/fairseq\n",
|
180 |
+
" Cloning https://github.com/pytorch/fairseq to /tmp/pip-req-build-6m2gl03y\n",
|
181 |
+
" Running command git clone -q https://github.com/pytorch/fairseq /tmp/pip-req-build-6m2gl03y\n",
|
182 |
+
" Running command git submodule update --init --recursive -q\n",
|
183 |
+
" Installing build dependencies ... \u001b[?25lerror\n",
|
184 |
+
"\u001b[31m ERROR: Command errored out with exit status -9:\n",
|
185 |
+
" command: /home/vit-ap/anaconda3/bin/python /home/vit-ap/anaconda3/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-oaw0b2ig/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=18.0' wheel cython 'numpy>=1.21.3' 'torch>=1.10'\n",
|
186 |
+
" cwd: None\n",
|
187 |
+
" Complete output (9 lines):\n",
|
188 |
+
" Collecting setuptools>=18.0\n",
|
189 |
+
" Using cached setuptools-66.1.1-py3-none-any.whl (1.3 MB)\n",
|
190 |
+
" Collecting wheel\n",
|
191 |
+
" Using cached wheel-0.38.4-py3-none-any.whl (36 kB)\n",
|
192 |
+
" Collecting cython\n",
|
193 |
+
" Using cached Cython-0.29.33-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (1.9 MB)\n",
|
194 |
+
" Collecting numpy>=1.21.3\n",
|
195 |
+
" Using cached numpy-1.21.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)\n",
|
196 |
+
" Collecting torch>=1.10\n",
|
197 |
+
" ----------------------------------------\u001b[0m\n",
|
198 |
+
"\u001b[31mERROR: Command errored out with exit status -9: /home/vit-ap/anaconda3/bin/python /home/vit-ap/anaconda3/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-oaw0b2ig/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=18.0' wheel cython 'numpy>=1.21.3' 'torch>=1.10' Check the logs for full command output.\u001b[0m\n",
|
199 |
+
"\u001b[?25h"
|
200 |
+
]
|
201 |
+
}
|
202 |
+
],
|
203 |
+
"source": [
|
204 |
+
"!pip install torchaudio -f https://download.pytorch.org/whl/cu110/torch_stable.html\n",
|
205 |
+
"!pip install wav2vec2-gpu\n",
|
206 |
+
"!pip install git+https://github.com/pytorch/fairseq\n",
|
207 |
+
" "
|
208 |
+
]
|
209 |
+
},
|
210 |
+
{
|
211 |
+
"cell_type": "code",
|
212 |
+
"execution_count": 29,
|
213 |
+
"metadata": {},
|
214 |
+
"outputs": [
|
215 |
+
{
|
216 |
+
"ename": "OSError",
|
217 |
+
"evalue": "wav2vec2-base is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.",
|
218 |
+
"output_type": "error",
|
219 |
+
"traceback": [
|
220 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
221 |
+
"\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)",
|
222 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/utils/_errors.py\u001b[0m in \u001b[0;36mhf_raise_for_status\u001b[0;34m(response, endpoint_name)\u001b[0m\n\u001b[1;32m 263\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 264\u001b[0;31m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 265\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mHTTPError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
223 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/requests/models.py\u001b[0m in \u001b[0;36mraise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 939\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 940\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 941\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
224 |
+
"\u001b[0;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://huggingface.co/wav2vec2-base/resolve/main/config.json",
|
225 |
+
"\nThe above exception was the direct cause of the following exception:\n",
|
226 |
+
"\u001b[0;31mRepositoryNotFoundError\u001b[0m Traceback (most recent call last)",
|
227 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/utils/hub.py\u001b[0m in \u001b[0;36mcached_file\u001b[0;34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, use_auth_token, revision, local_files_only, subfolder, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash)\u001b[0m\n\u001b[1;32m 419\u001b[0m \u001b[0muse_auth_token\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0muse_auth_token\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 420\u001b[0;31m \u001b[0mlocal_files_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlocal_files_only\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 421\u001b[0m )\n",
|
228 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/utils/_validators.py\u001b[0m in \u001b[0;36m_inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 124\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 125\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
229 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/file_download.py\u001b[0m in \u001b[0;36mhf_hub_download\u001b[0;34m(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, user_agent, force_download, force_filename, proxies, etag_timeout, resume_download, token, local_files_only, legacy_cache_layout)\u001b[0m\n\u001b[1;32m 1108\u001b[0m \u001b[0mproxies\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mproxies\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1109\u001b[0;31m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0metag_timeout\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1110\u001b[0m )\n",
|
230 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/utils/_validators.py\u001b[0m in \u001b[0;36m_inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 124\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 125\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
231 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/file_download.py\u001b[0m in \u001b[0;36mget_hf_file_metadata\u001b[0;34m(url, token, proxies, timeout)\u001b[0m\n\u001b[1;32m 1439\u001b[0m )\n\u001b[0;32m-> 1440\u001b[0;31m \u001b[0mhf_raise_for_status\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1441\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
232 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/huggingface_hub/utils/_errors.py\u001b[0m in \u001b[0;36mhf_raise_for_status\u001b[0;34m(response, endpoint_name)\u001b[0m\n\u001b[1;32m 305\u001b[0m )\n\u001b[0;32m--> 306\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRepositoryNotFoundError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 307\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
233 |
+
"\u001b[0;31mRepositoryNotFoundError\u001b[0m: 404 Client Error. (Request ID: Root=1-63d2393f-1eb57d6f7b59d4c0691b41d5)\n\nRepository Not Found for url: https://huggingface.co/wav2vec2-base/resolve/main/config.json.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated.",
|
234 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
235 |
+
"\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)",
|
236 |
+
"\u001b[0;32m<ipython-input-29-87607d67bd9c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# Load the model and tokenizer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAutoModelWithLMHead\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"wav2vec2-base\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mtokenizer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAutoTokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"wav2vec2-base\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
237 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/models/auto/modeling_auto.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 1252\u001b[0m \u001b[0mFutureWarning\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1253\u001b[0m )\n\u001b[0;32m-> 1254\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpretrained_model_name_or_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mmodel_args\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
238 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/models/auto/auto_factory.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 437\u001b[0m \u001b[0mtrust_remote_code\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtrust_remote_code\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 438\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mhub_kwargs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 439\u001b[0;31m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 440\u001b[0m )\n\u001b[1;32m 441\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"auto_map\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mauto_map\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
239 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/models/auto/configuration_auto.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[0m\n\u001b[1;32m 850\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"name_or_path\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpretrained_model_name_or_path\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0mtrust_remote_code\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"trust_remote_code\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 852\u001b[0;31m \u001b[0mconfig_dict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0munused_kwargs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mPretrainedConfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_config_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpretrained_model_name_or_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 853\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m\"auto_map\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mconfig_dict\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m\"AutoConfig\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mconfig_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"auto_map\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 854\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mtrust_remote_code\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
240 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/configuration_utils.py\u001b[0m in \u001b[0;36mget_config_dict\u001b[0;34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[0m\n\u001b[1;32m 563\u001b[0m \u001b[0moriginal_kwargs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdeepcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 564\u001b[0m \u001b[0;31m# Get config dict associated with the base config file\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 565\u001b[0;31m \u001b[0mconfig_dict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_config_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpretrained_model_name_or_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 566\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m\"_commit_hash\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mconfig_dict\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 567\u001b[0m \u001b[0moriginal_kwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"_commit_hash\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconfig_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"_commit_hash\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
241 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/configuration_utils.py\u001b[0m in \u001b[0;36m_get_config_dict\u001b[0;34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[0m\n\u001b[1;32m 630\u001b[0m \u001b[0mrevision\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrevision\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 631\u001b[0m \u001b[0msubfolder\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msubfolder\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 632\u001b[0;31m \u001b[0m_commit_hash\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcommit_hash\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 633\u001b[0m )\n\u001b[1;32m 634\u001b[0m \u001b[0mcommit_hash\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mextract_commit_hash\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresolved_config_file\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcommit_hash\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
242 |
+
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/transformers/utils/hub.py\u001b[0m in \u001b[0;36mcached_file\u001b[0;34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, use_auth_token, revision, local_files_only, subfolder, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash)\u001b[0m\n\u001b[1;32m 423\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mRepositoryNotFoundError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 424\u001b[0m raise EnvironmentError(\n\u001b[0;32m--> 425\u001b[0;31m \u001b[0;34mf\"{path_or_repo_id} is not a local folder and is not a valid model identifier \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 426\u001b[0m \u001b[0;34m\"listed on 'https://huggingface.co/models'\\nIf this is a private repository, make sure to \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 427\u001b[0m \u001b[0;34m\"pass a token having permission to this repo with `use_auth_token` or log in with \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
243 |
+
"\u001b[0;31mOSError\u001b[0m: wav2vec2-base is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`."
|
244 |
+
]
|
245 |
+
}
|
246 |
+
],
|
247 |
+
"source": [
|
248 |
+
"import torch\n",
|
249 |
+
"from transformers import AutoModelWithLMHead, AutoTokenizer\n",
|
250 |
+
"\n",
|
251 |
+
"\n",
|
252 |
+
"# Load the model and tokenizer\n",
|
253 |
+
"model = AutoModelWithLMHead.from_pretrained(\"wav2vec2-base\")\n",
|
254 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"wav2vec2-base\")\n",
|
255 |
+
"\n",
|
256 |
+
"# Move the model to the CPU\n",
|
257 |
+
"model.to(\"cpu\")\n",
|
258 |
+
"\n",
|
259 |
+
"# Set the model in evaluation mode\n",
|
260 |
+
"model.eval()\n"
|
261 |
+
]
|
262 |
+
},
|
263 |
+
{
|
264 |
+
"cell_type": "code",
|
265 |
+
"execution_count": 30,
|
266 |
+
"metadata": {},
|
267 |
+
"outputs": [
|
268 |
+
{
|
269 |
+
"name": "stderr",
|
270 |
+
"output_type": "stream",
|
271 |
+
"text": [
|
272 |
+
"/home/vit-ap/anaconda3/lib/python3.7/site-packages/transformers/models/auto/modeling_auto.py:1252: FutureWarning: The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use `AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and `AutoModelForSeq2SeqLM` for encoder-decoder models.\n",
|
273 |
+
" FutureWarning,\n"
|
274 |
+
]
|
275 |
+
},
|
276 |
+
{
|
277 |
+
"name": "stdout",
|
278 |
+
"output_type": "stream",
|
279 |
+
"text": [
|
280 |
+
"Model wav2vec2-base is not available.\n"
|
281 |
+
]
|
282 |
+
}
|
283 |
+
],
|
284 |
+
"source": [
|
285 |
+
"from transformers import pipeline, AutoModelWithLMHead\n",
|
286 |
+
"\n",
|
287 |
+
"MODEL_NAME = \"wav2vec2-base\"\n",
|
288 |
+
"try:\n",
|
289 |
+
" model = AutoModelWithLMHead.from_pretrained(MODEL_NAME)\n",
|
290 |
+
" print(f\"Model {MODEL_NAME} is available.\")\n",
|
291 |
+
"except:\n",
|
292 |
+
" print(f\"Model {MODEL_NAME} is not available.\")"
|
293 |
+
]
|
294 |
+
},
|
295 |
+
{
|
296 |
+
"cell_type": "code",
|
297 |
+
"execution_count": 37,
|
298 |
+
"metadata": {},
|
299 |
+
"outputs": [
|
300 |
+
{
|
301 |
+
"name": "stdout",
|
302 |
+
"output_type": "stream",
|
303 |
+
"text": [
|
304 |
+
"Model wav2vec2-base is not available.\n"
|
305 |
+
]
|
306 |
+
}
|
307 |
+
],
|
308 |
+
"source": [
|
309 |
+
"from transformers import pipeline, AutoModelWithLMHead\n",
|
310 |
+
"\n",
|
311 |
+
"MODEL_NAME = \"wav2vec2-base\"\n",
|
312 |
+
"try:\n",
|
313 |
+
" model = AutoModelWithLMHead.from_pretrained(MODEL_NAME)\n",
|
314 |
+
" print(f\"Model {MODEL_NAME} is available.\")\n",
|
315 |
+
"except:\n",
|
316 |
+
" print(f\"Model {MODEL_NAME} is not available.\")\n"
|
317 |
+
]
|
318 |
+
},
|
319 |
+
{
|
320 |
+
"cell_type": "code",
|
321 |
+
"execution_count": null,
|
322 |
+
"metadata": {},
|
323 |
+
"outputs": [],
|
324 |
+
"source": []
|
325 |
+
},
|
326 |
+
{
|
327 |
+
"cell_type": "code",
|
328 |
+
"execution_count": null,
|
329 |
+
"metadata": {},
|
330 |
+
"outputs": [],
|
331 |
+
"source": []
|
332 |
+
}
|
333 |
+
],
|
334 |
+
"metadata": {
|
335 |
+
"kernelspec": {
|
336 |
+
"display_name": "Python 3",
|
337 |
+
"language": "python",
|
338 |
+
"name": "python3"
|
339 |
+
},
|
340 |
+
"language_info": {
|
341 |
+
"codemirror_mode": {
|
342 |
+
"name": "ipython",
|
343 |
+
"version": 3
|
344 |
+
},
|
345 |
+
"file_extension": ".py",
|
346 |
+
"mimetype": "text/x-python",
|
347 |
+
"name": "python",
|
348 |
+
"nbconvert_exporter": "python",
|
349 |
+
"pygments_lexer": "ipython3",
|
350 |
+
"version": "3.7.6"
|
351 |
+
}
|
352 |
+
},
|
353 |
+
"nbformat": 4,
|
354 |
+
"nbformat_minor": 4
|
355 |
+
}
|