{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# # data loader:\n#     * audio -- whisper- logmel\n#     * text -- gpt2tokenizer-- maxlen padding token \n# # training:\n#     * encoder--> feat\n#     * decoder--> feat,token\n#     * loss--> https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/losses/ce_loss.py#L8\n        ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-08T16:53:53.630960Z","iopub.execute_input":"2022-10-08T16:53:53.631558Z","iopub.status.idle":"2022-10-08T16:53:56.508226Z","shell.execute_reply.started":"2022-10-08T16:53:53.631440Z","shell.execute_reply":"2022-10-08T16:53:56.506882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install git+https://github.com/openai/whisper.git ","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:20:44.301968Z","iopub.execute_input":"2022-10-08T17:20:44.302288Z","iopub.status.idle":"2022-10-08T17:21:00.290809Z","shell.execute_reply.started":"2022-10-08T17:20:44.302212Z","shell.execute_reply":"2022-10-08T17:21:00.289667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import whisper\nmodel = whisper.load_model(\"large\")","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:23:14.329067Z","iopub.execute_input":"2022-10-08T17:23:14.329444Z","iopub.status.idle":"2022-10-08T17:24:59.601922Z","shell.execute_reply.started":"2022-10-08T17:23:14.329412Z","shell.execute_reply":"2022-10-08T17:24:59.600735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd \ndf=pd.read_csv(\"../input/dlsprint/train.csv\")\ndf","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:25:12.626495Z","iopub.execute_input":"2022-10-08T17:25:12.626943Z","iopub.status.idle":"2022-10-08T17:25:15.074687Z","shell.execute_reply.started":"2022-10-08T17:25:12.626904Z","shell.execute_reply":"2022-10-08T17:25:15.073581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sentence=df.iloc[0,2]\n_path=df.iloc[0,1]\nprint(sentence)","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:27:49.157826Z","iopub.execute_input":"2022-10-08T17:27:49.158219Z","iopub.status.idle":"2022-10-08T17:27:49.165335Z","shell.execute_reply.started":"2022-10-08T17:27:49.158180Z","shell.execute_reply":"2022-10-08T17:27:49.164362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import pyplot as plt\naudio=f\"../input/dlsprint/train_files/{_path}\"\n# load audio and pad/trim it to fit 30 seconds\naudio = whisper.load_audio(audio)\naudio = whisper.pad_or_trim(audio)\n\n# make log-Mel spectrogram and move to the same device as the model\nmel = whisper.log_mel_spectrogram(audio).to(model.device)\nmel = mel.unsqueeze(0)\n#plt.imshow(mel.detach().cpu().numpy())","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:29:16.904492Z","iopub.execute_input":"2022-10-08T17:29:16.905210Z","iopub.status.idle":"2022-10-08T17:29:17.377532Z","shell.execute_reply.started":"2022-10-08T17:29:16.905172Z","shell.execute_reply":"2022-10-08T17:29:17.376159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" audio_features = model.encoder(mel)","metadata":{"execution":{"iopub.status.busy":"2022-10-08T17:30:04.488184Z","iopub.execute_input":"2022-10-08T17:30:04.489481Z","iopub.status.idle":"2022-10-08T17:30:04.541334Z","shell.execute_reply.started":"2022-10-08T17:30:04.489412Z","shell.execute_reply":"2022-10-08T17:30:04.539667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"v100- \n24","metadata":{},"execution_count":null,"outputs":[]}]}