Ejemplo n.º 1
0
def _combine_probs(phrasebook, attach, relate):
    """for all EDU pairs, retrieve probability of the best relation
    on that pair, given the probability of an attachment

    :type attach: DataAndModel
    :type relate: DataAndModel
    """
    # !! instances set must correspond to same edu pair in the same order !!
    distrib = []

    edu_pair = mk_edu_pairs(phrasebook, attach.data.domain)
    attach_instances = sorted(attach.data, key=lambda x: x.get_metas())
    relate_instances = sorted(relate.data, key=lambda x: x.get_metas())

    inst_pairs = zip(attach_instances, relate_instances)
    for i, (att, rel) in enumerate(inst_pairs):
        if not _instance_check(phrasebook, att, rel):
            print(
                "mismatch of attachment/relation instance, "
                "instance number",
                i,
                _instance_help(phrasebook, att),
                _instance_help(phrasebook, rel),
                file=sys.stderr)
        prob, best = _combine_single_prob(attach, relate, att, rel)
        edu1, edu2 = edu_pair(att)
        distrib.append((edu1, edu2, prob, best))
    return distrib
Ejemplo n.º 2
0
def _combine_probs(phrasebook, attach, relate):
    """for all EDU pairs, retrieve probability of the best relation
    on that pair, given the probability of an attachment

    :type attach: DataAndModel
    :type relate: DataAndModel
    """
    # !! instances set must correspond to same edu pair in the same order !!
    distrib = []

    edu_pair = mk_edu_pairs(phrasebook, attach.data.domain)
    attach_instances = sorted(attach.data, key=lambda x: x.get_metas())
    relate_instances = sorted(relate.data, key=lambda x: x.get_metas())

    inst_pairs = zip(attach_instances, relate_instances)
    for i, (att, rel) in enumerate(inst_pairs):
        if not _instance_check(phrasebook, att, rel):
            print("mismatch of attachment/relation instance, "
                  "instance number", i,
                  _instance_help(att, phrasebook),
                  _instance_help(rel, phrasebook),
                  file=sys.stderr)
        prob, best = _combine_single_prob(attach, relate, att, rel)
        edu1, edu2 = edu_pair(att)
        distrib.append((edu1, edu2, prob, best))
    return distrib
Ejemplo n.º 3
0
def _get_attach_prob_orange(phrasebook, attach):
    """
    Attachment probabilities (only) for each EDU pair in the data
    """
    # orange-based models
    edu_pair = mk_edu_pairs(phrasebook, attach.data.domain)
    prob_distrib = []
    for inst in attach.data:
        edu1, edu2 = edu_pair(inst)
        prob = _get_inst_attach_orange(attach.model, inst)
        prob_distrib.append((edu1, edu2, prob, "unlabelled"))
    return prob_distrib
Ejemplo n.º 4
0
def _get_attach_prob_orange(config, attach):
    """
    Attachment probabilities (only) for each EDU pair in the data
    """
    # orange-based models
    edu_pair = mk_edu_pairs(config.phrasebook, attach.data.domain)
    prob_distrib = []
    for inst in attach.data:
        edu1, edu2 = edu_pair(inst)
        probs = attach.model(inst, Classifier.GetProbabilities)[1]
        prob_distrib.append((edu1, edu2, probs, "unlabelled"))
    return prob_distrib
Ejemplo n.º 5
0
def _get_attach_prob_orange(config, attach):
    """
    Attachment probabilities (only) for each EDU pair in the data
    """
    # orange-based models
    edu_pair = mk_edu_pairs(config.phrasebook, attach.data.domain)
    prob_distrib = []
    for inst in attach.data:
        edu1, edu2 = edu_pair(inst)
        probs = attach.model(inst, Classifier.GetProbabilities)[1]
        prob_distrib.append((edu1, edu2, probs, "unlabelled"))
    return prob_distrib
Ejemplo n.º 6
0
def _get_attach_prob_orange(phrasebook, attach):
    """
    Attachment probabilities (only) for each EDU pair in the data
    """
    # orange-based models
    edu_pair = mk_edu_pairs(phrasebook, attach.data.domain)
    prob_distrib = []
    for inst in attach.data:
        edu1, edu2 = edu_pair(inst)
        prob = _get_inst_attach_orange(attach.model, inst)
        prob_distrib.append((edu1, edu2, prob, "unlabelled"))
    return prob_distrib
Ejemplo n.º 7
0
 def get_edu_pair(self, orange_inst):
     return mk_edu_pairs(self.__meta_features, self.__domain)(orange_inst)
Ejemplo n.º 8
0
 def get_edu_pair(self, orange_inst):
     return mk_edu_pairs(self.__phrasebook, self.__domain)(orange_inst)
Ejemplo n.º 9
0
 def get_edu_pair(self, orange_inst):
     return mk_edu_pairs(self.__phrasebook, self.__domain)(orange_inst)
Ejemplo n.º 10
0
 def get_edu_pair(self, orange_inst):
     return mk_edu_pairs(self.__meta_features, self.__domain)(orange_inst)