Esempio n. 1
0
def compute_paragraph_score(sample, mode=None):
    """
    For each paragraph, compute the f1 score compared with the question
    Args:
        sample: a sample in the dataset.
    Returns:
        None
    Raises:
        None
    """
    if mode == "train" and "segmented_answers" in sample:
        sentence = sample["segmented_answers"]
        sentence += sample["segmented_question"]
    else:
        sentence = sample["segmented_question"]
    for doc in sample['documents']:
        doc['segmented_paragraphs_scores'] = []
        for p_idx, (para_tokens, p_tokens) in enumerate(
                zip(doc['segmented_paragraphs'], doc['paragraphs'])):
            if len(sentence) > 0:

                if mode == "train":
                    related_score = metric_max_over_ground_truths(
                        f1_score, para_tokens, sentence)

                else:
                    related_score = metric_max_over_ground_truths(
                        f1_score, para_tokens, [sentence])
            else:
                related_score = 0.0
            doc['segmented_paragraphs_scores'].append(related_score)
def compute_paragraph_score(sample):
    """
    For each paragraph, compute the f1 score compared with the question
    Args:
        sample: a sample in the dataset.
    Returns:
        None
    Raises:
        None
    """
    scores = []
    question = sample["segmented_question"]
    sample['segmented_paragraphs'] = []
    sample['segmented_paragraphs_scores'] = []
    for d_idx, doc in enumerate(sample['documents']):
        for p_idx, para_tokens in enumerate(doc['segmented_paragraphs']):
            if len(question) > 0:
                related_score = metric_max_over_ground_truths(
                    f1_score, para_tokens, [question])
            else:
                related_score = 0.0
            sample['segmented_paragraphs'].append(para_tokens)
            sample['segmented_paragraphs_scores'].append(related_score)
            scores.append((related_score, d_idx, p_idx))

    with open('scores.txt', 'a') as f:
        f.write(str(scores) + '\n')
def compute_paragraph_score(sample):
    """
    For each paragraph, compute the f1 score compared with the question
    Args:
        sample: a sample in the dataset.
    Returns:
        None
    Raises:
        None
    """
    question = sample["segmented_question"]
    for doc in sample['documents']:
        doc['segmented_paragraphs_scores'] = []
        for p_idx, para_tokens in enumerate(doc['segmented_paragraphs']):
            if len(question) > 0:
                related_score = metric_max_over_ground_truths(
                    f1_score, para_tokens, [question])
            else:
                related_score = 0.0
            doc['segmented_paragraphs_scores'].append(related_score)