| | import spacy |
| | import numpy as np |
| | nlp = spacy.load("en_core_web_md") |
| |
|
| | def sim_score(ref,gen): |
| | a = nlp(ref).similarity(nlp(gen)) |
| | return a |
| |
|
| | def calculate_ratio(table): |
| | ratios = [] |
| | maximum = [] |
| | for column in table.T: |
| | max_value = np.max(column) |
| | average_value = np.mean(column) |
| | if max_value + average_value != 0: |
| | ratio = max_value / (max_value + average_value) |
| | else: |
| | ratio=0 |
| | ratios.append(ratio) |
| | |
| | return ratios |
| | |
| | def similarity_score(ref_term, gen_term): |
| | |
| | similarity_scores = [[sim_score(ref, gen) for gen in gen_term] for ref in ref_term] |
| | ratio = calculate_ratio(np.array(similarity_scores)) |
| |
|
| | |
| | |
| | return ratio |