import os import sys sys.path.append(".") import logging import logging.config from text_classification import utils # Directories BASE_DIR = os.getcwd() # project root APP_DIR = os.path.dirname(__file__) # app root LOGS_DIR = os.path.join(BASE_DIR, 'logs') EMBEDDINGS_DIR = os.path.join(BASE_DIR, 'embeddings') # Create dirs utils.create_dirs(LOGS_DIR) utils.create_dirs(EMBEDDINGS_DIR) # Loggers log_config = utils.load_json( filepath=os.path.join(BASE_DIR, 'logging.json')) logging.config.dictConfig(log_config) logger = logging.getLogger('logger')
pretrained_embeddings=embedding_matrix, freeze_embeddings=args.freeze_embeddings) model = model.to(device) config.logger.info("→ Model:\n" f" {model.named_parameters}") # Define optimizer & scheduler optimizer = torch.optim.Adam(model.parameters(), lr=args.learning_rate) scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=3) # Model dir experiment_id = f'{int(time.time())}-{petname.Generate(2)}' experiment_dir = os.path.join(config.EXPERIMENTS_DIR, experiment_id) utils.create_dirs(dirpath=experiment_dir) model_path = os.path.join(experiment_dir, 'model.h5') # TensorBoard tb_log_dir = f'{experiment_dir}/tensorboard/' writer = SummaryWriter(log_dir=tb_log_dir) # Train best_val_loss = train(model=model, optimizer=optimizer, scheduler=scheduler, num_epochs=args.num_epochs, patience=args.patience, train_set=train_set, val_set=val_set, test_set=test_set,
import os import sys sys.path.append(".") import logging import logging.config from text_classification import utils # Directories BASE_DIR = os.getcwd() # project root APP_DIR = os.path.dirname(__file__) # app root LOGS_DIR = os.path.join(BASE_DIR, 'logs') EMBEDDINGS_DIR = os.path.join(BASE_DIR, 'embeddings') EXPERIMENTS_DIR = os.path.join(BASE_DIR, 'experiments') # Create dirs utils.create_dirs(LOGS_DIR) utils.create_dirs(EMBEDDINGS_DIR) utils.create_dirs(EXPERIMENTS_DIR) # Loggers log_config = utils.load_json( filepath=os.path.join(BASE_DIR, 'logging.json')) logging.config.dictConfig(log_config) logger = logging.getLogger('logger')