Exemplo n.º 1
0
    def __run():

        # Setup default evaluator.
        evaluator = ThreeClassEvaluator(DataType.Test)

        experiment_data = RuSentRelTrainingData(
            labels_scaler=labels_scaler,
            stemmer=stemmer,
            evaluator=evaluator,
            opinion_formatter=RuSentRelOpinionCollectionFormatter(),
            callback=CallbackEvalF1NPU(DataType.Test))

        extra_name_suffix = Common.create_exp_name_suffix(
            use_balancing=balanced_input,
            terms_per_context=terms_per_context,
            dist_in_terms_between_att_ends=dist_in_terms_between_attitude_ends)

        # Composing experiment.
        experiment = create_experiment(exp_type=exp_type,
                                       experiment_data=experiment_data,
                                       folding_type=folding_type,
                                       rusentrel_version=rusentrel_version,
                                       experiment_io_type=CustomNetworkExperimentIO,
                                       ruattitudes_version=ra_version,
                                       load_ruattitude_docs=False,
                                       extra_name_suffix=extra_name_suffix)

        full_model_name = Common.create_full_model_name(folding_type=folding_type,
                                                        model_name=model_name,
                                                        input_type=model_input_type)

        model_io = NeuralNetworkModelIO(
            full_model_name=full_model_name,
            target_dir=experiment.ExperimentIO.get_target_dir(),
            # From this depends on whether we have a specific dir or not.
            source_dir=None if model_name_tag is None else u"",
            model_name_tag=ModelNameTagArg.NO_TAG if model_name_tag is None else model_name_tag)

        # Setup model io.
        experiment_data.set_model_io(model_io)

        # Check dir existence in advance.
        model_dir = model_io.get_model_dir()
        if not exists(model_dir):
            print u"Skipping [path not exists]: {}".format(model_dir)
            return

        engine = ExperimentF1pnuEvaluator(experiment=experiment,
                                          data_type=DataType.Test,
                                          max_epochs_count=max_epochs_count,
                                          forced=force_eval)

        # Starting evaluation process.
        engine.run()
    callback.set_eval_on_epochs(test_epochs_range)

    # Setup evaluation mode.
    eval_mode = EvaluationModes.Extraction if labels_count == 3 else EvaluationModes.Classification

    # Creating experiment
    evaluator = TwoClassEvaluator(eval_mode)
    experiment_data = RuSentRelTrainingData(
        labels_scaler=Common.create_labels_scaler(labels_count),
        stemmer=stemmer,
        opinion_formatter=Common.create_opinion_collection_formatter(),
        evaluator=evaluator,
        callback=callback)

    extra_name_suffix = Common.create_exp_name_suffix(
        use_balancing=balanced_input,
        terms_per_context=terms_per_context,
        dist_in_terms_between_att_ends=dist_in_terms_between_attitude_ends)

    experiment = create_experiment(
        exp_type=exp_type,
        experiment_data=experiment_data,
        folding_type=folding_type,
        rusentrel_version=rusentrel_version,
        ruattitudes_version=ra_version,
        experiment_io_type=CustomNetworkExperimentIO,
        extra_name_suffix=extra_name_suffix,
        load_ruattitude_docs=False)

    full_model_name = Common.create_full_model_name(
        folding_type=folding_type,
        model_name=model_name,