@@ -0,0 +1,2626 @@
+from Data.msd import MillionSongDataset%0Afrom params import FEATURES, LYRICS, LYRIC_MAPPINGS, TRACKS%0Afrom utils.training_utils.params import TRAIN_FRACTION, TEST_FRACTION, VALIDATE_FRACTION, TOTAL_NUM_EXAMPLES%0Aimport numpy as np%0Afrom utils.training_utils.params import EXPT_DIRECTORY_PATH%0Aimport os%0A%0A%0Adef fetch_data(task_ids):%0A    %22%22%22%0A    Fetches the dataset from the Database and then divides it into training / testing / validation data%0A    :param task_ids: labels on which the network is trained%0A    :return: split data, and labels%0A    %22%22%22%0A    # Load the data set in memory.%0A    db = MillionSongDataset(FEATURES, LYRICS, LYRIC_MAPPINGS, TRACKS)%0A    # Generate train/validation/test splits.%0A    db.generate_split(TRAIN_FRACTION, VALIDATE_FRACTION, TEST_FRACTION, TOTAL_NUM_EXAMPLES)%0A%0A    # Training set%0A    print(%22Creating training set%22)%0A    x_train = np.array(%5Bbow for bow in db.get_bow(db.train)%5D, dtype=float)%0A    labels_train = np.array(%5Bt.vector() for t in db.get_features(db.train)%5D)%0A%0A    # Validation set%0A    print(%22Creating validation set%22)%0A    x_validate = np.array(%5Bbow for bow in db.get_bow(db.validate)%5D, dtype=float)%0A    labels_val = np.array(%5Bt.vector() for t in db.get_features(db.validate)%5D)%0A%0A    # Testing set%0A    print(%22Creating testing set%22)%0A    x_test = np.array(%5Bbow for bow in db.get_bow(db.test)%5D, dtype=float)%0A    labels_test = np.array(%5Bt.vector() for t in db.get_features(db.test)%5D)%0A%0A    # Build the label dictionary using tasks under consideration, discarding other labels.%0A    y_train = %7Btask_id: np.array(labels_train%5B:, int(task_id)%5D, dtype=float).reshape(-1, 1) for task_id in task_ids%7D%0A    y_val = %7Btask_id: np.array(labels_val%5B:, int(task_id)%5D, dtype=float).reshape(-1, 1) for task_id in task_ids%7D%0A    y_test = %7Btask_id: np.array(labels_test%5B:, int(task_id)%5D, dtype=float).reshape(-1, 1) for task_id in task_ids%7D%0A%0A    return x_train, x_validate, x_test, y_train, y_val, y_test%0A%0A%0Adef create_experiment(expt_name):%0A    %22%22%22%0A    Creates a directory for this experiment where all the logs and outputs are saved. The directory is named%0A    after the experiment-name suffixed with a 4-digit random number.%0A%0A    :param expt_name: Experiment name.%0A    :return: None%0A    %22%22%22%0A    os.chdir(EXPT_DIRECTORY_PATH)  # Change working directory to the Experiments folder%0A    expt_dir = expt_name + %22-%22 + str(np.random.randint(1000, 9999))%0A    try:%0A        os.makedirs(expt_dir)%0A    except OSError:%0A        if not os.path.isdir(expt_dir):%0A            raise%0A    finally:%0A        os.chdir(%22./%22 + expt_dir)  # Change working directory to the newly created folder%0A        print(%22Experiment Directory: %22 + expt_dir)%0A

Refactor utils package