"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import IPython.display as ipd\n",
"import numpy as np\n",
"import random\n",
"\n",
"rand_int = random.randint(0, len(common_voice_train)-1)\n",
"\n",
"print(\"Target text:\", common_voice_train[rand_int][\"sentence\"])\n",
"print(\"Input array shape:\", common_voice_train[rand_int][\"audio\"][\"array\"].shape)\n",
"print(\"Sampling rate:\", common_voice_train[rand_int][\"audio\"][\"sampling_rate\"])\n",
"ipd.Audio(data=common_voice_train[rand_int][\"audio\"][\"array\"], autoplay=False, rate=16000)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "07cc904e",
"metadata": {},
"outputs": [],
"source": [
"# This does not prepare the input for the Transformer model.\n",
"# This will resample the data and convert the sentence into indices\n",
"# Batch here is just for one entry (row)\n",
"def prepare_dataset(batch):\n",
" audio = batch[\"audio\"]\n",
" \n",
" # batched output is \"un-batched\"\n",
" batch[\"input_values\"] = processor(audio[\"array\"], sampling_rate=audio[\"sampling_rate\"]).input_values[0]\n",
" batch[\"input_length\"] = len(batch[\"input_values\"])\n",
" \n",
" with processor.as_target_processor():\n",
" batch[\"labels\"] = processor(batch[\"sentence\"]).input_ids\n",
" return batch"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "0a85ba00",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a8ad7f3bec152712.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-5802da9af6ac9ac7.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-418585d4baf07152.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-c7e5028c91005615.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-b96a6332cc5af3be.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-6a1544fcabe8e1c5.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-4926c7991e987d55.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-b607d477202e12db.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a04833a515432724.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-bee3e39e2b69f652.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-ad833922c61a3f31.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-ecf0c779c655274d.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-2ba17aaff236f685.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-5ab7f29ea26c63ef.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-240348bb32bdbb06.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-38e1126fb0ce94f8.arrow\n"
]
}
],
"source": [
"common_voice_train = common_voice_train.map(prepare_dataset, remove_columns=common_voice_train.column_names, num_proc=16)\n",
"common_voice_valid = common_voice_valid.map(prepare_dataset, remove_columns=common_voice_valid.column_names, num_proc=16)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "76d9219c",
"metadata": {},
"outputs": [],
"source": [
"# In case the dataset is too long which can lead to OOM. We should filter them out.\n",
"# max_input_length_in_sec = 5.0\n",
"# common_voice_train = common_voice_train.filter(lambda x: x < max_input_length_in_sec * processor.feature_extractor.sampling_rate, input_columns=[\"input_length\"])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "1d89d3df",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"\n",
"from dataclasses import dataclass, field\n",
"from typing import Any, Dict, List, Optional, Union\n",
"\n",
"@dataclass\n",
"class DataCollatorCTCWithPadding:\n",
" \"\"\"\n",
" Data collator that will dynamically pad the inputs received.\n",
" Args:\n",
" processor (:class:`~transformers.Wav2Vec2Processor`)\n",
" The processor used for proccessing the data.\n",
" padding (:obj:`bool`, :obj:`str` or :class:`~transformers.tokenization_utils_base.PaddingStrategy`, `optional`, defaults to :obj:`True`):\n",
" Select a strategy to pad the returned sequences (according to the model's padding side and padding index)\n",
" among:\n",
" * :obj:`True` or :obj:`'longest'`: Pad to the longest sequence in the batch (or no padding if only a single\n",
" sequence if provided).\n",
" * :obj:`'max_length'`: Pad to a maximum length specified with the argument :obj:`max_length` or to the\n",
" maximum acceptable input length for the model if that argument is not provided.\n",
" * :obj:`False` or :obj:`'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of\n",
" different lengths).\n",
" \"\"\"\n",
"\n",
" processor: Wav2Vec2Processor\n",
" padding: Union[bool, str] = True\n",
"\n",
" def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:\n",
" # split inputs and labels since they have to be of different lenghts and need\n",
" # different padding methods\n",
" input_features = [{\"input_values\": feature[\"input_values\"]} for feature in features]\n",
" label_features = [{\"input_ids\": feature[\"labels\"]} for feature in features]\n",
"\n",
" batch = self.processor.pad(\n",
" input_features,\n",
" padding=self.padding,\n",
" return_tensors=\"pt\",\n",
" )\n",
"\n",
" with self.processor.as_target_processor():\n",
" labels_batch = self.processor.pad(\n",
" label_features,\n",
" padding=self.padding,\n",
" return_tensors=\"pt\",\n",
" )\n",
"\n",
" # replace padding with -100 to ignore loss correctly\n",
" labels = labels_batch[\"input_ids\"].masked_fill(labels_batch.attention_mask.ne(1), -100)\n",
"\n",
" batch[\"labels\"] = labels\n",
"\n",
" return batch"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "d3b3ba57",
"metadata": {},
"outputs": [],
"source": [
"data_collator = DataCollatorCTCWithPadding(processor=processor, padding=True)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "6c33263a",
"metadata": {},
"outputs": [],
"source": [
"wer_metric = load_metric(\"wer\")\n",
"# cer_metric = load_metric(\"cer\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "7d2e7755",
"metadata": {},
"outputs": [],
"source": [
"def compute_metrics(pred):\n",
" pred_logits = pred.predictions\n",
" pred_ids = np.argmax(pred_logits, axis=-1)\n",
"\n",
" pred.label_ids[pred.label_ids == -100] = tokenizer.pad_token_id\n",
"\n",
" pred_str = tokenizer.batch_decode(pred_ids)\n",
" label_str = tokenizer.batch_decode(pred.label_ids, group_tokens=False)\n",
" \n",
" wer = wer_metric.compute(predictions=pred_str, references=label_str)\n",
"\n",
" return {\"wer\": wer}"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "8f05c6fd",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Some weights of the model checkpoint at facebook/wav2vec2-xls-r-300m were not used when initializing Wav2Vec2ForCTC: ['project_hid.bias', 'quantizer.codevectors', 'quantizer.weight_proj.weight', 'project_q.weight', 'project_hid.weight', 'quantizer.weight_proj.bias', 'project_q.bias']\n",
"- This IS expected if you are initializing Wav2Vec2ForCTC from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
"- This IS NOT expected if you are initializing Wav2Vec2ForCTC from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
"Some weights of Wav2Vec2ForCTC were not initialized from the model checkpoint at facebook/wav2vec2-xls-r-300m and are newly initialized: ['lm_head.weight', 'lm_head.bias']\n",
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
]
}
],
"source": [
"from transformers import Wav2Vec2ForCTC\n",
"\n",
"model = Wav2Vec2ForCTC.from_pretrained(\n",
" \"facebook/wav2vec2-xls-r-300m\", \n",
" attention_dropout=0.1,\n",
" layerdrop=0.0,\n",
" feat_proj_dropout=0.0,\n",
" mask_time_prob=0.75, \n",
" mask_time_length=10,\n",
" mask_feature_prob=0.25,\n",
" mask_feature_length=64,\n",
" ctc_loss_reduction=\"mean\",\n",
" pad_token_id=processor.tokenizer.pad_token_id,\n",
" vocab_size=len(processor.tokenizer)\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "ab8e1dfa",
"metadata": {},
"outputs": [],
"source": [
"model.freeze_feature_encoder()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "b46286e7",
"metadata": {},
"outputs": [],
"source": [
"from transformers import TrainingArguments\n",
"\n",
"training_args = TrainingArguments(\n",
" output_dir='.',\n",
" group_by_length=True,\n",
" per_device_train_batch_size=8,\n",
" gradient_accumulation_steps=4,\n",
" evaluation_strategy=\"steps\",\n",
" gradient_checkpointing=True,\n",
" fp16=True,\n",
" num_train_epochs=100,\n",
" save_steps=400,\n",
" eval_steps=400,\n",
" logging_steps=100,\n",
" learning_rate=5e-5,\n",
" warmup_steps=1000,\n",
" save_total_limit=3,\n",
" load_best_model_at_end=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "8545cd28",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using amp half precision backend\n"
]
}
],
"source": [
"from transformers import Trainer\n",
"\n",
"trainer = Trainer(\n",
" model=model,\n",
" data_collator=data_collator,\n",
" args=training_args,\n",
" compute_metrics=compute_metrics,\n",
" train_dataset=common_voice_train,\n",
" eval_dataset=common_voice_valid,\n",
" tokenizer=processor.feature_extractor,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "f7b39403",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The following columns in the training set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"/opt/conda/lib/python3.8/site-packages/transformers/optimization.py:306: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use thePyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning\n",
" warnings.warn(\n",
"***** Running training *****\n",
" Num examples = 2353\n",
" Num Epochs = 100\n",
" Instantaneous batch size per device = 8\n",
" Total train batch size (w. parallel, distributed & accumulation) = 32\n",
" Gradient Accumulation steps = 4\n",
" Total optimization steps = 7300\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [7300/7300 4:05:50, Epoch 99/100]\n",
"
\n",
" \n",
" \n",
" \n",
" Step | \n",
" Training Loss | \n",
" Validation Loss | \n",
" Wer | \n",
"
\n",
" \n",
" \n",
" \n",
" 400 | \n",
" 5.079500 | \n",
" 4.412057 | \n",
" 1.000000 | \n",
"
\n",
" \n",
" 800 | \n",
" 3.565800 | \n",
" 3.520337 | \n",
" 1.000000 | \n",
"
\n",
" \n",
" 1200 | \n",
" 3.368900 | \n",
" 2.898376 | \n",
" 0.999596 | \n",
"
\n",
" \n",
" 1600 | \n",
" 2.010000 | \n",
" 1.004076 | \n",
" 0.728814 | \n",
"
\n",
" \n",
" 2000 | \n",
" 1.678300 | \n",
" 0.694064 | \n",
" 0.598870 | \n",
"
\n",
" \n",
" 2400 | \n",
" 1.527000 | \n",
" 0.559943 | \n",
" 0.528249 | \n",
"
\n",
" \n",
" 2800 | \n",
" 1.427800 | \n",
" 0.482676 | \n",
" 0.480630 | \n",
"
\n",
" \n",
" 3200 | \n",
" 1.345800 | \n",
" 0.442869 | \n",
" 0.453188 | \n",
"
\n",
" \n",
" 3600 | \n",
" 1.289300 | \n",
" 0.415609 | \n",
" 0.433010 | \n",
"
\n",
" \n",
" 4000 | \n",
" 1.244100 | \n",
" 0.402046 | \n",
" 0.403955 | \n",
"
\n",
" \n",
" 4400 | \n",
" 1.188000 | \n",
" 0.377747 | \n",
" 0.386602 | \n",
"
\n",
" \n",
" 4800 | \n",
" 1.162800 | \n",
" 0.360746 | \n",
" 0.385795 | \n",
"
\n",
" \n",
" 5200 | \n",
" 1.132400 | \n",
" 0.353398 | \n",
" 0.360371 | \n",
"
\n",
" \n",
" 5600 | \n",
" 1.096900 | \n",
" 0.342845 | \n",
" 0.362389 | \n",
"
\n",
" \n",
" 6000 | \n",
" 1.089700 | \n",
" 0.338743 | \n",
" 0.356739 | \n",
"
\n",
" \n",
" 6400 | \n",
" 1.062500 | \n",
" 0.333874 | \n",
" 0.349879 | \n",
"
\n",
" \n",
" 6800 | \n",
" 1.060100 | \n",
" 0.328815 | \n",
" 0.344633 | \n",
"
\n",
" \n",
" 7200 | \n",
" 1.047400 | \n",
" 0.328094 | \n",
" 0.346247 | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-400\n",
"Configuration saved in ./checkpoint-400/config.json\n",
"Model weights saved in ./checkpoint-400/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-400/preprocessor_config.json\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-800\n",
"Configuration saved in ./checkpoint-800/config.json\n",
"Model weights saved in ./checkpoint-800/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-800/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-3200] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-1200\n",
"Configuration saved in ./checkpoint-1200/config.json\n",
"Model weights saved in ./checkpoint-1200/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-1200/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-3600] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-1600\n",
"Configuration saved in ./checkpoint-1600/config.json\n",
"Model weights saved in ./checkpoint-1600/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-1600/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-400] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-2000\n",
"Configuration saved in ./checkpoint-2000/config.json\n",
"Model weights saved in ./checkpoint-2000/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-2000/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-800] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-2400\n",
"Configuration saved in ./checkpoint-2400/config.json\n",
"Model weights saved in ./checkpoint-2400/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-2400/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-1200] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-2800\n",
"Configuration saved in ./checkpoint-2800/config.json\n",
"Model weights saved in ./checkpoint-2800/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-2800/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-1600] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-3200\n",
"Configuration saved in ./checkpoint-3200/config.json\n",
"Model weights saved in ./checkpoint-3200/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-3200/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-2000] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-3600\n",
"Configuration saved in ./checkpoint-3600/config.json\n",
"Model weights saved in ./checkpoint-3600/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-3600/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-2400] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-4000\n",
"Configuration saved in ./checkpoint-4000/config.json\n",
"Model weights saved in ./checkpoint-4000/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-4000/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-2800] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-4400\n",
"Configuration saved in ./checkpoint-4400/config.json\n",
"Model weights saved in ./checkpoint-4400/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-4400/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-3200] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-4800\n",
"Configuration saved in ./checkpoint-4800/config.json\n",
"Model weights saved in ./checkpoint-4800/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-4800/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-3600] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-5200\n",
"Configuration saved in ./checkpoint-5200/config.json\n",
"Model weights saved in ./checkpoint-5200/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-5200/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-4000] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-5600\n",
"Configuration saved in ./checkpoint-5600/config.json\n",
"Model weights saved in ./checkpoint-5600/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-5600/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-4400] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-6000\n",
"Configuration saved in ./checkpoint-6000/config.json\n",
"Model weights saved in ./checkpoint-6000/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-6000/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-4800] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-6400\n",
"Configuration saved in ./checkpoint-6400/config.json\n",
"Model weights saved in ./checkpoint-6400/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-6400/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-5200] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-6800\n",
"Configuration saved in ./checkpoint-6800/config.json\n",
"Model weights saved in ./checkpoint-6800/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-6800/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-5600] due to args.save_total_limit\n",
"The following columns in the evaluation set don't have a corresponding argument in `Wav2Vec2ForCTC.forward` and have been ignored: input_length.\n",
"***** Running Evaluation *****\n",
" Num examples = 262\n",
" Batch size = 8\n",
"Saving model checkpoint to ./checkpoint-7200\n",
"Configuration saved in ./checkpoint-7200/config.json\n",
"Model weights saved in ./checkpoint-7200/pytorch_model.bin\n",
"Configuration saved in ./checkpoint-7200/preprocessor_config.json\n",
"Deleting older checkpoint [checkpoint-6000] due to args.save_total_limit\n",
"\n",
"\n",
"Training completed. Do not forget to share your model on huggingface.co/models =)\n",
"\n",
"\n",
"Loading best model from ./checkpoint-7200 (score: 0.3280937969684601).\n"
]
},
{
"data": {
"text/plain": [
"TrainOutput(global_step=7300, training_loss=2.0282830110314776, metrics={'train_runtime': 14754.0737, 'train_samples_per_second': 15.948, 'train_steps_per_second': 0.495, 'total_flos': 3.5572390287970673e+19, 'train_loss': 2.0282830110314776, 'epoch': 99.99})"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trainer.train()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "9f476560",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "cc4997d8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"tokenizer config file saved in vitouphy/xls-r-300m-km/tokenizer_config.json\n",
"Special tokens file saved in vitouphy/xls-r-300m-km/special_tokens_map.json\n",
"added tokens file saved in vitouphy/xls-r-300m-km/added_tokens.json\n",
"To https://huggingface.co/vitouphy/xls-r-300m-km\n",
" 3ef5dfc..cb4f72c main -> main\n",
"\n"
]
},
{
"data": {
"text/plain": [
"'https://huggingface.co/vitouphy/xls-r-300m-km/commit/cb4f72cb420eee8ca1f44b582a9d3cfbcd258f3d'"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tokenizer.push_to_hub('vitouphy/xls-r-300m-km')"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "186d4678",
"metadata": {},
"outputs": [],
"source": [
"kwargs = {\n",
" \"finetuned_from\": \"facebook/wav2vec2-xls-r-300m\",\n",
" \"tasks\": \"speech-recognition\",\n",
" \"tags\": [\"automatic-speech-recognition\", \"openslr\", \"robust-speech-event\", \"km\"],\n",
" \"dataset_args\": f\"Config: km, Training split: train, Eval split: validation\",\n",
" \"dataset\": \"openslr\",\n",
" \"language\": \"km\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "c71021ea",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Dropping the following result as it does not have all the necessary fields:\n",
"{}\n"
]
}
],
"source": [
"trainer.create_model_card(**kwargs)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "3afcbfb5",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Configuration saved in vitouphy/xls-r-300m-km/config.json\n",
"Model weights saved in vitouphy/xls-r-300m-km/pytorch_model.bin\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "69dc015463b64e3c946ccfbe017d1828",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Upload file pytorch_model.bin: 0%| | 3.39k/1.18G [00:00, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"To https://huggingface.co/vitouphy/xls-r-300m-km\n",
" cb4f72c..8fe8876 main -> main\n",
"\n"
]
},
{
"data": {
"text/plain": [
"'https://huggingface.co/vitouphy/xls-r-300m-km/commit/8fe88762a9fca1dce5e056605465042b5700b69e'"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.push_to_hub('vitouphy/xls-r-300m-km')"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "fdc2a063",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Saving model checkpoint to .\n",
"Configuration saved in ./config.json\n",
"Model weights saved in ./pytorch_model.bin\n",
"Configuration saved in ./preprocessor_config.json\n"
]
}
],
"source": [
"trainer.save_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5eb9cc6c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}