Source code for pyterrier_splade._utils
import pandas as pd
import pyterrier as pt
[docs]
class Toks2Doc(pt.Transformer):
"""Converts a toks field into a text field, by scaling the weights by ``mult`` and repeating them."""
def __init__(self, mult: float = 100.):
"""Initializes the transformer.
Args:
mult: the multiplier to apply to the term frequencies
"""
self.mult = mult
def _dict_tf2text(self, tfdict):
rtr = ""
for t in tfdict:
for i in range(int(self.mult * tfdict[t])):
rtr += t + " "
return rtr