:mod:`capreolus.reranker.TK` ============================ .. py:module:: capreolus.reranker.TK Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: capreolus.reranker.TK.PositionalEncoding capreolus.reranker.TK.TK_class capreolus.reranker.TK.TK .. data:: logger .. py:class:: PositionalEncoding(d_model, dropout=0.1, max_len=5000) Bases: :class:`torch.nn.Module` .. method:: forward(self, x) .. py:class:: TK_class(extractor, config) Bases: :class:`torch.nn.Module` Adapted from https://github.com/sebastian-hofstaetter/transformer-kernel-ranking/blob/master/matchmaker/models/tk.py TK is a neural IR model - a fusion between transformer contextualization & kernel-based scoring -> uses 1 transformer block to contextualize embeddings -> soft-histogram kernels to score interactions .. method:: get_mu_matrix(self, extractor) Returns a matrix of mu values that can be directly subtracted from the cosine matrix. This is the matrix mu in equation 5 in the paper (https://arxiv.org/pdf/2002.01854.pdf) .. method:: get_mask(self, embedding) Gets a mask of shape (seq_len, seq_len). This is an additive mask, hence masked elements should be -inf .. method:: get_embedding(self, toks) Overrides KNRM_Class's get_embedding to return contextualized word embeddings .. method:: forward(self, doctoks, querytoks, query_idf) .. py:class:: TK Bases: :class:`capreolus.reranker.Reranker` .. attribute:: module_name :annotation: = TK .. attribute:: description :annotation: = Sebastian Hofstätter, Markus Zlabinger, and Allan Hanbury. 2019. TU Wien @ TREC Deep Learning '19 -- Simple Contextualization for Re-ranking. In TREC '19. .. attribute:: config_spec .. method:: build_model(self) .. method:: score(self, d) .. method:: test(self, d)