marinone94
commited on
Commit
·
0a1c33d
1
Parent(s):
db1f503
split training in two, one per dataset
Browse files- old_run.sh +37 -0
- old_run_asr_ctc.py +911 -0
- run.sh +42 -6
- run_speech_recognition_ctc.py +79 -65
old_run.sh
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python run_speech_recognition_ctc.py \
|
2 |
+
--dataset_name="mozilla-foundation/common_voice_8_0,marinone94/nst_sv" \
|
3 |
+
--model_name_or_path="KBLab/wav2vec2-large-voxrex" \
|
4 |
+
--dataset_config_name="sv-SE,distant_channel" \
|
5 |
+
--train_split_name="train+validation,train" \
|
6 |
+
--eval_split_name="test,None" \
|
7 |
+
--output_dir="./" \
|
8 |
+
--overwrite_output_dir \
|
9 |
+
--num_train_epochs="3" \
|
10 |
+
--per_device_train_batch_size="32" \
|
11 |
+
--per_device_eval_batch_size="32" \
|
12 |
+
--gradient_accumulation_steps="4" \
|
13 |
+
--learning_rate="7.5e-4" \
|
14 |
+
--warmup_ratio="0.0" \
|
15 |
+
--length_column_name="input_length" \
|
16 |
+
--evaluation_strategy="steps" \
|
17 |
+
--save_strategy="steps" \
|
18 |
+
--eval_steps="100" \
|
19 |
+
--save_steps="100" \
|
20 |
+
--text_column_name="sentence" \
|
21 |
+
--chars_to_ignore , ? . ! \- \; \: \" “ % ‘ ” � — ’ … – \
|
22 |
+
--logging_steps="20" \
|
23 |
+
--layerdrop="0.0" \
|
24 |
+
--activation_dropout="0.1" \
|
25 |
+
--save_total_limit="2" \
|
26 |
+
--freeze_feature_encoder \
|
27 |
+
--feat_proj_dropout="0.0" \
|
28 |
+
--mask_time_prob="0.75" \
|
29 |
+
--mask_time_length="10" \
|
30 |
+
--mask_feature_prob="0.25" \
|
31 |
+
--mask_feature_length="64" \
|
32 |
+
--gradient_checkpointing \
|
33 |
+
--use_auth_token \
|
34 |
+
--fp16 \
|
35 |
+
--group_by_length \
|
36 |
+
--do_train --do_eval \
|
37 |
+
--push_to_hub
|
old_run_asr_ctc.py
ADDED
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding=utf-8
|
3 |
+
# Copyright 2021 The HuggingFace Inc. team. All rights reserved.
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
|
16 |
+
""" Fine-tuning a 🤗 Transformers CTC model for automatic speech recognition"""
|
17 |
+
|
18 |
+
import datetime
|
19 |
+
import functools
|
20 |
+
import json
|
21 |
+
import logging
|
22 |
+
import os
|
23 |
+
import re
|
24 |
+
import sys
|
25 |
+
import warnings
|
26 |
+
from dataclasses import dataclass, field
|
27 |
+
from typing import Dict, List, Optional, Union
|
28 |
+
|
29 |
+
import datasets
|
30 |
+
import numpy as np
|
31 |
+
import pandas as pd
|
32 |
+
import torch
|
33 |
+
import wandb
|
34 |
+
from datasets import DatasetDict, concatenate_datasets, load_dataset, load_metric
|
35 |
+
|
36 |
+
import transformers
|
37 |
+
from transformers import (
|
38 |
+
AutoConfig,
|
39 |
+
AutoFeatureExtractor,
|
40 |
+
AutoModelForCTC,
|
41 |
+
AutoProcessor,
|
42 |
+
AutoTokenizer,
|
43 |
+
HfArgumentParser,
|
44 |
+
Trainer,
|
45 |
+
TrainingArguments,
|
46 |
+
Wav2Vec2Processor,
|
47 |
+
set_seed,
|
48 |
+
)
|
49 |
+
from transformers.trainer_utils import get_last_checkpoint, is_main_process
|
50 |
+
from transformers.utils import check_min_version
|
51 |
+
from transformers.utils.versions import require_version
|
52 |
+
|
53 |
+
|
54 |
+
# Will error if the minimal version of Transformers is not installed. Remove at your own risks.
|
55 |
+
check_min_version("4.16.0.dev0")
|
56 |
+
|
57 |
+
require_version("datasets>=1.13.3", "To fix: pip install -r examples/pytorch/text-classification/requirements.txt")
|
58 |
+
|
59 |
+
|
60 |
+
logger = logging.getLogger(__name__)
|
61 |
+
|
62 |
+
|
63 |
+
def list_field(default=None, metadata=None):
|
64 |
+
return field(default_factory=lambda: default, metadata=metadata)
|
65 |
+
|
66 |
+
|
67 |
+
@dataclass
|
68 |
+
class ModelArguments:
|
69 |
+
"""
|
70 |
+
Arguments pertaining to which model/config/tokenizer we are going to fine-tune from.
|
71 |
+
"""
|
72 |
+
|
73 |
+
model_name_or_path: str = field(
|
74 |
+
metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}
|
75 |
+
)
|
76 |
+
tokenizer_name_or_path: Optional[str] = field(
|
77 |
+
default=None,
|
78 |
+
metadata={"help": "Path to pretrained tokenizer or tokenizer identifier from huggingface.co/models"},
|
79 |
+
)
|
80 |
+
cache_dir: Optional[str] = field(
|
81 |
+
default=None,
|
82 |
+
metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"},
|
83 |
+
)
|
84 |
+
freeze_feature_encoder: bool = field(
|
85 |
+
default=True, metadata={"help": "Whether to freeze the feature encoder layers of the model."}
|
86 |
+
)
|
87 |
+
attention_dropout: float = field(
|
88 |
+
default=0.0, metadata={"help": "The dropout ratio for the attention probabilities."}
|
89 |
+
)
|
90 |
+
activation_dropout: float = field(
|
91 |
+
default=0.0, metadata={"help": "The dropout ratio for activations inside the fully connected layer."}
|
92 |
+
)
|
93 |
+
feat_proj_dropout: float = field(default=0.0, metadata={"help": "The dropout ratio for the projected features."})
|
94 |
+
hidden_dropout: float = field(
|
95 |
+
default=0.0,
|
96 |
+
metadata={
|
97 |
+
"help": "The dropout probability for all fully connected layers in the embeddings, encoder, and pooler."
|
98 |
+
},
|
99 |
+
)
|
100 |
+
final_dropout: float = field(
|
101 |
+
default=0.0,
|
102 |
+
metadata={"help": "The dropout probability for the final projection layer."},
|
103 |
+
)
|
104 |
+
mask_time_prob: float = field(
|
105 |
+
default=0.05,
|
106 |
+
metadata={
|
107 |
+
"help": "Probability of each feature vector along the time axis to be chosen as the start of the vector"
|
108 |
+
"span to be masked. Approximately ``mask_time_prob * sequence_length // mask_time_length`` feature"
|
109 |
+
"vectors will be masked along the time axis."
|
110 |
+
},
|
111 |
+
)
|
112 |
+
mask_time_length: int = field(
|
113 |
+
default=10,
|
114 |
+
metadata={"help": "Length of vector span to mask along the time axis."},
|
115 |
+
)
|
116 |
+
mask_feature_prob: float = field(
|
117 |
+
default=0.0,
|
118 |
+
metadata={
|
119 |
+
"help": "Probability of each feature vector along the feature axis to be chosen as the start of the vector"
|
120 |
+
"span to be masked. Approximately ``mask_feature_prob * sequence_length // mask_feature_length`` feature bins will be masked along the time axis."
|
121 |
+
},
|
122 |
+
)
|
123 |
+
mask_feature_length: int = field(
|
124 |
+
default=10,
|
125 |
+
metadata={"help": "Length of vector span to mask along the feature axis."},
|
126 |
+
)
|
127 |
+
layerdrop: float = field(default=0.0, metadata={"help": "The LayerDrop probability."})
|
128 |
+
ctc_loss_reduction: Optional[str] = field(
|
129 |
+
default="mean", metadata={"help": "The way the ctc loss should be reduced. Should be one of 'mean' or 'sum'."}
|
130 |
+
)
|
131 |
+
|
132 |
+
|
133 |
+
@dataclass
|
134 |
+
class DataTrainingArguments:
|
135 |
+
"""
|
136 |
+
Arguments pertaining to what data we are going to input our model for training and eval.
|
137 |
+
|
138 |
+
Using `HfArgumentParser` we can turn this class
|
139 |
+
into argparse arguments to be able to specify them on
|
140 |
+
the command line.
|
141 |
+
"""
|
142 |
+
|
143 |
+
dataset_name: str = field(
|
144 |
+
metadata={
|
145 |
+
"help": "The name of the dataset to use (via the datasets library)."
|
146 |
+
" To use multiple datasets, specify them separated by a comma."
|
147 |
+
" e.g.: 'mozilla-foundation/common_voice_7_0,marinone94/nst_sv'"
|
148 |
+
}
|
149 |
+
)
|
150 |
+
dataset_config_name: str = field(
|
151 |
+
default=None, metadata={
|
152 |
+
"help": "The configuration name of the dataset to use (via the datasets library)."
|
153 |
+
" To use multiple datasets, specify them separated by a comma."
|
154 |
+
" e.g.: 'sv-SE,sv'"
|
155 |
+
}
|
156 |
+
)
|
157 |
+
train_split_name: str = field(
|
158 |
+
default="train+validation",
|
159 |
+
metadata={
|
160 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'train+validation'"
|
161 |
+
" To use multiple datasets, specify them separated by a comma."
|
162 |
+
" e.g.: 'train+validation,all'"
|
163 |
+
},
|
164 |
+
)
|
165 |
+
eval_split_name: str = field(
|
166 |
+
default="test",
|
167 |
+
metadata={
|
168 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'test'"
|
169 |
+
" To use multiple datasets, specify them separated by a comma."
|
170 |
+
" e.g.: 'test,None'"
|
171 |
+
},
|
172 |
+
)
|
173 |
+
audio_column_name: str = field(
|
174 |
+
default="audio",
|
175 |
+
metadata={"help": "The name of the dataset column containing the audio data. Defaults to 'audio'"},
|
176 |
+
)
|
177 |
+
text_column_name: str = field(
|
178 |
+
default="text",
|
179 |
+
metadata={"help": "The name of the dataset column containing the text data. Defaults to 'text'"},
|
180 |
+
)
|
181 |
+
overwrite_cache: bool = field(
|
182 |
+
default=False, metadata={"help": "Overwrite the cached preprocessed datasets or not."}
|
183 |
+
)
|
184 |
+
preprocessing_num_workers: Optional[int] = field(
|
185 |
+
default=None,
|
186 |
+
metadata={"help": "The number of processes to use for the preprocessing."},
|
187 |
+
)
|
188 |
+
max_train_samples: Optional[int] = field(
|
189 |
+
default=None,
|
190 |
+
metadata={
|
191 |
+
"help": "For debugging purposes or quicker training, truncate the number of training examples to this "
|
192 |
+
"value if set."
|
193 |
+
},
|
194 |
+
)
|
195 |
+
max_eval_samples: Optional[int] = field(
|
196 |
+
default=None,
|
197 |
+
metadata={
|
198 |
+
"help": "For debugging purposes or quicker training, truncate the number of validation examples to this "
|
199 |
+
"value if set."
|
200 |
+
},
|
201 |
+
)
|
202 |
+
chars_to_ignore: Optional[List[str]] = list_field(
|
203 |
+
default=None,
|
204 |
+
metadata={"help": "A list of characters to remove from the transcripts."},
|
205 |
+
)
|
206 |
+
eval_metrics: List[str] = list_field(
|
207 |
+
default=["wer"],
|
208 |
+
metadata={"help": "A list of metrics the model should be evaluated on. E.g. `'wer cer'`"},
|
209 |
+
)
|
210 |
+
max_duration_in_seconds: float = field(
|
211 |
+
default=20.0,
|
212 |
+
metadata={
|
213 |
+
"help": "Filter audio files that are longer than `max_duration_in_seconds` seconds to 'max_duration_in_seconds`"
|
214 |
+
},
|
215 |
+
)
|
216 |
+
min_duration_in_seconds: float = field(
|
217 |
+
default=0.0, metadata={"help": "Filter audio files that are shorter than `min_duration_in_seconds` seconds"}
|
218 |
+
)
|
219 |
+
preprocessing_only: bool = field(
|
220 |
+
default=False,
|
221 |
+
metadata={
|
222 |
+
"help": "Whether to only do data preprocessing and skip training. "
|
223 |
+
"This is especially useful when data preprocessing errors out in distributed training due to timeout. "
|
224 |
+
"In this case, one should run the preprocessing in a non-distributed setup with `preprocessing_only=True` "
|
225 |
+
"so that the cached datasets can consequently be loaded in distributed training"
|
226 |
+
},
|
227 |
+
)
|
228 |
+
use_auth_token: bool = field(
|
229 |
+
default=False,
|
230 |
+
metadata={
|
231 |
+
"help": "If :obj:`True`, will use the token generated when running"
|
232 |
+
":obj:`transformers-cli login` as HTTP bearer authorization for remote files."
|
233 |
+
},
|
234 |
+
)
|
235 |
+
unk_token: str = field(
|
236 |
+
default="[UNK]",
|
237 |
+
metadata={"help": "The unk token for the tokenizer"},
|
238 |
+
)
|
239 |
+
pad_token: str = field(
|
240 |
+
default="[PAD]",
|
241 |
+
metadata={"help": "The padding token for the tokenizer"},
|
242 |
+
)
|
243 |
+
word_delimiter_token: str = field(
|
244 |
+
default="|",
|
245 |
+
metadata={"help": "The word delimiter token for the tokenizer"},
|
246 |
+
)
|
247 |
+
phoneme_language: Optional[str] = field(
|
248 |
+
default=None,
|
249 |
+
metadata={
|
250 |
+
"help": "The target language that should be used be"
|
251 |
+
" passed to the tokenizer for tokenization. Note that"
|
252 |
+
" this is only relevant if the model classifies the"
|
253 |
+
" input audio to a sequence of phoneme sequences."
|
254 |
+
},
|
255 |
+
)
|
256 |
+
dataset_seed: Optional[int] = field(
|
257 |
+
default=None,
|
258 |
+
metadata={"help": "Seed for shuffling training data"},
|
259 |
+
)
|
260 |
+
|
261 |
+
|
262 |
+
@dataclass
|
263 |
+
class DataCollatorCTCWithPadding:
|
264 |
+
"""
|
265 |
+
Data collator that will dynamically pad the inputs received.
|
266 |
+
Args:
|
267 |
+
processor (:class:`~transformers.AutoProcessor`)
|
268 |
+
The processor used for proccessing the data.
|
269 |
+
padding (:obj:`bool`, :obj:`str` or :class:`~transformers.tokenization_utils_base.PaddingStrategy`, `optional`, defaults to :obj:`True`):
|
270 |
+
Select a strategy to pad the returned sequences (according to the model's padding side and padding index)
|
271 |
+
among:
|
272 |
+
* :obj:`True` or :obj:`'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
|
273 |
+
sequence if provided).
|
274 |
+
* :obj:`'max_length'`: Pad to a maximum length specified with the argument :obj:`max_length` or to the
|
275 |
+
maximum acceptable input length for the model if that argument is not provided.
|
276 |
+
* :obj:`False` or :obj:`'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of
|
277 |
+
different lengths).
|
278 |
+
max_length (:obj:`int`, `optional`):
|
279 |
+
Maximum length of the ``input_values`` of the returned list and optionally padding length (see above).
|
280 |
+
max_length_labels (:obj:`int`, `optional`):
|
281 |
+
Maximum length of the ``labels`` returned list and optionally padding length (see above).
|
282 |
+
pad_to_multiple_of (:obj:`int`, `optional`):
|
283 |
+
If set will pad the sequence to a multiple of the provided value.
|
284 |
+
This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability >=
|
285 |
+
7.5 (Volta).
|
286 |
+
"""
|
287 |
+
|
288 |
+
processor: AutoProcessor
|
289 |
+
padding: Union[bool, str] = "longest"
|
290 |
+
pad_to_multiple_of: Optional[int] = None
|
291 |
+
pad_to_multiple_of_labels: Optional[int] = None
|
292 |
+
|
293 |
+
def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
|
294 |
+
# split inputs and labels since they have to be of different lenghts and need
|
295 |
+
# different padding methods
|
296 |
+
input_features = [{"input_values": feature["input_values"]} for feature in features]
|
297 |
+
label_features = [{"input_ids": feature["labels"]} for feature in features]
|
298 |
+
|
299 |
+
batch = self.processor.pad(
|
300 |
+
input_features,
|
301 |
+
padding=self.padding,
|
302 |
+
pad_to_multiple_of=self.pad_to_multiple_of,
|
303 |
+
return_tensors="pt",
|
304 |
+
)
|
305 |
+
|
306 |
+
with self.processor.as_target_processor():
|
307 |
+
labels_batch = self.processor.pad(
|
308 |
+
label_features,
|
309 |
+
padding=self.padding,
|
310 |
+
pad_to_multiple_of=self.pad_to_multiple_of_labels,
|
311 |
+
return_tensors="pt",
|
312 |
+
)
|
313 |
+
|
314 |
+
# replace padding with -100 to ignore loss correctly
|
315 |
+
labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)
|
316 |
+
|
317 |
+
batch["labels"] = labels
|
318 |
+
|
319 |
+
return batch
|
320 |
+
|
321 |
+
|
322 |
+
def create_vocabulary_from_data(
|
323 |
+
datasets: DatasetDict,
|
324 |
+
word_delimiter_token: Optional[str] = None,
|
325 |
+
unk_token: Optional[str] = None,
|
326 |
+
pad_token: Optional[str] = None,
|
327 |
+
):
|
328 |
+
# Given training and test labels create vocabulary
|
329 |
+
def extract_all_chars(batch, vocab):
|
330 |
+
all_text = " ".join(batch)
|
331 |
+
return list(set(list(set(all_text)) + vocab))
|
332 |
+
|
333 |
+
batch_size = 10000
|
334 |
+
vocab = []
|
335 |
+
for i in range(0, datasets["train"].num_rows, 10000):
|
336 |
+
batch = datasets["train"].select(range(i, min(datasets["train"].num_rows, i+batch_size)))
|
337 |
+
vocab = extract_all_chars(batch["target_text"], vocab)
|
338 |
+
for i in range(0, datasets["eval"].num_rows, 10000):
|
339 |
+
batch = datasets["eval"].select(range(i, min(datasets["eval"].num_rows, i+batch_size)))
|
340 |
+
vocab = extract_all_chars(batch["target_text"], vocab)
|
341 |
+
|
342 |
+
vocab_dict = {v: k for k, v in enumerate(sorted(vocab))}
|
343 |
+
|
344 |
+
# replace white space with delimiter token
|
345 |
+
if word_delimiter_token is not None:
|
346 |
+
vocab_dict[word_delimiter_token] = vocab_dict[" "]
|
347 |
+
del vocab_dict[" "]
|
348 |
+
|
349 |
+
# add unk and pad token
|
350 |
+
if unk_token is not None:
|
351 |
+
vocab_dict[unk_token] = len(vocab_dict)
|
352 |
+
|
353 |
+
if pad_token is not None:
|
354 |
+
vocab_dict[pad_token] = len(vocab_dict)
|
355 |
+
|
356 |
+
return vocab_dict
|
357 |
+
|
358 |
+
|
359 |
+
def main():
|
360 |
+
# See all possible arguments in src/transformers/training_args.py
|
361 |
+
# or by passing the --help flag to this script.
|
362 |
+
# We now keep distinct sets of args, for a cleaner separation of concerns.
|
363 |
+
|
364 |
+
parser = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments))
|
365 |
+
if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
|
366 |
+
# If we pass only one argument to the script and it's the path to a json file,
|
367 |
+
# let's parse it to get our arguments.
|
368 |
+
model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1]))
|
369 |
+
else:
|
370 |
+
model_args, data_args, training_args = parser.parse_args_into_dataclasses()
|
371 |
+
|
372 |
+
# TODO: Replace with check of wandb env vars
|
373 |
+
try:
|
374 |
+
repo_name = os.getcwd().split("/")[-1]
|
375 |
+
run_name = f"{datetime.datetime.utcnow()}".replace(" ", "T")
|
376 |
+
os.environ["WANDB_PROJECT"] = repo_name
|
377 |
+
wandb.login()
|
378 |
+
training_args.report_to = ["wandb"]
|
379 |
+
training_args.run_name = run_name
|
380 |
+
# wandb.init()
|
381 |
+
except:
|
382 |
+
pass
|
383 |
+
|
384 |
+
# Detecting last checkpoint.
|
385 |
+
last_checkpoint = None
|
386 |
+
if os.path.isdir(training_args.output_dir) and training_args.do_train and not training_args.overwrite_output_dir:
|
387 |
+
last_checkpoint = get_last_checkpoint(training_args.output_dir)
|
388 |
+
if last_checkpoint is None and len(os.listdir(training_args.output_dir)) > 0:
|
389 |
+
raise ValueError(
|
390 |
+
f"Output directory ({training_args.output_dir}) already exists and is not empty. "
|
391 |
+
"Use --overwrite_output_dir to overcome."
|
392 |
+
)
|
393 |
+
elif last_checkpoint is not None:
|
394 |
+
logger.info(
|
395 |
+
f"Checkpoint detected, resuming training at {last_checkpoint}. To avoid this behavior, change "
|
396 |
+
"the `--output_dir` or add `--overwrite_output_dir` to train from scratch."
|
397 |
+
)
|
398 |
+
|
399 |
+
# Setup logging
|
400 |
+
logging.basicConfig(
|
401 |
+
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
|
402 |
+
datefmt="%m/%d/%Y %H:%M:%S",
|
403 |
+
handlers=[logging.StreamHandler(sys.stdout)],
|
404 |
+
)
|
405 |
+
logger.setLevel(logging.INFO if is_main_process(training_args.local_rank) else logging.WARN)
|
406 |
+
|
407 |
+
# Log on each process the small summary:
|
408 |
+
logger.warning(
|
409 |
+
f"Process rank: {training_args.local_rank}, device: {training_args.device}, n_gpu: {training_args.n_gpu}"
|
410 |
+
f"distributed training: {bool(training_args.local_rank != -1)}, 16-bits training: {training_args.fp16}"
|
411 |
+
)
|
412 |
+
# Set the verbosity to info of the Transformers logger (on main process only):
|
413 |
+
if is_main_process(training_args.local_rank):
|
414 |
+
transformers.utils.logging.set_verbosity_info()
|
415 |
+
logger.info("Training/evaluation parameters %s", training_args)
|
416 |
+
|
417 |
+
# Set seed before initializing model.
|
418 |
+
set_seed(training_args.seed)
|
419 |
+
|
420 |
+
# 1. First, let's load the dataset
|
421 |
+
raw_datasets = DatasetDict()
|
422 |
+
|
423 |
+
def common_cols(columns_a, columns_b):
|
424 |
+
col_a = set(columns_a)
|
425 |
+
col_b = set(columns_b)
|
426 |
+
return [col for col in col_a if col in col_b]
|
427 |
+
|
428 |
+
if training_args.do_train:
|
429 |
+
|
430 |
+
# Multiple datasets might need to be loaded from HF
|
431 |
+
# It assumes they all follow the common voice format
|
432 |
+
for (dataset_name, dataset_config_name, train_split_name) in zip(
|
433 |
+
data_args.dataset_name.split(","),
|
434 |
+
data_args.dataset_config_name.split(","),
|
435 |
+
data_args.train_split_name.split(","),
|
436 |
+
):
|
437 |
+
|
438 |
+
|
439 |
+
if train_split_name != "None":
|
440 |
+
if "train" not in raw_datasets:
|
441 |
+
raw_datasets["train"] = load_dataset(
|
442 |
+
dataset_name,
|
443 |
+
dataset_config_name,
|
444 |
+
split=train_split_name,
|
445 |
+
use_auth_token=data_args.use_auth_token,
|
446 |
+
)
|
447 |
+
min_columns_train = raw_datasets["train"].column_names
|
448 |
+
dataset_sampling_rate = raw_datasets["train"].features[data_args.audio_column_name].sampling_rate
|
449 |
+
print(f"Dataset sampling rate: {dataset_sampling_rate}")
|
450 |
+
else:
|
451 |
+
new_dataset = DatasetDict()
|
452 |
+
new_dataset["train"] = load_dataset(
|
453 |
+
dataset_name,
|
454 |
+
dataset_config_name,
|
455 |
+
split=train_split_name,
|
456 |
+
use_auth_token=data_args.use_auth_token,
|
457 |
+
)
|
458 |
+
new_dataset_sampling_rate = next(iter(new_dataset.values())).features[data_args.audio_column_name].sampling_rate
|
459 |
+
if new_dataset_sampling_rate != dataset_sampling_rate:
|
460 |
+
print(f"New dataset sampling rate casted from {dataset_sampling_rate} to {dataset_sampling_rate}")
|
461 |
+
new_dataset["train"] = new_dataset["train"].cast_column(
|
462 |
+
data_args.audio_column_name, datasets.features.Audio(sampling_rate=dataset_sampling_rate)
|
463 |
+
)
|
464 |
+
raw_datasets["train"] = concatenate_datasets(
|
465 |
+
[
|
466 |
+
raw_datasets["train"],
|
467 |
+
new_dataset["train"]
|
468 |
+
]
|
469 |
+
)
|
470 |
+
min_columns_train = common_cols(min_columns_train, new_dataset.column_names)
|
471 |
+
else:
|
472 |
+
logging.warning(f"{dataset_name} {dataset_config_name} train not loaded as split is {train_split_name}")
|
473 |
+
|
474 |
+
if data_args.audio_column_name not in raw_datasets["train"].column_names:
|
475 |
+
raise ValueError(
|
476 |
+
f"--audio_column_name '{data_args.audio_column_name}' not found in dataset '{data_args.dataset_name}'. "
|
477 |
+
"Make sure to set `--audio_column_name` to the correct audio column - one of "
|
478 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
479 |
+
)
|
480 |
+
|
481 |
+
if data_args.text_column_name not in raw_datasets["train"].column_names:
|
482 |
+
raise ValueError(
|
483 |
+
f"--text_column_name {data_args.text_column_name} not found in dataset '{data_args.dataset_name}'. "
|
484 |
+
"Make sure to set `--text_column_name` to the correct text column - one of "
|
485 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
486 |
+
)
|
487 |
+
|
488 |
+
if data_args.max_train_samples is not None:
|
489 |
+
raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
|
490 |
+
other_columns_train = [col for col in raw_datasets["train"].column_names if col not in min_columns_train]
|
491 |
+
raw_datasets["train"].remove_columns(other_columns_train)
|
492 |
+
|
493 |
+
# pd_train_head = raw_datasets["train"].select(range(10)).to_pandas()
|
494 |
+
# pd_train_tail = raw_datasets["train"].select(range(raw_datasets["train"].num_rows-10, raw_datasets["train"].num_rows)).to_pandas()
|
495 |
+
# pd_train = pd.concat([pd_train_head, pd_train_tail])
|
496 |
+
# print(pd_train["audio"])
|
497 |
+
|
498 |
+
if training_args.do_eval:
|
499 |
+
# Multiple datasets might need to be loaded from HF
|
500 |
+
# It assumes they all follow the common voice format
|
501 |
+
for (dataset_name, dataset_config_name, eval_split_name) in zip(
|
502 |
+
data_args.dataset_name.split(","),
|
503 |
+
data_args.dataset_config_name.split(","),
|
504 |
+
data_args.eval_split_name.split(","),
|
505 |
+
):
|
506 |
+
|
507 |
+
if eval_split_name != "None":
|
508 |
+
if "eval" not in raw_datasets:
|
509 |
+
raw_datasets["eval"] = load_dataset(
|
510 |
+
dataset_name,
|
511 |
+
dataset_config_name,
|
512 |
+
split=eval_split_name,
|
513 |
+
use_auth_token=data_args.use_auth_token,
|
514 |
+
)
|
515 |
+
min_columns_eval = raw_datasets["eval"].column_names
|
516 |
+
dataset_sampling_rate = raw_datasets["eval"].features[data_args.audio_column_name].sampling_rate
|
517 |
+
print(f"Dataset sampling rate: {dataset_sampling_rate}")
|
518 |
+
else:
|
519 |
+
new_dataset = DatasetDict()
|
520 |
+
new_dataset["eval"] = load_dataset(
|
521 |
+
dataset_name,
|
522 |
+
dataset_config_name,
|
523 |
+
split=train_split_name,
|
524 |
+
use_auth_token=data_args.use_auth_token,
|
525 |
+
)
|
526 |
+
new_dataset_sampling_rate = new_dataset["eval"].features[data_args.audio_column_name].sampling_rate
|
527 |
+
if new_dataset_sampling_rate != dataset_sampling_rate:
|
528 |
+
print(f"New dataset sampling rate casted from {dataset_sampling_rate} to {dataset_sampling_rate}")
|
529 |
+
new_dataset["eval"] = new_dataset["eval"].cast_column(
|
530 |
+
data_args.audio_column_name, datasets.features.Audio(sampling_rate=dataset_sampling_rate)
|
531 |
+
)
|
532 |
+
raw_datasets["eval"] = concatenate_datasets(
|
533 |
+
[
|
534 |
+
raw_datasets["eval"],
|
535 |
+
new_dataset["eval"]
|
536 |
+
]
|
537 |
+
)
|
538 |
+
min_columns_eval = common_cols(min_columns_eval, new_dataset.column_names)
|
539 |
+
else:
|
540 |
+
logging.warning(f"{dataset_name} {dataset_config_name} eval not loaded as split is {eval_split_name}")
|
541 |
+
|
542 |
+
if data_args.max_eval_samples is not None:
|
543 |
+
raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
|
544 |
+
other_columns_eval = [col for col in raw_datasets["eval"].column_names if col not in min_columns_eval]
|
545 |
+
raw_datasets["eval"].remove_columns(other_columns_eval)
|
546 |
+
|
547 |
+
# pd_eval_head = raw_datasets["eval"].select(range(10)).to_pandas()
|
548 |
+
# pd_eval_tail = raw_datasets["eval"].select(range(raw_datasets["eval"].num_rows-10, raw_datasets["eval"].num_rows)).to_pandas()
|
549 |
+
# pd_eval = pd.concat([pd_eval_head, pd_eval_tail])
|
550 |
+
# print(pd_eval["audio"])
|
551 |
+
|
552 |
+
# 2. We remove some special characters from the datasets
|
553 |
+
# that make training complicated and do not help in transcribing the speech
|
554 |
+
# E.g. characters, such as `,` and `.` do not really have an acoustic characteristic
|
555 |
+
# that could be easily picked up by the model
|
556 |
+
chars_to_ignore_regex = (
|
557 |
+
f'[{"".join(data_args.chars_to_ignore)}]' if data_args.chars_to_ignore is not None else None
|
558 |
+
)
|
559 |
+
text_column_name = data_args.text_column_name
|
560 |
+
|
561 |
+
def is_text_valid(text):
|
562 |
+
for token in text.split():
|
563 |
+
if len(token) > 1:
|
564 |
+
return True
|
565 |
+
return False
|
566 |
+
|
567 |
+
def remove_special_characters(batch):
|
568 |
+
if chars_to_ignore_regex is not None:
|
569 |
+
batch["target_text"] = \
|
570 |
+
re.sub(chars_to_ignore_regex, "", batch[text_column_name]) \
|
571 |
+
.replace("\\\\Punkt", "") \
|
572 |
+
.replace("\\\\Komma", "") \
|
573 |
+
.replace("è", "e") \
|
574 |
+
.replace("é", "e") \
|
575 |
+
.replace("î", "i") \
|
576 |
+
.replace("ü", "u") \
|
577 |
+
.replace("ÿ", "y") \
|
578 |
+
.replace("ô", "o") \
|
579 |
+
.replace("\\", "") \
|
580 |
+
.replace("/", "") \
|
581 |
+
.replace("|", "") \
|
582 |
+
.lower() + " "
|
583 |
+
else:
|
584 |
+
batch["target_text"] = batch[text_column_name] \
|
585 |
+
.replace("\\\\Punkt", "") \
|
586 |
+
.replace("\\\\Komma", "") \
|
587 |
+
.replace("è", "e") \
|
588 |
+
.replace("é", "e") \
|
589 |
+
.replace("î", "i") \
|
590 |
+
.replace("ü", "u") \
|
591 |
+
.replace("ÿ", "y") \
|
592 |
+
.replace("ô", "o") \
|
593 |
+
.replace("\\", "") \
|
594 |
+
.replace("/", "") \
|
595 |
+
.replace("|", "") \
|
596 |
+
.lower() + " "
|
597 |
+
return batch
|
598 |
+
|
599 |
+
num_workers = data_args.preprocessing_num_workers
|
600 |
+
with training_args.main_process_first(desc="dataset map special characters removal"):
|
601 |
+
raw_datasets = raw_datasets.map(
|
602 |
+
remove_special_characters,
|
603 |
+
remove_columns=[text_column_name],
|
604 |
+
desc="remove special characters from datasets",
|
605 |
+
)
|
606 |
+
|
607 |
+
raw_datasets = raw_datasets.filter(
|
608 |
+
is_text_valid,
|
609 |
+
num_proc=num_workers,
|
610 |
+
input_columns=["target_text"],
|
611 |
+
desc="remove single words, single chars and 'W O R D S'",
|
612 |
+
)
|
613 |
+
|
614 |
+
# save special tokens for tokenizer
|
615 |
+
word_delimiter_token = data_args.word_delimiter_token
|
616 |
+
unk_token = data_args.unk_token
|
617 |
+
pad_token = data_args.pad_token
|
618 |
+
|
619 |
+
# 3. Next, let's load the config as we might need it to create
|
620 |
+
# the tokenizer
|
621 |
+
# load config
|
622 |
+
config = AutoConfig.from_pretrained(
|
623 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
624 |
+
)
|
625 |
+
|
626 |
+
# 4. Next, if no tokenizer file is defined,
|
627 |
+
# we create the vocabulary of the model by extracting all unique characters from
|
628 |
+
# the training and evaluation datasets
|
629 |
+
# We need to make sure that only first rank saves vocabulary
|
630 |
+
# make sure all processes wait until vocab is created
|
631 |
+
tokenizer_name_or_path = model_args.tokenizer_name_or_path
|
632 |
+
tokenizer_kwargs = {}
|
633 |
+
if tokenizer_name_or_path is None:
|
634 |
+
# save vocab in training output dir
|
635 |
+
tokenizer_name_or_path = training_args.output_dir
|
636 |
+
|
637 |
+
vocab_file = os.path.join(tokenizer_name_or_path, "vocab.json")
|
638 |
+
|
639 |
+
with training_args.main_process_first():
|
640 |
+
if training_args.overwrite_output_dir and os.path.isfile(vocab_file):
|
641 |
+
os.remove(vocab_file)
|
642 |
+
|
643 |
+
with training_args.main_process_first(desc="dataset map vocabulary creation"):
|
644 |
+
if not os.path.isfile(vocab_file):
|
645 |
+
os.makedirs(tokenizer_name_or_path, exist_ok=True)
|
646 |
+
vocab_dict = create_vocabulary_from_data(
|
647 |
+
raw_datasets,
|
648 |
+
word_delimiter_token=word_delimiter_token,
|
649 |
+
unk_token=unk_token,
|
650 |
+
pad_token=pad_token,
|
651 |
+
)
|
652 |
+
|
653 |
+
# save vocab dict to be loaded into tokenizer
|
654 |
+
with open(vocab_file, "w") as file:
|
655 |
+
json.dump(vocab_dict, file)
|
656 |
+
|
657 |
+
# if tokenizer has just been created
|
658 |
+
# it is defined by `tokenizer_class` if present in config else by `model_type`
|
659 |
+
tokenizer_kwargs = {
|
660 |
+
"config": config if config.tokenizer_class is not None else None,
|
661 |
+
"tokenizer_type": config.model_type if config.tokenizer_class is None else None,
|
662 |
+
"unk_token": unk_token,
|
663 |
+
"pad_token": pad_token,
|
664 |
+
"word_delimiter_token": word_delimiter_token,
|
665 |
+
}
|
666 |
+
|
667 |
+
# 5. Now we can instantiate the feature extractor, tokenizer and model
|
668 |
+
# Note for distributed training, the .from_pretrained methods guarantee that only
|
669 |
+
# one local process can concurrently download model & vocab.
|
670 |
+
|
671 |
+
# load feature_extractor and tokenizer
|
672 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
673 |
+
tokenizer_name_or_path,
|
674 |
+
use_auth_token=data_args.use_auth_token,
|
675 |
+
**tokenizer_kwargs,
|
676 |
+
)
|
677 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
678 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
679 |
+
)
|
680 |
+
|
681 |
+
# adapt config
|
682 |
+
config.update(
|
683 |
+
{
|
684 |
+
"feat_proj_dropout": model_args.feat_proj_dropout,
|
685 |
+
"attention_dropout": model_args.attention_dropout,
|
686 |
+
"hidden_dropout": model_args.hidden_dropout,
|
687 |
+
"final_dropout": model_args.final_dropout,
|
688 |
+
"mask_time_prob": model_args.mask_time_prob,
|
689 |
+
"mask_time_length": model_args.mask_time_length,
|
690 |
+
"mask_feature_prob": model_args.mask_feature_prob,
|
691 |
+
"mask_feature_length": model_args.mask_feature_length,
|
692 |
+
"gradient_checkpointing": training_args.gradient_checkpointing,
|
693 |
+
"layerdrop": model_args.layerdrop,
|
694 |
+
"ctc_loss_reduction": model_args.ctc_loss_reduction,
|
695 |
+
"pad_token_id": tokenizer.pad_token_id,
|
696 |
+
"vocab_size": len(tokenizer),
|
697 |
+
"activation_dropout": model_args.activation_dropout,
|
698 |
+
}
|
699 |
+
)
|
700 |
+
|
701 |
+
# create model
|
702 |
+
model = AutoModelForCTC.from_pretrained(
|
703 |
+
model_args.model_name_or_path,
|
704 |
+
cache_dir=model_args.cache_dir,
|
705 |
+
config=config,
|
706 |
+
use_auth_token=data_args.use_auth_token,
|
707 |
+
)
|
708 |
+
|
709 |
+
# freeze encoder
|
710 |
+
if model_args.freeze_feature_encoder:
|
711 |
+
model.freeze_feature_encoder()
|
712 |
+
|
713 |
+
# 6. Now we preprocess the datasets including loading the audio, resampling and normalization
|
714 |
+
# Thankfully, `datasets` takes care of automatically loading and resampling the audio,
|
715 |
+
# so that we just need to set the correct target sampling rate and normalize the input
|
716 |
+
# via the `feature_extractor`
|
717 |
+
|
718 |
+
# make sure that dataset decodes audio with correct sampling rate
|
719 |
+
dataset_sampling_rate = next(iter(raw_datasets.values())).features[data_args.audio_column_name].sampling_rate
|
720 |
+
if dataset_sampling_rate != feature_extractor.sampling_rate:
|
721 |
+
raw_datasets = raw_datasets.cast_column(
|
722 |
+
data_args.audio_column_name, datasets.features.Audio(sampling_rate=feature_extractor.sampling_rate)
|
723 |
+
)
|
724 |
+
|
725 |
+
# derive max & min input length for sample rate & max duration
|
726 |
+
max_input_length = data_args.max_duration_in_seconds * feature_extractor.sampling_rate
|
727 |
+
min_input_length = data_args.min_duration_in_seconds * feature_extractor.sampling_rate
|
728 |
+
audio_column_name = data_args.audio_column_name
|
729 |
+
|
730 |
+
# `phoneme_language` is only relevant if the model is fine-tuned on phoneme classification
|
731 |
+
phoneme_language = data_args.phoneme_language
|
732 |
+
|
733 |
+
# Preprocessing the datasets.
|
734 |
+
# We need to read the audio files as arrays and tokenize the targets.
|
735 |
+
def prepare_dataset(batch):
|
736 |
+
# load audio
|
737 |
+
sample = batch[audio_column_name]
|
738 |
+
|
739 |
+
inputs = feature_extractor(sample["array"], sampling_rate=sample["sampling_rate"])
|
740 |
+
batch["input_values"] = inputs.input_values[0]
|
741 |
+
batch["input_length"] = len(batch["input_values"])
|
742 |
+
|
743 |
+
# encode targets
|
744 |
+
additional_kwargs = {}
|
745 |
+
if phoneme_language is not None:
|
746 |
+
additional_kwargs["phonemizer_lang"] = phoneme_language
|
747 |
+
|
748 |
+
batch["labels"] = tokenizer(batch["target_text"], **additional_kwargs).input_ids
|
749 |
+
return batch
|
750 |
+
|
751 |
+
with training_args.main_process_first(desc="dataset map preprocessing"):
|
752 |
+
vectorized_datasets = DatasetDict()
|
753 |
+
vectorized_datasets["train"] = raw_datasets["train"].map(
|
754 |
+
prepare_dataset,
|
755 |
+
remove_columns=raw_datasets["train"].column_names,
|
756 |
+
num_proc=num_workers,
|
757 |
+
desc="preprocess datasets",
|
758 |
+
)
|
759 |
+
vectorized_datasets["eval"] = raw_datasets["eval"].map(
|
760 |
+
prepare_dataset,
|
761 |
+
remove_columns=raw_datasets["eval"].column_names,
|
762 |
+
num_proc=num_workers,
|
763 |
+
desc="preprocess datasets",
|
764 |
+
)
|
765 |
+
|
766 |
+
def is_audio_in_length_range(length):
|
767 |
+
return length > min_input_length and length < max_input_length
|
768 |
+
|
769 |
+
# filter data that is shorter than min_input_length
|
770 |
+
vectorized_datasets = vectorized_datasets.filter(
|
771 |
+
is_audio_in_length_range,
|
772 |
+
num_proc=num_workers,
|
773 |
+
input_columns=["input_length"],
|
774 |
+
)
|
775 |
+
|
776 |
+
# 7. Next, we can prepare the training.
|
777 |
+
# Let's use word error rate (WER) as our evaluation metric,
|
778 |
+
# instantiate a data collator and the trainer
|
779 |
+
|
780 |
+
# Define evaluation metrics during training, *i.e.* word error rate, character error rate
|
781 |
+
eval_metrics = {metric: load_metric(metric) for metric in data_args.eval_metrics}
|
782 |
+
|
783 |
+
# If dataset_seed is set, shuffle train
|
784 |
+
if data_args.dataset_seed is not None:
|
785 |
+
vectorized_datasets["train"] = vectorized_datasets["train"].shuffle(seed=data_args.dataset_seed)
|
786 |
+
|
787 |
+
# TODO: Log sample of datasets in the right way (see wandb docs)
|
788 |
+
pd_train = vectorized_datasets["train"].select(range(10)).to_pandas()
|
789 |
+
pd_eval = vectorized_datasets["eval"].select(range(10)).to_pandas()
|
790 |
+
# wandb.log({"train_sample": pd_train})
|
791 |
+
# wandb.log({"eval_sample": pd_eval})
|
792 |
+
|
793 |
+
# for large datasets it is advised to run the preprocessing on a
|
794 |
+
# single machine first with ``args.preprocessing_only`` since there will mostly likely
|
795 |
+
# be a timeout when running the script in distributed mode.
|
796 |
+
# In a second step ``args.preprocessing_only`` can then be set to `False` to load the
|
797 |
+
# cached dataset
|
798 |
+
if data_args.preprocessing_only:
|
799 |
+
logger.info(f"Data preprocessing finished. Files cached at {vectorized_datasets.cache_files}")
|
800 |
+
return
|
801 |
+
|
802 |
+
def compute_metrics(pred):
|
803 |
+
pred_logits = pred.predictions
|
804 |
+
pred_ids = np.argmax(pred_logits, axis=-1)
|
805 |
+
|
806 |
+
pred.label_ids[pred.label_ids == -100] = tokenizer.pad_token_id
|
807 |
+
|
808 |
+
pred_str = tokenizer.batch_decode(pred_ids)
|
809 |
+
# we do not want to group tokens when computing the metrics
|
810 |
+
label_str = tokenizer.batch_decode(pred.label_ids, group_tokens=False)
|
811 |
+
|
812 |
+
metrics = {k: v.compute(predictions=pred_str, references=label_str) for k, v in eval_metrics.items()}
|
813 |
+
|
814 |
+
return metrics
|
815 |
+
|
816 |
+
# Now save everything to be able to create a single processor later
|
817 |
+
if is_main_process(training_args.local_rank):
|
818 |
+
# save feature extractor, tokenizer and config
|
819 |
+
feature_extractor.save_pretrained(training_args.output_dir)
|
820 |
+
tokenizer.save_pretrained(training_args.output_dir)
|
821 |
+
config.save_pretrained(training_args.output_dir)
|
822 |
+
|
823 |
+
try:
|
824 |
+
processor = AutoProcessor.from_pretrained(training_args.output_dir)
|
825 |
+
except (OSError, KeyError):
|
826 |
+
warnings.warn(
|
827 |
+
"Loading a processor from a feature extractor config that does not"
|
828 |
+
" include a `processor_class` attribute is deprecated and will be removed in v5. Please add the following "
|
829 |
+
" attribute to your `preprocessor_config.json` file to suppress this warning: "
|
830 |
+
" `'processor_class': 'Wav2Vec2Processor'`",
|
831 |
+
FutureWarning,
|
832 |
+
)
|
833 |
+
processor = Wav2Vec2Processor.from_pretrained(training_args.output_dir)
|
834 |
+
|
835 |
+
# Instantiate custom data collator
|
836 |
+
data_collator = DataCollatorCTCWithPadding(processor=processor)
|
837 |
+
|
838 |
+
# Initialize Trainer
|
839 |
+
trainer = Trainer(
|
840 |
+
model=model,
|
841 |
+
data_collator=data_collator,
|
842 |
+
args=training_args,
|
843 |
+
compute_metrics=compute_metrics,
|
844 |
+
train_dataset=vectorized_datasets["train"] if training_args.do_train else None,
|
845 |
+
eval_dataset=vectorized_datasets["eval"] if training_args.do_eval else None,
|
846 |
+
tokenizer=feature_extractor,
|
847 |
+
)
|
848 |
+
|
849 |
+
# 8. Finally, we can start training
|
850 |
+
|
851 |
+
# Training
|
852 |
+
if training_args.do_train:
|
853 |
+
|
854 |
+
# use last checkpoint if exist
|
855 |
+
if last_checkpoint is not None:
|
856 |
+
checkpoint = last_checkpoint
|
857 |
+
elif os.path.isdir(model_args.model_name_or_path):
|
858 |
+
checkpoint = model_args.model_name_or_path
|
859 |
+
else:
|
860 |
+
checkpoint = None
|
861 |
+
|
862 |
+
train_result = trainer.train(resume_from_checkpoint=checkpoint)
|
863 |
+
trainer.save_model()
|
864 |
+
|
865 |
+
metrics = train_result.metrics
|
866 |
+
max_train_samples = (
|
867 |
+
data_args.max_train_samples
|
868 |
+
if data_args.max_train_samples is not None
|
869 |
+
else len(vectorized_datasets["train"])
|
870 |
+
)
|
871 |
+
metrics["train_samples"] = min(max_train_samples, len(vectorized_datasets["train"]))
|
872 |
+
|
873 |
+
trainer.log_metrics("train", metrics)
|
874 |
+
trainer.save_metrics("train", metrics)
|
875 |
+
trainer.save_state()
|
876 |
+
|
877 |
+
# Evaluation
|
878 |
+
results = {}
|
879 |
+
if training_args.do_eval:
|
880 |
+
logger.info("*** Evaluate ***")
|
881 |
+
metrics = trainer.evaluate()
|
882 |
+
max_eval_samples = (
|
883 |
+
data_args.max_eval_samples if data_args.max_eval_samples is not None else len(vectorized_datasets["eval"])
|
884 |
+
)
|
885 |
+
metrics["eval_samples"] = min(max_eval_samples, len(vectorized_datasets["eval"]))
|
886 |
+
|
887 |
+
trainer.log_metrics("eval", metrics)
|
888 |
+
trainer.save_metrics("eval", metrics)
|
889 |
+
|
890 |
+
# Write model card and (optionally) push to hub
|
891 |
+
config_name = data_args.dataset_config_name if data_args.dataset_config_name is not None else "na"
|
892 |
+
kwargs = {
|
893 |
+
"finetuned_from": model_args.model_name_or_path,
|
894 |
+
"tasks": "speech-recognition",
|
895 |
+
"tags": ["automatic-speech-recognition", data_args.dataset_name],
|
896 |
+
"dataset_args": f"Config: {config_name}, Training split: {data_args.train_split_name}, Eval split: {data_args.eval_split_name}",
|
897 |
+
"dataset": f"{data_args.dataset_name.upper()} - {config_name.upper()}",
|
898 |
+
}
|
899 |
+
if "common_voice" in data_args.dataset_name:
|
900 |
+
kwargs["language"] = config_name
|
901 |
+
|
902 |
+
if training_args.push_to_hub:
|
903 |
+
trainer.push_to_hub(**kwargs)
|
904 |
+
else:
|
905 |
+
trainer.create_model_card(**kwargs)
|
906 |
+
|
907 |
+
return results
|
908 |
+
|
909 |
+
|
910 |
+
if __name__ == "__main__":
|
911 |
+
main()
|
run.sh
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
python run_speech_recognition_ctc.py \
|
2 |
-
--dataset_name="
|
3 |
--model_name_or_path="KBLab/wav2vec2-large-voxrex" \
|
4 |
-
--dataset_config_name="
|
5 |
-
--train_split_name="train
|
6 |
-
--eval_split_name="test
|
7 |
--output_dir="./" \
|
8 |
--overwrite_output_dir \
|
9 |
--num_train_epochs="3" \
|
10 |
--per_device_train_batch_size="32" \
|
11 |
--per_device_eval_batch_size="32" \
|
12 |
--gradient_accumulation_steps="4" \
|
13 |
-
--learning_rate="7.5e-
|
14 |
--warmup_ratio="0.02" \
|
15 |
--length_column_name="input_length" \
|
16 |
--evaluation_strategy="steps" \
|
@@ -20,7 +20,43 @@ python run_speech_recognition_ctc.py \
|
|
20 |
--text_column_name="sentence" \
|
21 |
--chars_to_ignore , ? . ! \- \; \: \" “ % ‘ ” � — ’ … – \
|
22 |
--logging_steps="20" \
|
23 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
--layerdrop="0.0" \
|
25 |
--activation_dropout="0.1" \
|
26 |
--save_total_limit="2" \
|
|
|
1 |
python run_speech_recognition_ctc.py \
|
2 |
+
--dataset_name="marinone94/nst_sv" \
|
3 |
--model_name_or_path="KBLab/wav2vec2-large-voxrex" \
|
4 |
+
--dataset_config_name="distant_channel" \
|
5 |
+
--train_split_name="train" \
|
6 |
+
--eval_split_name="test" \
|
7 |
--output_dir="./" \
|
8 |
--overwrite_output_dir \
|
9 |
--num_train_epochs="3" \
|
10 |
--per_device_train_batch_size="32" \
|
11 |
--per_device_eval_batch_size="32" \
|
12 |
--gradient_accumulation_steps="4" \
|
13 |
+
--learning_rate="7.5e-" \
|
14 |
--warmup_ratio="0.02" \
|
15 |
--length_column_name="input_length" \
|
16 |
--evaluation_strategy="steps" \
|
|
|
20 |
--text_column_name="sentence" \
|
21 |
--chars_to_ignore , ? . ! \- \; \: \" “ % ‘ ” � — ’ … – \
|
22 |
--logging_steps="20" \
|
23 |
+
--layerdrop="0.0" \
|
24 |
+
--activation_dropout="0.1" \
|
25 |
+
--save_total_limit="2" \
|
26 |
+
--freeze_feature_encoder \
|
27 |
+
--feat_proj_dropout="0.0" \
|
28 |
+
--mask_time_prob="0.75" \
|
29 |
+
--mask_time_length="10" \
|
30 |
+
--mask_feature_prob="0.25" \
|
31 |
+
--mask_feature_length="64" \
|
32 |
+
--gradient_checkpointing \
|
33 |
+
--use_auth_token \
|
34 |
+
--fp16 \
|
35 |
+
--group_by_length \
|
36 |
+
--do_train --do_eval \
|
37 |
+
--push_to_hub
|
38 |
+
|
39 |
+
python run_speech_recognition_ctc.py \
|
40 |
+
--dataset_name="mozilla-foundation/common_voice_8_0" \
|
41 |
+
--model_name_or_path="KBLab/wav2vec2-large-voxrex" \
|
42 |
+
--dataset_config_name="distant_channel" \
|
43 |
+
--train_split_name="train+validation" \
|
44 |
+
--eval_split_name="test" \
|
45 |
+
--output_dir="./" \
|
46 |
+
--num_train_epochs="50" \
|
47 |
+
--per_device_train_batch_size="32" \
|
48 |
+
--per_device_eval_batch_size="32" \
|
49 |
+
--gradient_accumulation_steps="4" \
|
50 |
+
--learning_rate="7.5e-5" \
|
51 |
+
--warmup_steps="2000" \
|
52 |
+
--length_column_name="input_length" \
|
53 |
+
--evaluation_strategy="steps" \
|
54 |
+
--save_strategy="steps" \
|
55 |
+
--eval_steps="500" \
|
56 |
+
--save_steps="500" \
|
57 |
+
--text_column_name="sentence" \
|
58 |
+
--chars_to_ignore , ? . ! \- \; \: \" “ % ‘ ” � — ’ … – \
|
59 |
+
--logging_steps="100" \
|
60 |
--layerdrop="0.0" \
|
61 |
--activation_dropout="0.1" \
|
62 |
--save_total_limit="2" \
|
run_speech_recognition_ctc.py
CHANGED
@@ -429,38 +429,45 @@ def main():
|
|
429 |
|
430 |
# Multiple datasets might need to be loaded from HF
|
431 |
# It assumes they all follow the common voice format
|
432 |
-
for (dataset_name, dataset_config_name, train_split_name) in zip(
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
):
|
437 |
|
438 |
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
|
465 |
if data_args.audio_column_name not in raw_datasets["train"].column_names:
|
466 |
raise ValueError(
|
@@ -478,8 +485,8 @@ def main():
|
|
478 |
|
479 |
if data_args.max_train_samples is not None:
|
480 |
raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
|
481 |
-
other_columns_train = [col for col in raw_datasets["train"].column_names if col not in min_columns_train]
|
482 |
-
raw_datasets["train"].remove_columns(other_columns_train)
|
483 |
|
484 |
# pd_train_head = raw_datasets["train"].select(range(10)).to_pandas()
|
485 |
# pd_train_tail = raw_datasets["train"].select(range(raw_datasets["train"].num_rows-10, raw_datasets["train"].num_rows)).to_pandas()
|
@@ -489,42 +496,49 @@ def main():
|
|
489 |
if training_args.do_eval:
|
490 |
# Multiple datasets might need to be loaded from HF
|
491 |
# It assumes they all follow the common voice format
|
492 |
-
for (dataset_name, dataset_config_name, eval_split_name) in zip(
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
):
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
|
524 |
if data_args.max_eval_samples is not None:
|
525 |
raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
|
526 |
-
other_columns_eval = [col for col in raw_datasets["eval"].column_names if col not in min_columns_eval]
|
527 |
-
raw_datasets["eval"].remove_columns(other_columns_eval)
|
528 |
|
529 |
# pd_eval_head = raw_datasets["eval"].select(range(10)).to_pandas()
|
530 |
# pd_eval_tail = raw_datasets["eval"].select(range(raw_datasets["eval"].num_rows-10, raw_datasets["eval"].num_rows)).to_pandas()
|
|
|
429 |
|
430 |
# Multiple datasets might need to be loaded from HF
|
431 |
# It assumes they all follow the common voice format
|
432 |
+
# for (dataset_name, dataset_config_name, train_split_name) in zip(
|
433 |
+
# data_args.dataset_name.split(","),
|
434 |
+
# data_args.dataset_config_name.split(","),
|
435 |
+
# data_args.train_split_name.split(","),
|
436 |
+
# ):
|
437 |
|
438 |
|
439 |
+
# if train_split_name != "None":
|
440 |
+
# if "train" not in raw_datasets:
|
441 |
+
# raw_datasets["train"] = load_dataset(
|
442 |
+
# dataset_name,
|
443 |
+
# dataset_config_name,
|
444 |
+
# split=train_split_name,
|
445 |
+
# use_auth_token=data_args.use_auth_token,
|
446 |
+
# )
|
447 |
+
# min_columns_train = raw_datasets["train"].column_names
|
448 |
+
# else:
|
449 |
+
# new_dataset = load_dataset(
|
450 |
+
# dataset_name,
|
451 |
+
# dataset_config_name,
|
452 |
+
# split=train_split_name,
|
453 |
+
# use_auth_token=data_args.use_auth_token,
|
454 |
+
# )
|
455 |
+
# raw_datasets["train"] = concatenate_datasets(
|
456 |
+
# [
|
457 |
+
# raw_datasets["train"],
|
458 |
+
# new_dataset
|
459 |
+
# ]
|
460 |
+
# )
|
461 |
+
# min_columns_train = common_cols(min_columns_train, new_dataset.column_names)
|
462 |
+
# else:
|
463 |
+
# logging.warning(f"{dataset_name} {dataset_config_name} train not loaded as split is {train_split_name}")
|
464 |
+
|
465 |
+
raw_datasets["train"] = load_dataset(
|
466 |
+
data_args.dataset_name,
|
467 |
+
data_args.dataset_config_name,
|
468 |
+
split=data_args.train_split_name,
|
469 |
+
use_auth_token=data_args.use_auth_token,
|
470 |
+
)
|
471 |
|
472 |
if data_args.audio_column_name not in raw_datasets["train"].column_names:
|
473 |
raise ValueError(
|
|
|
485 |
|
486 |
if data_args.max_train_samples is not None:
|
487 |
raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
|
488 |
+
# other_columns_train = [col for col in raw_datasets["train"].column_names if col not in min_columns_train]
|
489 |
+
# raw_datasets["train"].remove_columns(other_columns_train)
|
490 |
|
491 |
# pd_train_head = raw_datasets["train"].select(range(10)).to_pandas()
|
492 |
# pd_train_tail = raw_datasets["train"].select(range(raw_datasets["train"].num_rows-10, raw_datasets["train"].num_rows)).to_pandas()
|
|
|
496 |
if training_args.do_eval:
|
497 |
# Multiple datasets might need to be loaded from HF
|
498 |
# It assumes they all follow the common voice format
|
499 |
+
# for (dataset_name, dataset_config_name, eval_split_name) in zip(
|
500 |
+
# data_args.dataset_name.split(","),
|
501 |
+
# data_args.dataset_config_name.split(","),
|
502 |
+
# data_args.eval_split_name.split(","),
|
503 |
+
# ):
|
504 |
+
|
505 |
+
# if eval_split_name != "None":
|
506 |
+
# if "eval" not in raw_datasets:
|
507 |
+
# raw_datasets["eval"] = load_dataset(
|
508 |
+
# dataset_name,
|
509 |
+
# dataset_config_name,
|
510 |
+
# split=eval_split_name,
|
511 |
+
# use_auth_token=data_args.use_auth_token,
|
512 |
+
# )
|
513 |
+
# min_columns_eval = raw_datasets["eval"].column_names
|
514 |
+
# else:
|
515 |
+
# new_dataset = load_dataset(
|
516 |
+
# dataset_name,
|
517 |
+
# dataset_config_name,
|
518 |
+
# split=eval_split_name,
|
519 |
+
# use_auth_token=data_args.use_auth_token,
|
520 |
+
# )
|
521 |
+
# raw_datasets["eval"] = concatenate_datasets(
|
522 |
+
# [
|
523 |
+
# raw_datasets["eval"],
|
524 |
+
# new_dataset
|
525 |
+
# ]
|
526 |
+
# )
|
527 |
+
# min_columns_eval = common_cols(min_columns_eval, new_dataset.column_names)
|
528 |
+
# else:
|
529 |
+
# logging.warning(f"{dataset_name} {dataset_config_name} eval not loaded as split is {eval_split_name}")
|
530 |
+
|
531 |
+
raw_datasets["eval"] = load_dataset(
|
532 |
+
data_args.dataset_name,
|
533 |
+
data_args.dataset_config_name,
|
534 |
+
split=data_args.eval_split_name,
|
535 |
+
use_auth_token=data_args.use_auth_token,
|
536 |
+
)
|
537 |
|
538 |
if data_args.max_eval_samples is not None:
|
539 |
raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
|
540 |
+
# other_columns_eval = [col for col in raw_datasets["eval"].column_names if col not in min_columns_eval]
|
541 |
+
# raw_datasets["eval"].remove_columns(other_columns_eval)
|
542 |
|
543 |
# pd_eval_head = raw_datasets["eval"].select(range(10)).to_pandas()
|
544 |
# pd_eval_tail = raw_datasets["eval"].select(range(raw_datasets["eval"].num_rows-10, raw_datasets["eval"].num_rows)).to_pandas()
|