Evaluates the answer leakage of the hints of the given instances using the lexical comparison [38].
Parameters:
instances (List[Instance]) – List of instances to evaluate.
**kwargs – Additional keyword arguments.
Returns:
List of answer leakage scores for each instance.
Return type:
List[List[float]]
Notes
This function stores the scores as Metric objects within the metrics attribute of the Hint of the instances, with names based on the model, such as “answer-leakage-lexical-include_stop_words-sm”.
Examples
>>> fromhinteval.coresimportInstance,Question,Hint,Answer>>> fromhinteval.evaluation.answer_leakageimportLexical>>>>>> lexical=Lexical(method='include_stop_words')>>> instance_1=Instance(... question=Question('What is the capital of Austria?'),... answers=[Answer('Vienna')],... hints=[Hint('This city, once home to Mozart and Beethoven.'),... Hint('This city is called as Vienna.')])>>> instance_2=Instance(... question=Question('Who was the president of USA in 2009?'),... answers=[Answer('Barack Obama')],... hints=[Hint('His lastname is Obama.'),... Hint('He was named the 2009 Nobel Peace Prize laureate.')])>>> instances=[instance_1,instance_2]>>> results=lexical.evaluate(instances)>>> print(results)# [[0, 1], [1, 0]]>>> metrics=[f'{metric_key}: {metric_value.value}'for... instanceininstances... forhintininstance.hintsformetric_key,metric_valuein... hint.metrics.items()]>>> print(metrics)# ['answer-leakage-lexical-include_stop_words-sm: 0', 'answer-leakage-lexical-include_stop_words-sm: 1',# 'answer-leakage-lexical-include_stop_words-sm: 1', 'answer-leakage-lexical-include_stop_words-sm: 0']
Evaluates the answer leakage of the hints of the given instances using the contextual word embeddings.
Parameters:
instances (List[Instance]) – List of instances to evaluate.
**kwargs – Additional keyword arguments.
Returns:
List of answer leakage scores for each instance.
Return type:
List[List[float]]
Notes
This function stores the scores as Metric objects within the metrics attribute of the Hint of the instances, with names based on the model, such as “answer-leakage-contextual-include_stop_words-sm”.
Examples
>>> fromhinteval.coresimportInstance,Question,Hint,Answer>>> fromhinteval.evaluation.answer_leakageimportContextualEmbeddings>>>>>> contextual=ContextualEmbeddings(sbert_model='paraphrase-multilingual-mpnet-base-v2')>>> instance_1=Instance(... question=Question('What is the capital of Austria?'),... answers=[Answer('Vienna')],... hints=[Hint('This city, once home to Mozart and Beethoven.'),... Hint('This city is called as Vienna.')])>>> instance_2=Instance(... question=Question('Who was the president of USA in 2009?'),... answers=[Answer('Barack Obama')],... hints=[Hint('His lastname is Obama.'),... Hint('He was named the 2009 Nobel Peace Prize laureate.')])>>> instances=[instance_1,instance_2]>>> results=contextual.evaluate(instances)>>> print(results)# [[0.495, 1.0], [0.967, 0.332]]>>> metrics=[f'{metric_key}: {metric_value.value}'for... instanceininstances... forhintininstance.hintsformetric_key,metric_valuein... hint.metrics.items()]>>> print(metrics)# ['answer-leakage-lexical-include_stop_words-sm: 0.495', 'answer-leakage-lexical-include_stop_words-sm: 1.0',# 'answer-leakage-lexical-include_stop_words-sm: 0.967', 'answer-leakage-lexical-include_stop_words-sm: 0.332']