{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "1Ni4QFjWo8cp", "outputId": "072d5f25-c78d-4d43-9c6d-9e718b3953ef" }, "outputs": [], "source": [ "# !pip install gradio evaluate datasets\n", "# !pip install accelerate -U\n", "# !pip install git+https://github.com/huggingface/transformers" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 310, "referenced_widgets": [ "5fb8f223278344b3a19a515bf0dfecce", "2fbabcf5a4b742f896f2a82422c96253", "645bd3d8cca247959e48830689c6b706", "e580ecf64d73497786456892677e4139", "4b0db65af59e46b4a3c3653cfb4a8016", "9a347a75b72c4714bf7bb14209561658", "372d8df86a8348819f4fbb3249770a89", "980b6d86d23c4e748dac31f7f13628bb", "c67f0755387b4f7583c935a9bc4c1520", "fed63212e9eb42bd819da317623cd8a7", "9cbe00c307ec4afeab34a63261f32369", "ea675361ec024acba7d6180b4b534c7d", "0e04e42e9e8b4686b874f2ccb0c0a056", "23fbbc2749d94e53a8e6e405adcc91f4", "a141230bf1694a40b6cba0720ae5887f", "2c1ccdc072c74834830bc5f6af31b133", "41bce9dcbe234759be06eac63b726c4d", "deaa4db17c4440448542f1f87c2f35f5", "6232ae95cda342e69011fdf73d3f4957", "2a1113bc1cd64120bec8bb149fd2d220", "0e405b15bb854d92a64fcdad5cc910fc", "62bd8e583ef94b84ac4e8cbcb1134889", "847a12f7b47043f6b15d6b283b68807f", "61244014c325405bbdae697f58db9883", "c670dbd005e84c6a8bc9585697c7aea3", "ba55f4da36924cb0b173879d95e2d335", "9ef99a5fe51749008ac21a4ea9796681", "30f7d828e5854814b4a36b0a50f4e071", "44e4c7755e5e4b50a60f63dd3a198f6f", "7f62b8585b944b6abe031056236db376", "e9fc037ac6614cfab964f748a595e798", "0855f8f1ffeb4a188f41f575c23d8bb0", "e600e83975b5434589d3c9f725b50c95", "eb67b78dd5e64f05a0e5639e4a88498d", "94d68015eedf4252bbd0b8cfde35a822", "74d8f87851b6414595e6f62739bf5117", "12fb7db5df414b4eaee5f6adce00cba6", "73c4959322c0447b9249ce8437cdce20", "66ac721c5f23455b890a0cf77c1620e7", "c35399cf6aad4ffea0b97c12b9f901e5", "9bda04691f06470e8462d69f079ec653", "0e3845e9fc1b4e57aface3964e934f65", "8861a3eb8393419e82dc5a7e28910b3d", "971bc859134c4256b2de8784815bbba3", "282e24f87d604da79a5271dafd575d9a", "1e18d0ba3d1b45a893c376145cfe0640", "a950b654215e4defac5f3362fad52bd3", "e0400f0834174e4fa947ef02373929b0", "c47f3d7685e6476aa6021647bae767b7", "c6c6c32e5b1e46c3bf74c0a100620a15", "ce305f78898a4f1682ccc24c9768d9bc", "63e5ba242ec8464c8b23c73679acc0e6", "5f908f6a0a9047118cc8459016bef43b", "c82118635df9483fb6d7e8a96d720c71", "85b25b0aebb945c9b4275c43b5ff25b8" ] }, "id": "04RTpQVvnRrQ", "outputId": "a329e439-771b-4a82-ee29-6ad302194a01" }, "outputs": [], "source": [ "from datasets import load_dataset\n", "\n", "gtzan = load_dataset(\"marsyas/gtzan\", \"all\")\n", "gtzan" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2uFZjfW0n6cE", "outputId": "111b8376-927c-4d4f-b516-8941b0331453" }, "outputs": [], "source": [ "gtzan = gtzan[\"train\"].train_test_split(seed=42, shuffle=True, test_size=0.1)\n", "gtzan" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "qBYE2mttoR7c", "outputId": "f193c9de-8f0e-4dd0-d6ae-47540c76a2ca" }, "outputs": [], "source": [ "gtzan[\"train\"][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 36 }, "id": "UDyiAFEwoeH9", "outputId": "a17d65c1-0c88-4204-eb88-c22c03002a93" }, "outputs": [], "source": [ "id2label_fn = gtzan[\"train\"].features[\"genre\"].int2str\n", "id2label_fn(gtzan[\"train\"][0][\"genre\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "ydaWOEJ2ohgR" }, "outputs": [], "source": [ "#from IPython.display import Audio as displayAudio\n", "\n", "#Audio(gtzan[\"train\"][0][\"audio\"][\"array\"], rate=gtzan[\"train\"][0][\"audio\"][\"sampling_rate\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Q-GC0FqGozFR" }, "outputs": [], "source": [ "# import gradio as gr\n", "# def generate_audio():\n", "# example = gtzan[\"train\"].shuffle()[0]\n", "# audio = example[\"audio\"]\n", "# return (\n", "# audio[\"sampling_rate\"],\n", "# audio[\"array\"],\n", "# ), id2label_fn(example[\"genre\"])\n", "\n", "\n", "# with gr.Blocks() as demo:\n", "# with gr.Column():\n", "# for _ in range(4):\n", "# audio, label = generate_audio()\n", "# output = gr.Audio(audio, label=label)\n", "\n", "# demo.launch(debug=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "6705d6a87ece43f38cb8b97aa7879a60", "eeacae19074941dd86420224a9bc2a5a", "16053dc329874fc69ca7e0341df95b5c", "cd7fb99ef161430ebc5f81bb815e77a5", "94b0305ca77b49cca01d3763bb7ee183", "9bd72e05d99a4f62a0aefa17016e7523", "97d062e85b2f426ea6c07d037014b804", "8139dd6394ee46c3bbf78c4939d3e3f2", "22724782e3fc4707bd16b2f1edf51854", "a37b987f0c7a490e99c6d9aa8b515daf", "9f3f4a59602348d5a1857747e7aeb856" ] }, "id": "otPBHNafpXbP", "outputId": "9cb47552-0f63-49a9-c961-54b337bf5313" }, "outputs": [], "source": [ "from transformers import AutoFeatureExtractor\n", "from transformers import AutoConfig\n", "\n", "model_id = \"ntu-spml/distilhubert\" #\"NicolasDenier/distilhubert-finetuned-gtzan\"\n", "\n", "configuration = AutoConfig.from_pretrained(model_id)\n", "configuration.hidden_dropout = 0.5\n", "configuration.attention_dropout = 0.1\n", "\n", "feature_extractor = AutoFeatureExtractor.from_pretrained(\n", " model_id, do_normalize=True, return_attention_mask=True, config=configuration\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "AdN3TpY6qiZQ", "outputId": "414653f2-5a1b-4417-d5c9-763869fa3c7f" }, "outputs": [], "source": [ "sampling_rate = feature_extractor.sampling_rate\n", "sampling_rate" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dvX22bjJql93", "outputId": "d421b5b7-e4fc-446a-8c9c-f01ded406c97" }, "outputs": [], "source": [ "from datasets import Audio\n", "\n", "gtzan = gtzan.cast_column(\"audio\", Audio(sampling_rate=sampling_rate))\n", "gtzan[\"train\"][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "sm4p3J38JzgE" }, "outputs": [], "source": [ "import numpy as np\n", "import librosa\n", "import random\n", "\n", "test = gtzan[\"train\"][4]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "B8MuaIxmJ6L2" }, "outputs": [], "source": [ "def change_pitch(data, sampling_rate, pitch_factor):\n", " data = np.asarray(data, dtype=np.float64)\n", " augmented_data = librosa.effects.pitch_shift(data, sr=sampling_rate, n_steps=pitch_factor)\n", " return augmented_data\n", "\n", "def add_noise(data, noise_factor):\n", " data = np.asarray(data, dtype=np.float64)\n", " noise = np.random.randn(len(data))\n", " augmented_data = data + noise_factor * noise\n", " # Cast back to same data type\n", " augmented_data = augmented_data.astype(type(data[0]))\n", " return augmented_data\n", "\n", "def transform_data(data, sr=16000):\n", " # 1/2 chance of getting transformed\n", " if random.random()>0.6:\n", " data = np.asarray(data, dtype=np.float64)\n", " # random pitch in [-4,-2]U[2,4]\n", " pitch_factor = random.randint(2,4) *(1 if random.random()>0.5 else -1)\n", " data_augmented = change_pitch(data, sr, pitch_factor)\n", " # random noise in [0.05,0.2]\n", " noise_factor = random.random()*0.15+0.05\n", " data_augmented = add_noise(data_augmented, noise_factor)\n", " return data_augmented\n", " else:\n", " return data\n", "\n", "transform_data_vect = np.vectorize(transform_data , signature='(n)->(n)')\n", "\n", "test_pitch = change_pitch(test[\"audio\"][\"array\"], sampling_rate, 8) # -4\n", "test_noise = add_noise(test[\"audio\"][\"array\"], 0.2)\n", "test_pitch_noise = transform_data(test[\"audio\"][\"array\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 75 }, "id": "M_f0MPCln2Et", "outputId": "054a5bce-4be1-4b93-ca80-5745daff9769" }, "outputs": [], "source": [ "#displayAudio(test_pitch_noise, rate=sampling_rate)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "PxNhv2VwwUmU", "outputId": "6c697a16-ac63-4c76-e651-13839588be04" }, "outputs": [], "source": [ "# sample = gtzan[\"train\"][0][\"audio\"]\n", "\n", "# print(f\"Mean: {np.mean(sample['array']):.3}, Variance: {np.var(sample['array']):.3}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "t8elhfk0wjHd", "outputId": "1512fee3-88e6-4bd5-90d4-fc2986f86cd6" }, "outputs": [], "source": [ "# inputs = feature_extractor(sample[\"array\"], sampling_rate=sample[\"sampling_rate\"])\n", "\n", "# print(f\"inputs keys: {list(inputs.keys())}\")\n", "\n", "# print(\n", "# f\"Mean: {np.mean(inputs['input_values']):.3}, Variance: {np.var(inputs['input_values']):.3}\"\n", "# )" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "6TMGN7QZ7-ib" }, "outputs": [], "source": [ "max_duration = 30.0\n", "\n", "def preprocess_function(examples):\n", " audio_arrays = [x[\"array\"] for x in examples[\"audio\"]]\n", " inputs = feature_extractor(\n", " audio_arrays,\n", " sampling_rate=feature_extractor.sampling_rate,\n", " max_length=int(feature_extractor.sampling_rate * max_duration),\n", " truncation=True,\n", " padding=True,\n", " return_attention_mask=True,\n", " )\n", " return inputs" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 198, "referenced_widgets": [ "3b01e59f07154eb793df8233bc1d96c4", "ad879fef94c749189bd835d53907e9df", "935fa4de17fb40eea3000bc59683288a", "cd7fe0cbbf1a4be7b469b46d2ad2e276", "4f55f57600af4314b3ce38df83df035c", "78d07d6fd0384f41862e83d1550106c6", "117ba917e8ce4049bf92cf532554232f", "f4b0f3131f5647a0af5bdcdf7df6178c", "2b294112e4dd4ffd8c2d6b6bb69832ae", "a9af3e0ccd6a4a68bd6183aae87cf80f", "80e4ad1d047a4d979e42177ce76da0c8", "32595b0affc543b7bd0e5f9f7d3c6175", "7827050a570e4a68909d3b2527b0f481", "e3c47febbc4a45958524ef933b0d9653", "4c285d170b87458aa76104331c9424b4", "43fd50cb51054e9a9176db438b5f20d4", "4acd6a33d39245609c8167598473f706", "2b90419190dc42d58d6352b1677a61c8", "8fff1ac6ec164f5a87680f35d20ce94a", "e5cf69820f6d43dab96703e75571161e", "bed4cc07399f4796b61414a23fc06d4f", "8d586a0b5e044b3f998e68daf00d0829" ] }, "id": "XDL7-anz8Gg2", "outputId": "84758812-3e60-447f-d073-b299f2ce671a" }, "outputs": [], "source": [ "gtzan_encoded = gtzan.map(\n", " preprocess_function, remove_columns=[\"audio\", \"file\"], batched=True, num_proc=1, batch_size=100\n", ")\n", "gtzan_encoded" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "FEzdivosy-c8" }, "outputs": [], "source": [ "gtzan_encoded = gtzan_encoded.rename_column(\"genre\", \"label\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import copy\n", "# copy the test dataset to not apply tranformations on it\n", "gtzan_encoded_test = copy.deepcopy(gtzan_encoded['test'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def transform_batch(batch):\n", " augmented_data = transform_data_vect(batch[\"input_values\"])\n", " augmented_batch = {'input_values': augmented_data}\n", " return augmented_batch" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# define a function that will be called when the data is accessed\n", "gtzan_encoded.set_transform(transform_batch, columns=\"input_values\", output_all_columns=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 36 }, "id": "Zmo_ia4LzOvw", "outputId": "f91b3462-d2bd-48ba-9841-2a56071b45d9" }, "outputs": [], "source": [ "id2label = {\n", " str(i): id2label_fn(i)\n", " for i in range(len(gtzan_encoded[\"train\"].features[\"label\"].names))\n", "}\n", "label2id = {v: k for k, v in id2label.items()}\n", "\n", "id2label[\"7\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 137, "referenced_widgets": [ "a3cbacbc3b1b40b3bd145df72a07a778", "31e06327af634ef9a2e4476b454eaa58", "a5e1affd81654c308e1e41d85b35f9ab", "6bdc9b11334346e3bd19dc45dafc0e43", "587082d7b0ad4c7fb985cb80c10fcb4a", "6b62572975f44b579f0c45db436d7ab3", "e6737f67833744ad81c7e777d4c00339", "d4b7fd062f9441acb627ac78c40f3c53", "92c5af5998a94f3789013c7b132a85da", "abfff74215f04bc0ba792759d5741b0d", "bc59e3149c384a1a862c2a2dbcdc5cb6", "6590afcf2dd34bcb92e3dea7c03feeab", "9de5fd6c3f384174a494fbc21063762e", "150b7dc6d536416885a0feac36590d60", "c3efdfb00ae4409c88af13eccc9feafc", "4c30a61ec8ec49398fce28254d525c9e", "f497c9b05ba7450699bb5249efdcdd78", "d22bc41a3cc24a3b8af5a0b757a50772", "8d2aaedb349740be9631a8d06dadaa0d", "75aab13f7e3545bd8bfcaa93588be53d", "38f925efe22c4e07ad4e26b43c77efbf", "2965fd0946a240ccb2a107733892e2e3" ] }, "id": "jFjF5q2E0qyK", "outputId": "a3fb48ec-2487-4fb9-d93c-dc993020a52d" }, "outputs": [], "source": [ "from transformers import AutoModelForAudioClassification\n", "\n", "num_labels = len(id2label)\n", "\n", "model = AutoModelForAudioClassification.from_pretrained(\n", " model_id,\n", " num_labels=num_labels,\n", " label2id=label2id,\n", " id2label=id2label,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 145, "referenced_widgets": [ "8c23597b6abc4cf8b487cf766b49a6b2", "1b52606d686449f9a77a5c5321ca9ce5", "043f75f6d78a4d1ca7427f43ba1bb7cd", "4dce3211a1f143cea43853a83745692b", "7365f71967f6446f9f78eb89f012f348", "7f671f9b13114c31982d15550a301308", "791e8d132702459e8f1b0c5c8d60e9dd", "540fa5459a694eb5ac9747c306a63912", "ca77eb4d0599477faaaeb953a2e6f8a1", "81d830c97454458b9a093b32429613c8", "454ef1f88a2744e79e69e933834cade7", "7314bc0da35f433e93adc61c741c1ad9", "92b64987bf2843a89ae3fd239e2e929e", "20dd91b670e646ffa303ad76f66d04d8", "eaa7dbe42bad4d0283e6d9b507bf8e6a", "5aaad882c04e42d88c0dd15384b096cb", "c3a0f81d455e49afae01d787742aa6f4", "e8eb66948a5b4599aaace3d2520283ff", "408d33017f9349f8a31ea5fa8156bbb0", "a1092655795141a085b063e2b7f1c45a", "2cbb9d1cce814926a8f0e7458666fc44", "c440162fe99b42cabe7e0f136460fdc3", "9e65a231c1a14e4da50a053e7f8bb5ab", "4d193662761b4b52a5a7f759815faa3f", "1b70e404a2ba4668bac0e82ec7ce68c4", "171011631ac045599f2dd83388ebf9e3", "5ae1d20a96aa462f8ec8d60b6e55acb3", "b8de8534ea9a4e868d1683f5aeaabd58", "573ca706e5134763a429bf47dd39b2f4", "8fc0ed8838664cee88277304ae9fc6bc", "9e2c1b17dd524281af3f207059f36041", "7ca139ff1841490484b7e668effd52c8" ] }, "id": "R2dV29rf1Dvj", "outputId": "d22284bc-b1e1-4f5f-81c3-1108d2548108" }, "outputs": [], "source": [ "from huggingface_hub import notebook_login\n", "\n", "notebook_login()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Xxv5arIP1cyI" }, "outputs": [], "source": [ "from transformers import TrainingArguments\n", "\n", "model_name = \"distilhubert\"\n", "batch_size = 8\n", "gradient_accumulation_steps = 1\n", "num_train_epochs = 12\n", "\n", "training_args = TrainingArguments(\n", " f\"{model_name}-finetuned-gtzan\",\n", " evaluation_strategy=\"epoch\",\n", " save_strategy=\"epoch\",\n", " learning_rate=5e-5,\n", " per_device_train_batch_size=batch_size,\n", " gradient_accumulation_steps=gradient_accumulation_steps,\n", " per_device_eval_batch_size=batch_size,\n", " num_train_epochs=num_train_epochs,\n", " warmup_ratio=0.1,\n", " logging_steps=5,\n", " load_best_model_at_end=True,\n", " metric_for_best_model=\"accuracy\",\n", " fp16=True,\n", " push_to_hub=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "304c62f983bc4232a83bb429b5fc8d0c", "1fc3df88a70d46c0b67020afd379203a", "b4735b71f900407e8f2fe9f119b8f111", "ba1ff564aeb04f4396792b9cbdc1e0f5", "7480b817c9264eba8b0cbac25cfc3f10", "07a8375025d8401bbbcc43ab57633bc1", "9997f9a8942a489993f0ebd243d2e423", "b0d95b787b854b5c8271b04e112444b0", "37877593945a4a1891a8136badc92201", "7bead6838739449a8f6aeef66d59e9af", "9132e77095e1407aa1fb28db2f989514" ] }, "id": "NkqgKuNV1rBe", "outputId": "ca2ec7c8-80b0-4eea-98df-5ef644d818ae" }, "outputs": [], "source": [ "import evaluate\n", "\n", "metric = evaluate.load(\"accuracy\")\n", "\n", "def compute_metrics(eval_pred):\n", " \"\"\"Computes accuracy on a batch of predictions\"\"\"\n", " predictions = np.argmax(eval_pred.predictions, axis=1)\n", " return metric.compute(predictions=predictions, references=eval_pred.label_ids)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 359, "referenced_widgets": [ "b043a9063db14270b195d54c4e8c42ad", "24581013477447d1bb761d8517177e76", "8d73176ff94249468ccc2a9777407e22", "2a9f59358c554426b79cff091f55c487", "d9970f23d16e4e41a951cedb1dd47bfb", "bafa2bca542b40c0a357210e9c83c509", "11e193d3246f44a8869620cf786d5d62", "2cab9bba3d5747e79288511a99eb21a6", "d8744994d56f47aeb06cea8fb8dba07b", "95dceb9ab17e473c89f2c72a3f2a68a0", "255bfdc762b742a9ae3af4aa56da5b1c", "e069fce283f344e1a92ea47df36ef346", "d798661d4ed649cf85056e54406307cc", "0fe949d1ec35494bb4a7e8e7d1a8050d", "6d421970654c44058ef03b70ce557b60", "47f0c035c81241b19a06a77429740e92", "a0bc7f86b5614cd784f6b0686dfb2581", "e5e769fa3a1c448c8e3c213de225a431", "7ba8f6ce9d93449387d378444acc683d", "cdbe0ea3fd59430c923be729b1deade8", "155b4fa93ef94ab4975634cf39da0969", "6e1ddf6400fd4b07831ef86668001076", "4ff60ff736804323a077a0fa7e6d7ce4", "ec96fb7664d24a6cb28aff91e17cd4a8", "bee53fa1dc844b5d86e17805fe3087a0", "6c71c282f88e4404b34d7690d4224cca", "7b8aad8a749a44b9891ef56cd772f910", "402e1dbe1c7c4c00911b130f444aab18", "4affe25a3b85475fb11bda89bba7222a", "d48fd7b4ae6542b085c0f82b9c18ed69", "9bcb9506a4874c4ba080d3241e507dcc", "540ef1c963084116991ed2aea8c6fad3", "2304bff708e743cfb3f19e696f100432", "543cdbe9b3ce43a597c0f8509a7bbfa0", "533081161a804167a55ba0c19f0a9ddd", "76404f3e6a4d42cca4102c07a03ee159", "52b2ff0a584247d08422f77132ef610f", "633e9fd315dc45c9ab17bd787798c2a7", "285d0cfdeaee43d4a3c60de325ef5221", "c43b18364ba648148b6b57f5dd6ab849", "3bcdcfa52abb4ef0a285621885c28544", "457c501f18f347e88af360a29bfa9fdf", "02f40854352b46d9a1a0bc86d34b4af2", "4aae3489a85f41d68d970c536e13b29f", "e2e696fa8f1a433f944fe153b26c4eb0", "6497a86551214cbdb1281d47052fa5e4", "38789a16681c4c61a7a5148115346c60", "7ceffe69553a4ec59a66e1cebd94e541", "85543a17516f43d6ad4894f050ce35c7", "19f792849b3845dbb7492ebfa9a1f31a", "bdacb25547ce42cb9b4d26e27a251904", "bd32be802d19465e96eb7f927cc0e698", "b23180d8d2b84ef6accca1bd3a649ae6", "fd7bafa7326e4ee9ad050abf1aac3174", "8fc4551adb9c47c184ea72f013463157", "8adee9856a8743dba319f9c25e4c64a9", "fea935e8fdce40668b62482d53f00773", "3c9224f54fd24382ad669d1e90382d41", "0d68455f2d044561b80c09eefc7ff89c", "441b6c9ae6584592889ea1933f27cceb", "a1a2f8b305f04c41b6ab07b72b16b089", "f0f542be1e494419915b1ff98c0bdfb4", "749ff73cf55942ada26ac7bcf9082bca", "56472d58023241239cbfa4e620715fd7", "a6207d866ae64640ae1947e3ed557cac", "b2ec44989dcf437e9e4806b8925262c7" ] }, "id": "7OwwlTZe17kG", "outputId": "b6050257-ae63-42d7-a87e-14c5d631fd57" }, "outputs": [], "source": [ "from transformers import Trainer\n", "\n", "trainer = Trainer(\n", " model,\n", " training_args,\n", " train_dataset=gtzan_encoded[\"train\"],\n", " eval_dataset=gtzan_encoded_test,\n", " tokenizer=feature_extractor,\n", " compute_metrics=compute_metrics,\n", ")\n", "\n", "trainer.train()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "ZYmItvzH3JUp" }, "outputs": [], "source": [ "kwargs = {\n", " \"dataset_tags\": \"marsyas/gtzan\",\n", " \"dataset\": \"GTZAN\",\n", " \"model_name\": f\"{model_name}-finetuned-gtzan\",\n", " \"finetuned_from\": model_id,\n", " \"tasks\": \"audio-classification\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "BDzHhpmB3NW7" }, "outputs": [], "source": [ "trainer.push_to_hub(**kwargs)" ] } ], "metadata": { "accelerator": "GPU", "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "02f40854352b46d9a1a0bc86d34b4af2": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "043f75f6d78a4d1ca7427f43ba1bb7cd": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "PasswordModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "PasswordModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "PasswordView", "continuous_update": true, "description": "Token:", "description_tooltip": null, "disabled": false, "layout": "IPY_MODEL_81d830c97454458b9a093b32429613c8", "placeholder": "", "style": "IPY_MODEL_454ef1f88a2744e79e69e933834cade7", "value": "" } }, "07a8375025d8401bbbcc43ab57633bc1": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "0855f8f1ffeb4a188f41f575c23d8bb0": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "0d68455f2d044561b80c09eefc7ff89c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_a6207d866ae64640ae1947e3ed557cac", "placeholder": "", "style": "IPY_MODEL_b2ec44989dcf437e9e4806b8925262c7", "value": " 90.4M/90.4M [00:12<00:00, 8.07MB/s]" } }, "0e04e42e9e8b4686b874f2ccb0c0a056": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_41bce9dcbe234759be06eac63b726c4d", "placeholder": "", "style": "IPY_MODEL_deaa4db17c4440448542f1f87c2f35f5", "value": "Downloading readme: 100%" } }, "0e3845e9fc1b4e57aface3964e934f65": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "0e405b15bb854d92a64fcdad5cc910fc": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "0fe949d1ec35494bb4a7e8e7d1a8050d": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_7ba8f6ce9d93449387d378444acc683d", "max": 44253, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_cdbe0ea3fd59430c923be729b1deade8", "value": 44253 } }, "117ba917e8ce4049bf92cf532554232f": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "11e193d3246f44a8869620cf786d5d62": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "12fb7db5df414b4eaee5f6adce00cba6": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_8861a3eb8393419e82dc5a7e28910b3d", "placeholder": "", "style": "IPY_MODEL_971bc859134c4256b2de8784815bbba3", "value": " 621/0 [00:00<00:00, 4950.97 examples/s]" } }, "148a4e3377b045f4bdeb945555535fb1": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "150b7dc6d536416885a0feac36590d60": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_8d2aaedb349740be9631a8d06dadaa0d", "max": 93985618, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_75aab13f7e3545bd8bfcaa93588be53d", "value": 93985618 } }, "155b4fa93ef94ab4975634cf39da0969": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "16053dc329874fc69ca7e0341df95b5c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_8139dd6394ee46c3bbf78c4939d3e3f2", "max": 214, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_22724782e3fc4707bd16b2f1edf51854", "value": 214 } }, "171011631ac045599f2dd83388ebf9e3": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "19f792849b3845dbb7492ebfa9a1f31a": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "1b52606d686449f9a77a5c5321ca9ce5": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_540fa5459a694eb5ac9747c306a63912", "placeholder": "", "style": "IPY_MODEL_ca77eb4d0599477faaaeb953a2e6f8a1", "value": "