r"""
Adding the Meaningless sentences to the hypothesis
==========================================================
"""
from ..transformation import Transformation
__all__ = ['AddSent']
[docs]class AddSent(Transformation):
r"""
Adding the Meaningless sentences to the hypothesis and remain both premise
and label.
Users can use their own meaningless sentences by change the text in
transform method
exmaple:
{
hypothesis: I hate this book.
premise: This book is my favorite. today is Monday.
y: contradiction
}
"""
def __init__(self):
super().__init__()
def __repr__(self):
return 'AddSent'
# TODO, add irrelevant sentence resource
def _transform(self, sample, text, n=1, **kwargs):
r"""
Transform text string, this kind of transformation can only produce one
sample.
:param ~NLISample sample: input data, a NLISample contains 'hypothesis'
field, 'premise' field and 'y' field
:param int n: number of generated samples, this transformation can only
generate one sample
:return list trans_samples: transformed sample list that only contain
one sample
"""
label_tag = sample.get_value('y')
original_text1 = sample.get_text('hypothesis') + text
original_text2 = sample.get_text('premise')
sample = sample.replace_fields(['hypothesis', 'premise', 'y'],
[original_text1, original_text2,
label_tag])
return [sample]