def _get2(context, xi, span): if len(xi) <= span[0][0]: return "" if len(xi[span[0][0]]) <= span[1][1]: return "" print(span) return get_phrase(context, xi, span)
def ensemble3(context, wordss, y1_list, y2_list): d = defaultdict(float) for y1, y2 in zip(y1_list, y2_list): span, score = get_best_span(y1, y2) phrase = get_phrase(context, wordss, span) d[phrase] += score return max(d.items(), key=lambda pair: pair[1])[0]
def ensemble4(context, wordss, y1_list, y2_list): d = defaultdict(lambda: 0.0) for y1, y2 in zip(y1_list, y2_list): for span, score in get_span_score_pairs(y1, y2): d[span] += score span = max(d.items(), key=lambda pair: pair[1])[0] phrase = get_phrase(context, wordss, span) return phrase
def _get2(context, xi, span): if len(xi) <= span[0][0]: return "" if len(xi[span[0][0]]) <= span[1][1]: return "" if self.config.na: start, stop = span if start == (0, 0) and stop == (0, 1): return "" return get_phrase(context, xi, span)
def ensemble2(context, wordss, y1_list, y2_list): start_dict = defaultdict(float) stop_dict = defaultdict(float) for y1, y2 in zip(y1_list, y2_list): span, score = get_best_span(y1, y2) start_dict[span[0]] += y1[span[0][0]][span[0][1]] stop_dict[span[1]] += y2[span[1][0]][span[1][1]] start = max(start_dict.items(), key=lambda pair: pair[1])[0] stop = max(stop_dict.items(), key=lambda pair: pair[1])[0] best_span = (start, stop) return get_phrase(context, wordss, best_span)
def ensemble3_getAllSpans_Snigdha(context, wordss, y1_list, y2_list, max_span_len): d = defaultdict(float) d_span = {} #Snigdha for y1, y2 in zip(y1_list, y2_list): d_span_scores = get_all_spans_Snigdha(y1, y2, context, wordss, max_span_len) for span in d_span_scores: phrase = get_phrase(context, wordss, span) d[phrase] += d_span_scores[span] d_span[phrase] = span return (d, d_span)
def ensemble1(context, wordss, y1_list, y2_list): """ :param context: Original context :param wordss: tokenized words (nested 2D list) :param y1_list: list of start index probs (each element corresponds to probs form single model) :param y2_list: list of stop index probs :return: """ sum_y1 = combine_y_list(y1_list) sum_y2 = combine_y_list(y2_list) span, score = get_best_span(sum_y1, sum_y2) return get_phrase(context, wordss, span)
def ensemble3_Snigdha(context, wordss, y1_list, y2_list): d = defaultdict(float) d_span = {} #Snigdha outputted = list() #Snigdha for i in range( 0, no_of_top_candidates ): # Snigdha: Change here to determine how many candidates you want it to output for y1, y2 in zip(y1_list, y2_list): span, score = get_best_span_Snigdha(y1, y2, outputted) phrase = get_phrase(context, wordss, span) d[phrase] += score d_span[phrase] = span outputted.append(span) #Snigdha return (d, d_span)
def _get2(context, xi, span): if len(xi) <= span[0][0]: return "" if len(xi[span[0][0]]) <= span[1][1]: return "" return get_phrase(context, xi, span)