src/predict_many_samples.py [673:761]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    model_dir = "%s/../models/%s/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str,
        args.step if args.step == "best" else "checkpoint-{}".format(args.step)
    )
    config_dir = "%s/../logs/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str
    )
    predict_dir = "%s/../predicts/%s/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str,
        args.step if args.step == "best" else "checkpoint-{}".format(args.step)
    )

    # Step1: loading the model configuration
    config = load_args(config_dir)
    for key, value in config.items():
        try:
            if value.startswith("../"):
                value = os.path.join(SCRIPT_DIR, value)
        except AttributeError:
            continue
        print(f'My item {value} is labelled {key}')
        config[key] = value
    print("-" * 25 + "config:" + "-" * 25)
    print(config)
    print("-" * 60)
    if config:
        args.dataset_name = config["dataset_name"]
        args.dataset_type = config["dataset_type"]
        args.task_type = config["task_type"]
        args.model_type = config["model_type"]
        args.has_seq_encoder = config["has_seq_encoder"]
        args.has_struct_encoder = config["has_struct_encoder"]
        args.has_embedding_encoder = config["has_embedding_encoder"]
        args.subword = config["subword"]
        args.codes_file = config["codes_file"]
        args.input_mode = config["input_mode"]
        args.label_filepath = config["label_filepath"]
        if not os.path.exists(args.label_filepath):
            args.label_filepath = os.path.join(config_dir, "label.txt")
        args.output_dir = config["output_dir"]
        args.config_path = config["config_path"]

        args.do_lower_case = config["do_lower_case"]
        args.sigmoid = config["sigmoid"]
        args.loss_type = config["loss_type"]
        args.output_mode = config["output_mode"]

        args.seq_vocab_path = config["seq_vocab_path"]
        args.seq_pooling_type = config["seq_pooling_type"]
        args.seq_max_length = config["seq_max_length"]
        args.struct_vocab_path = config["struct_vocab_path"]
        args.struct_max_length = config["struct_max_length"]
        args.struct_pooling_type = config["struct_pooling_type"]
        args.trunc_type = config["trunc_type"]
        args.no_position_embeddings = config["no_position_embeddings"]
        args.no_token_type_embeddings = config["no_token_type_embeddings"]
        args.cmap_type = config["cmap_type"]
        args.cmap_type = float(config["cmap_thresh"])
        args.embedding_input_size = config["embedding_input_size"]
        args.embedding_pooling_type = config["embedding_pooling_type"]
        args.embedding_max_length = config["embedding_max_length"]
        args.embedding_type = config["embedding_type"]
        if args.task_type in ["multi-label", "multi_label"]:
            args.sigmoid = True
        elif args.task_type in ["binary-class", "binary_class"]:
            args.sigmoid = True

    if args.gpu_id <= -1:
        args.device = torch.device("cpu")
    else:
        args.device = torch.device("cuda:%d" % args.gpu_id) if torch.cuda.is_available() else torch.device("cpu")

    print("-" * 25 + "args:" + "-" * 25)
    print(args.__dict__.items())
    print("-" * 60)
    '''
    print("-" * 25 + "model_dir list:" + "-" * 25)
    print(os.listdir(model_dir))
    print("-" * 60)
    '''

    if args.device.type == 'cpu':
        print("Running Device is CPU!")
    else:
        print("Running Device is GPU(%d)!" % args.gpu_id)
    print("-" * 60)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



src/predict_one_sample.py [657:745]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    model_dir = "%s/../models/%s/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str,
        args.step if args.step == "best" else "checkpoint-{}".format(args.step)
    )
    config_dir = "%s/../logs/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str
    )
    predict_dir = "%s/../predicts/%s/%s/%s/%s/%s/%s" % (
        SCRIPT_DIR, args.dataset_name, args.dataset_type, args.task_type,
        args.model_type, args.time_str,
        args.step if args.step == "best" else "checkpoint-{}".format(args.step)
    )

    # Step1: loading the model configuration
    config = load_args(config_dir)
    for key, value in config.items():
        try:
            if value.startswith("../"):
                value = os.path.join(SCRIPT_DIR, value)
        except AttributeError:
            continue
        print(f'My item {value} is labelled {key}')
        config[key] = value
    print("-" * 25 + "config:" + "-" * 25)
    print(config)
    print("-" * 60)
    if config:
        args.dataset_name = config["dataset_name"]
        args.dataset_type = config["dataset_type"]
        args.task_type = config["task_type"]
        args.model_type = config["model_type"]
        args.has_seq_encoder = config["has_seq_encoder"]
        args.has_struct_encoder = config["has_struct_encoder"]
        args.has_embedding_encoder = config["has_embedding_encoder"]
        args.subword = config["subword"]
        args.codes_file = config["codes_file"]
        args.input_mode = config["input_mode"]
        args.label_filepath = config["label_filepath"]
        if not os.path.exists(args.label_filepath):
            args.label_filepath = os.path.join(config_dir, "label.txt")
        args.output_dir = config["output_dir"]
        args.config_path = config["config_path"]

        args.do_lower_case = config["do_lower_case"]
        args.sigmoid = config["sigmoid"]
        args.loss_type = config["loss_type"]
        args.output_mode = config["output_mode"]

        args.seq_vocab_path = config["seq_vocab_path"]
        args.seq_pooling_type = config["seq_pooling_type"]
        args.seq_max_length = config["seq_max_length"]
        args.struct_vocab_path = config["struct_vocab_path"]
        args.struct_max_length = config["struct_max_length"]
        args.struct_pooling_type = config["struct_pooling_type"]
        args.trunc_type = config["trunc_type"]
        args.no_position_embeddings = config["no_position_embeddings"]
        args.no_token_type_embeddings = config["no_token_type_embeddings"]
        args.cmap_type = config["cmap_type"]
        args.cmap_type = float(config["cmap_thresh"])
        args.embedding_input_size = config["embedding_input_size"]
        args.embedding_pooling_type = config["embedding_pooling_type"]
        args.embedding_max_length = config["embedding_max_length"]
        args.embedding_type = config["embedding_type"]
        if args.task_type in ["multi-label", "multi_label"]:
            args.sigmoid = True
        elif args.task_type in ["binary-class", "binary_class"]:
            args.sigmoid = True

    if args.gpu_id <= -1:
        args.device = torch.device("cpu")
    else:
        args.device = torch.device("cuda:%d" % args.gpu_id) if torch.cuda.is_available() else torch.device("cpu")

    print("-" * 25 + "args:" + "-" * 25)
    print(args.__dict__.items())
    print("-" * 60)
    '''
    print("-" * 25 + "model_dir list:" + "-" * 25)
    print(os.listdir(model_dir))
    print("-" * 60)
    '''

    if args.device.type == 'cpu':
        print("Running Device is CPU!")
    else:
        print("Running Device is GPU(%d)!" % args.gpu_id)
    print("-" * 60)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



