concept config file in category deep learning

This is an excerpt from Manning's book Deep Learning with Structured Data.
Config files are files that are external to your Python program where you can set parameter values. Your Python program reads the config file and uses the values from the config file for the parameters in the Python program. With config files you separate setting the parameter values from the Python code. This means you can update the parameter values and rerun your code without having to make updates to the code itself. This reduces the risk of introducing errors in your code when you update parameter values and keeps your code neater. For the streetcar delay prediction example, we have config files for all the major Python programs, as shown in Figure 3.1.
Figure 3.1 summary of the config files used in the streetcar delay prediction example
![]()
You can define config files for your Python program as JSON or YAML. For the streetcar delay prediction example in this book we use YAML. Here is the config file used by the streetcar_data_preparation notebook, streetcar_data_preparation_config.yml:
general: #A load_from_scratch: False #B save_transformed_dataframe: False #C remove_bad_values: True #D file_names: pickled_input_dataframe: 2014_2019_upto_june.pkl #E pickled_output_dataframe: 2014_2019_df_cleaned_remove_bad_oct18.pkl #FHere is the code in the streetcar_data_preparation notebook that reads the config file and sets the parameters based on the values in the config file:
current_path = os.getcwd() #A path_to_yaml = os.path.join(current_path, 'streetcar_data_preparation_config.yml') #B try: with open (path_to_yaml, 'r') as c_file: config = yaml.safe_load(c_file) #C except Exception as e: print('Error reading the config file') load_from_scratch = config['general']['load_from_scratch'] #D save_transformed_dataframe = config['general']['save_transformed_dataframe'] remove_bad_values = config['general']['remove_bad_values'] pickled_input_dataframe = config['file_names']['pickled_input_dataframe'] pickled_output_dataframe = config['file_names']['pickled_output_dataframe']In this section you have seen why we use config files with the major Python programs in the streetcar delay prediction example along with a description of the details of the config file for the data preparation code. Config files are particularly handy for this example because we are using pickle files to save the interim results. By setting the values for the file names of these pickle files in config files we can rerun the code on different interim result sets without having to modify the code itself.