UnboundLocalError: cannot access local variable 'input_ids' where it is not associated with a value

I get this error during evaluation while training using SimpleTransformers library on my local machine.

Full error message:

UnboundLocalError Traceback (most recent call last) Cell In[12], line 2 1 # Train the model ----> 2 model.train_model(train_file, eval_file=test_file) File ~\anaconda3\envs\training_pytorch\Lib\site-packages\simpletransformers\language_modeling\language_modeling_model.py:567, in LanguageModelingModel.train_model(self, train_file, output_dir, show_running_loss, args, eval_file, verbose, **kwargs) 563 train_dataset = self.load_and_cache_examples(train_file, verbose=verbose) 565 os.makedirs(output_dir, exist_ok=True) → 567 global_step, training_details = self.train( 568 train_dataset, 569 output_dir, 570 show_running_loss=show_running_loss, 571 eval_file=eval_file, 572 verbose=verbose, 573 **kwargs, 574 ) 576 self.save_model(output_dir, model=self.model) 577 if self.args.model_type == “electra”: File ~\anaconda3\envs\training_pytorch\Lib\site-packages\simpletransformers\language_modeling\language_modeling_model.py:1201, in LanguageModelingModel.train(self, train_dataset, output_dir, show_running_loss, eval_file, verbose, **kwargs) 1198 self.save_model(output_dir_current, optimizer, scheduler, model=model) 1200 if args.evaluate_during_training and args.evaluate_each_epoch: → 1201 results = self.eval_model( 1202 eval_file, 1203 verbose=verbose and args.evaluate_during_training_verbose, 1204 silent=args.evaluate_during_training_silent, 1205 **kwargs, 1206 ) 1208 self.save_model( 1209 output_dir_current, optimizer, scheduler, results=results 1210 ) 1212 training_progress_scores[“global_step”].append(global_step) File ~\anaconda3\envs\training_pytorch\Lib\site-packages\simpletransformers\language_modeling\language_modeling_model.py:1367, in LanguageModelingModel.eval_model(self, eval_file, output_dir, evaluate_generated_text, verbose, silent, **kwargs) 1362 eval_dataset = self.load_and_cache_examples( 1363 eval_file, evaluate=True, verbose=verbose, silent=silent 1364 ) 1365 os.makedirs(output_dir, exist_ok=True) → 1367 result = self.evaluate( 1368 eval_dataset, output_dir, verbose=verbose, silent=silent, **kwargs 1369 ) 1370 self.results.update(result) 1372 if verbose: File ~\anaconda3\envs\training_pytorch\Lib\site-packages\simpletransformers\language_modeling\language_modeling_model.py:1436, in LanguageModelingModel.evaluate(self, eval_dataset, output_dir, prefix, verbose, silent, **kwargs) 1430 if self.args.use_hf_datasets: 1431 input_ids = batch[“input_ids”] 1433 inputs, labels = ( 1434 mask_tokens(batch, tokenizer, args) 1435 if args.mlm → 1436 else (input_ids, input_ids) 1437 ) 1438 inputs = inputs.to(self.device) 1439 labels = labels.to(self.device) UnboundLocalError: cannot access local variable ‘input_ids’ where it is not associated with a value

1 Like

From the error description, you probably missed some part of the program.