"
]
},
"execution_count": 16,
"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": 17,
"id": "833f0ebe",
"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": 18,
"id": "06d2bf9a",
"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-184b00bfb8aa2e66.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-8b5882414ea77072.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-3db1be060b3bc81d.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-6c1bbaf643bc5b5f.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-54f525e223e6e4ff.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-e1d9a3bde74cc37c.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-63b9566ab8c13005.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-57b75a9a4b1a9660.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-33f2de77aa38e989.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-5008166243ea7b2b.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-dc8dc0c047dc1c05.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a84df502424a3cb4.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-6a11a4a3280d39b8.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-93315f983e1a2ae9.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-2534e3d140b7f374.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-decaf49f8e8b5be8/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-3ca6f7f1d923400e.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-b5e44329345c21ce.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-12da16342ab2ddc3.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-59cd84dcce2af6d8.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a16f6b5197fbc4c9.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-d54449708673af7f.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a3e265dae408f0ce.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-f7d6406bc2011cb2.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-c1f6017df2a13df3.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-1f54c3872acab8c3.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-abbd70cf97c8fbdb.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-9f8e1f3440a42e0c.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-1502759588e87b89.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-453a18daa2a9e9cc.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-a258ce0e41871520.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-25e62e092344aab4.arrow\n",
"Loading cached processed dataset at /workspace/.cache/huggingface/datasets/csv/default-2ae3784a8d52f12b/0.0.0/6b9057d9e23d9d8a2f05b985917a0da84d70c5dae3d22ddd8a3f22fb01c69d9e/cache-e38f0aea7790ffdf.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": 41,
"id": "4b600726",
"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": 19,
"id": "e661ff49",
"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": 20,
"id": "84c914d0",
"metadata": {},
"outputs": [],
"source": [
"data_collator = DataCollatorCTCWithPadding(processor=processor, padding=True)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ccee9d9b",
"metadata": {},
"outputs": [],
"source": [
"wer_metric = load_metric(\"wer\")\n",
"# cer_metric = load_metric(\"cer\")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "f68a0d6e",
"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",
"# print(\"pred : \", pred_ids[0])\n",
"# print(\"label: \", pred.label_ids[0])\n",
"# print(\"-----------------\")\n",
" \n",
" wer = wer_metric.compute(predictions=pred_str, references=label_str)\n",
"\n",
" return {\"wer\": wer}"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "13f2e1d0",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Some weights of the model checkpoint at facebook/wav2vec2-xls-r-1b were not used when initializing Wav2Vec2ForCTC: ['project_hid.weight', 'quantizer.codevectors', 'project_q.weight', 'project_q.bias', 'quantizer.weight_proj.weight', 'quantizer.weight_proj.bias', 'project_hid.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-1b 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-1b\",\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": 24,
"id": "e5ce29d3",
"metadata": {},
"outputs": [],
"source": [
"model.freeze_feature_encoder()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "69d68721",
"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=75,\n",
" save_steps=400,\n",
" eval_steps=400,\n",
" logging_steps=100,\n",
" learning_rate=1e-5,\n",
" warmup_steps=2000,\n",
" save_total_limit=3,\n",
" load_best_model_at_end=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "19a742e3",
"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": 27,
"id": "ec1cabad",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"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 = 75\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 = 5475\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [5475/5475 5:17:18, Epoch 74/75]\n",
"
\n",
" \n",
" \n",
" \n",
" Step | \n",
" Training Loss | \n",
" Validation Loss | \n",
" Wer | \n",
"
\n",
" \n",
" \n",
" \n",
" 400 | \n",
" 3.567100 | \n",
" 12.021813 | \n",
" 1.000000 | \n",
"
\n",
" \n",
" 800 | \n",
" 3.515900 | \n",
" 10.633655 | \n",
" 1.000000 | \n",
"
\n",
" \n",
" 1200 | \n",
" 2.454300 | \n",
" 1.825636 | \n",
" 0.983858 | \n",
"
\n",
" \n",
" 1600 | \n",
" 1.943700 | \n",
" 1.123718 | \n",
" 0.917272 | \n",
"
\n",
" \n",
" 2000 | \n",
" 1.696000 | \n",
" 0.824568 | \n",
" 0.769976 | \n",
"
\n",
" \n",
" 2400 | \n",
" 1.534200 | \n",
" 0.643288 | \n",
" 0.659403 | \n",
"
\n",
" \n",
" 2800 | \n",
" 1.450900 | \n",
" 0.550019 | \n",
" 0.578692 | \n",
"
\n",
" \n",
" 3200 | \n",
" 1.347800 | \n",
" 0.507016 | \n",
" 0.490718 | \n",
"
\n",
" \n",
" 3600 | \n",
" 1.309600 | \n",
" 0.469202 | \n",
" 0.472559 | \n",
"
\n",
" \n",
" 4000 | \n",
" 1.253200 | \n",
" 0.444805 | \n",
" 0.447942 | \n",
"
\n",
" \n",
" 4400 | \n",
" 1.229100 | \n",
" 0.437418 | \n",
" 0.436642 | \n",
"
\n",
" \n",
" 4800 | \n",
" 1.196000 | \n",
" 0.431371 | \n",
" 0.430993 | \n",
"
\n",
" \n",
" 5200 | \n",
" 1.186200 | \n",
" 0.423944 | \n",
" 0.422115 | \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",
"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-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-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-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-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-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",
"\n",
"\n",
"Training completed. Do not forget to share your model on huggingface.co/models =)\n",
"\n",
"\n",
"Loading best model from ./checkpoint-5200 (score: 0.4239440858364105).\n"
]
},
{
"data": {
"text/plain": [
"TrainOutput(global_step=5475, training_loss=2.0858804112264555, metrics={'train_runtime': 19044.9812, 'train_samples_per_second': 9.266, 'train_steps_per_second': 0.287, 'total_flos': 8.13888461360448e+19, 'train_loss': 2.0858804112264555, 'epoch': 74.99})"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trainer.train()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "3666e499",
"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('vitouphy/wav2vec2-xls-r-1b-km')\n",
"trainer.save_model('.')"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "e52460e6",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"tokenizer config file saved in ./tokenizer_config.json\n",
"Special tokens file saved in ./special_tokens_map.json\n",
"added tokens file saved in ./added_tokens.json\n"
]
},
{
"data": {
"text/plain": [
"('./tokenizer_config.json',\n",
" './special_tokens_map.json',\n",
" './vocab.json',\n",
" './added_tokens.json')"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tokenizer.save_pretrained(\".\")\n",
"# tokenizer.push_to_hub('vitouphy/wav2vec2-xls-r-1b-km')"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "49e54770",
"metadata": {},
"outputs": [],
"source": [
"kwargs = {\n",
" \"finetuned_from\": \"facebook/wav2vec2-xls-r-1b\",\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": 42,
"id": "6ab99e82",
"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": 32,
"id": "5c8abdc9",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Configuration saved in vitouphy/wav2vec2-xls-r-1b-km/config.json\n",
"Model weights saved in vitouphy/wav2vec2-xls-r-1b-km/pytorch_model.bin\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2b7d33e02e974830824e8c1acccc1dbf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Upload file pytorch_model.bin: 0%| | 3.38k/3.59G [00:00, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"To https://huggingface.co/vitouphy/wav2vec2-xls-r-1b-km\n",
" 953f61b..183c558 main -> main\n",
"\n"
]
},
{
"data": {
"text/plain": [
"'https://huggingface.co/vitouphy/wav2vec2-xls-r-1b-km/commit/183c558dd0aa166ae36561174695557ff4117eed'"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# model.push_to_hub('vitouphy/wav2vec2-xls-r-1b-km')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7dfead73",
"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
}