matchzoo.preprocessors.units.matching_histogram

Module Contents

class matchzoo.preprocessors.units.matching_histogram.MatchingHistogram(bin_size:int=30, embedding_matrix=None, normalize=True, mode:str='LCH')

Bases: matchzoo.preprocessors.units.unit.Unit

MatchingHistogramUnit Class.

Parameters:
  • bin_size – The number of bins of the matching histogram.
  • embedding_matrix – The word embedding matrix applied to calculate the matching histogram.
  • normalize – Boolean, normalize the embedding or not.
  • mode – The type of the historgram, it should be one of ‘CH’, ‘NG’, or ‘LCH’.

Examples

>>> embedding_matrix = np.array([[1.0, -1.0], [1.0, 2.0], [1.0, 3.0]])
>>> text_left = [0, 1]
>>> text_right = [1, 2]
>>> histogram = MatchingHistogram(3, embedding_matrix, True, 'CH')
>>> histogram.transform([text_left, text_right])
[[3.0, 1.0, 1.0], [1.0, 2.0, 2.0]]
_normalize_embedding(self)

Normalize the embedding matrix.

transform(self, input_:list)

Transform the input text.