I'm getting configparser.NoSectionError: No section: 'data' error. I've also found some relevant questions in this and this links, but neither of them worked for me. I've also checked the file path and it's correct.
Below is my main.py code:
import torch
import argparse
from utils.configparser_hook import get_config
from utils.global_variables import Global
from utils.initializer import initialize
from utils.runner import run
if __name__ == "__main__":
parser = argparse.ArgumentParser()
required_args = ["config"]
normal_args = ["gpu"]
for arg in required_args + normal_args:
parser.add_argument("--{}".format(arg), required=arg in required_args)
args = parser.parse_args()
device = torch.device("cuda:{}".format(args.gpu) if args.gpu and torch.cuda.is_available() else "cpu")
Global.device = device
print("Device:", device)
config = get_config(args.config)
config.add_section("runtime")
parameters = initialize(config, device)
run(parameters, config, device)
The content of config file is as follow:
[train]
epoch = 15
batch_size = 200
shuffle = True
valid_interval = 1
save_strategy = save_best
[test]
batch_size = 200
shuffle = False
[data]
reader_name = MavenReader
formatter_name = BilstmFormatter
word2vec_file = 100.utf8
split_labels = True
[model]
model_name = Bilstm
num_layers = 1
hidden_size = 256
dropout = 0.5
[optimizer]
optimizer_name = Adam
lr = 1e-3
weight_decay = 1e-8
Also, the ConfigParserHook class is as follow in which it parses the input config file:
import functools
import configparser
class ConfigParserHook(object):
def __init__(self):
self.config = configparser.RawConfigParser()
def read(self, config_file):
self.config.read(config_file, encoding="utf-8")
def set_hook(func_name):
@functools.wraps(getattr(configparser.RawConfigParser, func_name))
def wrapper(self, *args, **kwargs):
return getattr(self.config, func_name)(*args, **kwargs)
return wrapper
def get_config(config_file):
for func_name in dir(configparser.RawConfigParser):
if not func_name.startswith("_") and func_name != "read":
setattr(ConfigParserHook, func_name, set_hook(func_name))
setattr(ConfigParserHook, "__getitem__", set_hook("__getitem__"))
config = ConfigParserHook()
config.read(config_file)
return config
I'm running the script following the python main.py --config [path of config files]
command line and got the below error:
File "main.py", line 23, in <module>
parameters = initialize(config, device)
File "C:\Users\S3763411\Desktop\MAVEN-dataset-main\MAVEN-dataset-main\baselines\DMCNN_BiLSTM_(CRF)\utils\initializer.py", line 12, in initialize
reader = get_class("reader", config.get("data", "reader_name"))(config)
File "C:\Users\S3763411\Desktop\MAVEN-dataset-main\MAVEN-dataset-main\baselines\DMCNN_BiLSTM_(CRF)\utils\configparser_hook.py", line 14, in wrapper
return getattr(self.config, func_name)(*args, **kwargs)
File "E:\allennlp\lib\configparser.py", line 780, in get
d = self._unify_values(section, vars)
File "E:\allennlp\lib\configparser.py", line 1146, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'data'
I don't really understand why it raises this error while I'm defining the correct file path. Not quite sure what I'm doing wrong to get this error. Thanks for your time and help in advance.