MCPcopy
hub / github.com/huggingface/transformers / main

Function main

examples/pytorch/token-classification/run_ner.py:225–632  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

223
224
225def main():
226 # See all possible arguments in src/transformers/training_args.py
227 # or by passing the --help flag to this script.
228 # We now keep distinct sets of args, for a cleaner separation of concerns.
229
230 parser = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments))
231 if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
232 # If we pass only one argument to the script and it's the path to a json file,
233 # let's parse it to get our arguments.
234 model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1]))
235 else:
236 model_args, data_args, training_args = parser.parse_args_into_dataclasses()
237
238 # Setup logging
239 logging.basicConfig(
240 format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
241 datefmt="%m/%d/%Y %H:%M:%S",
242 handlers=[logging.StreamHandler(sys.stdout)],
243 )
244
245 if training_args.should_log:
246 # The default of training_args.log_level is passive, so we set log level at info here to have that default.
247 transformers.utils.logging.set_verbosity_info()
248
249 log_level = training_args.get_process_log_level()
250 logger.setLevel(log_level)
251 datasets.utils.logging.set_verbosity(log_level)
252 transformers.utils.logging.set_verbosity(log_level)
253 transformers.utils.logging.enable_default_handler()
254 transformers.utils.logging.enable_explicit_format()
255
256 # Log on each process the small summary:
257 logger.warning(
258 f"Process rank: {training_args.local_process_index}, device: {training_args.device}, n_gpu: {training_args.n_gpu}, "
259 + f"distributed training: {training_args.parallel_mode.value == 'distributed'}, 16-bits training: {training_args.fp16}"
260 )
261 logger.info(f"Training/evaluation parameters {training_args}")
262
263 # Set seed before initializing model.
264 set_seed(training_args.seed)
265
266 # Get the datasets: you can either provide your own CSV/JSON/TXT training and evaluation files (see below)
267 # or just provide the name of one of the public datasets available on the hub at https://huggingface.co/datasets/
268 # (the dataset will be downloaded automatically from the datasets Hub).
269 #
270 # For CSV/JSON files, this script will use the column called 'text' or the first column if no column called
271 # 'text' is found. You can easily tweak this behavior (see below).
272 #
273 # In distributed training, the load_dataset function guarantee that only one local process can concurrently
274 # download the dataset.
275 if data_args.dataset_name is not None:
276 # Downloading and loading a dataset from the hub.
277 raw_datasets = load_dataset(
278 data_args.dataset_name,
279 data_args.dataset_config_name,
280 cache_dir=model_args.cache_dir,
281 token=model_args.token,
282 trust_remote_code=model_args.trust_remote_code,

Callers 2

_mp_fnFunction · 0.70
run_ner.pyFile · 0.70

Calls 15

parse_json_fileMethod · 0.95
trainMethod · 0.95
save_modelMethod · 0.95
evaluateMethod · 0.95
predictMethod · 0.95
is_world_process_zeroMethod · 0.95
push_to_hubMethod · 0.95
create_model_cardMethod · 0.95
HfArgumentParserClass · 0.90
set_seedFunction · 0.90
PreTrainedConfigClass · 0.90

Tested by

no test coverage detected