capreolus.reranker.TK

Module Contents

Classes

PositionalEncoding(d_model, dropout=0.1, max_len=5000)
TK_class(extractor, config) Adapted from https://github.com/sebastian-hofstaetter/transformer-kernel-ranking/blob/master/matchmaker/models/tk.py
TK(config=None, provide=None, share_dependency_objects=False, build=True) Base class for profane modules.
capreolus.reranker.TK.logger[source]
class capreolus.reranker.TK.PositionalEncoding(d_model, dropout=0.1, max_len=5000)[source]

Bases: torch.nn.Module

forward(self, x)[source]
class capreolus.reranker.TK.TK_class(extractor, config)[source]

Bases: 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

get_mu_matrix(self, extractor)[source]

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)

get_mask(self, embedding)[source]

Gets a mask of shape (seq_len, seq_len). This is an additive mask, hence masked elements should be -inf

get_embedding(self, toks)[source]

Overrides KNRM_Class’s get_embedding to return contextualized word embeddings

forward(self, doctoks, querytoks, query_idf)[source]
class capreolus.reranker.TK.TK(config=None, provide=None, share_dependency_objects=False, build=True)[source]

Bases: capreolus.reranker.Reranker

Base class for profane modules. Module construction proceeds as follows: 1) Any config options not present in config are filled in with their default values. Config options and their defaults are specified in the config_spec class attribute. 2) Any dependencies declared in the dependencies class attribute are recursively instantiated. If the dependency object is present in provide, this object will be used instead of instantiating a new object for the dependency. 3) The module object’s config variable is updated to reflect the configs of its dependencies and then frozen.

After construction is complete, the module’s dependencies are available as instance variables: self.`dependency key`.

Parameters:
  • config – dictionary containing a config to apply to this module and its dependencies
  • provide – dictionary mapping dependency keys to module objects
  • share_dependency_objects – if true, dependencies will be cached in the registry based on their configs and reused. See the share_objects argument of ModuleBase.create.
module_name = TK[source]
description = Sebastian Hofstätter, Markus Zlabinger, and Allan Hanbury. 2019. TU Wien @ TREC Deep Learning '19 -- Simple Contextualization for Re-ranking. In TREC '19.[source]
config_spec[source]
build_model(self)[source]
score(self, d)[source]
test(self, d)[source]