code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def get_standard_normalized_histogram_GN(batch_std_labels, gain_base=2.0):
"""
Convert to a normalized histogram based on gain values, i.e., each entry equals to gain_value/sum_gain_value
:param batch_std_labels:
:return:
"""
batch_std_gains = torch.pow(gain_base, batch_std_labels) - 1.0
bat... |
Convert to a normalized histogram based on gain values, i.e., each entry equals to gain_value/sum_gain_value
:param batch_std_labels:
:return:
| get_standard_normalized_histogram_GN | python | wildltr/ptranking | ptranking/ltr_adhoc/listwise/wassrank/wasserstein_cost_mat.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/listwise/wassrank/wasserstein_cost_mat.py | MIT |
def get_normalized_histograms(batch_std_labels=None, batch_preds=None,
wass_dict_std_dists=None, qid=None, wass_para_dict=None, TL_AF=None):
""" Convert both standard labels and predictions w.r.t. a query to normalized histograms """
smooth_type, norm_type = wass_para_dict['smooth_... | Convert both standard labels and predictions w.r.t. a query to normalized histograms | get_normalized_histograms | python | wildltr/ptranking | ptranking/ltr_adhoc/listwise/wassrank/wasserstein_cost_mat.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/listwise/wassrank/wasserstein_cost_mat.py | MIT |
def default_para_dict(self):
"""
Default parameter setting for WassRank. EntropicOT | SinkhornOT
:return:
"""
self.wass_para_dict = dict(model_id=self.model_id, mode='SinkhornOT', sh_itr=20, lam=0.1, smooth_type='ST',
norm_type='BothST', cost_ty... |
Default parameter setting for WassRank. EntropicOT | SinkhornOT
:return:
| default_para_dict | python | wildltr/ptranking | ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | MIT |
def grid_search(self):
"""
Iterator of parameter settings for WassRank
"""
if self.use_json:
wass_choice_mode = self.json_dict['mode']
wass_choice_itr = self.json_dict['itr']
wass_choice_lam = self.json_dict['lam']
wass_cost_type = self.js... |
Iterator of parameter settings for WassRank
| grid_search | python | wildltr/ptranking | ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/listwise/wassrank/wassRank.py | MIT |
def custom_loss_function(self, batch_preds, batch_std_labels, **kwargs):
'''
@param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents associated with the same query
@param batch_std_labels: [batch, ranking_size] each row represents the standard releva... |
@param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents associated with the same query
@param batch_std_labels: [batch, ranking_size] each row represents the standard relevance grades for documents associated with the same query
@param kwargs:
... | custom_loss_function | python | wildltr/ptranking | ptranking/ltr_adhoc/pairwise/ranknet.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/pairwise/ranknet.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adhoc/pairwise/ranknet.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/pairwise/ranknet.py | MIT |
def grid_search(self):
"""
Iterator of parameter settings for RankNet
"""
if self.use_json:
choice_sigma = self.json_dict['sigma']
else:
choice_sigma = [5.0, 1.0] if self.debug else [1.0] # 1.0, 10.0, 50.0, 100.0
for sigma in choice_sigma:
... |
Iterator of parameter settings for RankNet
| grid_search | python | wildltr/ptranking | ptranking/ltr_adhoc/pairwise/ranknet.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/pairwise/ranknet.py | MIT |
def rankMSE_loss_function(relevance_preds=None, std_labels=None):
'''
Ranking loss based on mean square error TODO adjust output scale w.r.t. output layer activation function
@param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents associated with the same query
@param b... |
Ranking loss based on mean square error TODO adjust output scale w.r.t. output layer activation function
@param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents associated with the same query
@param batch_std_labels: [batch, ranking_size] each row represents the standar... | rankMSE_loss_function | python | wildltr/ptranking | ptranking/ltr_adhoc/pointwise/rank_mse.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/pointwise/rank_mse.py | MIT |
def custom_loss_function(self, batch_preds, batch_std_labels, **kwargs):
'''
:param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents within a ltr_adhoc
:param batch_std_labels: [batch, ranking_size] each row represents the standard relevance grades for documents withi... |
:param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents within a ltr_adhoc
:param batch_std_labels: [batch, ranking_size] each row represents the standard relevance grades for documents within a ltr_adhoc
:return:
| custom_loss_function | python | wildltr/ptranking | ptranking/ltr_adhoc/pointwise/rank_mse.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/pointwise/rank_mse.py | MIT |
def batch_count(batch_std_labels=None, max_rele_grade=None, descending=False, gpu=False):
"""
Todo now an api is already provided by pytorch
:param batch_std_labels:
:param max_rele_grade:
:param descending:
:param gpu:
:return:
"""
rele_grades = torch.arange(max_rele_grade+1).type(t... |
Todo now an api is already provided by pytorch
:param batch_std_labels:
:param max_rele_grade:
:param descending:
:param gpu:
:return:
| batch_count | python | wildltr/ptranking | ptranking/ltr_adhoc/util/bin_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/bin_utils.py | MIT |
def torch_batch_triu(batch_mats=None, k=0, pair_type='All', batch_std_labels=None, gpu=False, device=None):
'''
Get unique document pairs being consistent with the specified pair_type. This function is used to avoid duplicate computation.
All: pairs including both pairs of documents across different... |
Get unique document pairs being consistent with the specified pair_type. This function is used to avoid duplicate computation.
All: pairs including both pairs of documents across different relevance levels and
pairs of documents having the same relevance level.
NoTies: the pairs c... | torch_batch_triu | python | wildltr/ptranking | ptranking/ltr_adhoc/util/gather_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/gather_utils.py | MIT |
def torch_triu_indice(k=0, pair_type='All', batch_label=None, gpu=False, device=None):
'''
Get unique document pairs being consistent with the specified pair_type. This function is used to avoid duplicate computation.
All: pairs including both pairs of documents across different relevance levels and... |
Get unique document pairs being consistent with the specified pair_type. This function is used to avoid duplicate computation.
All: pairs including both pairs of documents across different relevance levels and
pairs of documents having the same relevance level.
NoTies: the pairs... | torch_triu_indice | python | wildltr/ptranking | ptranking/ltr_adhoc/util/gather_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/gather_utils.py | MIT |
def get_pairwise_comp_probs(batch_preds, batch_std_labels, sigma=None):
'''
Get the predicted and standard probabilities p_ij which denotes d_i beats d_j
@param batch_preds:
@param batch_std_labels:
@param sigma:
@return:
'''
# computing pairwise differences w.r.t. predictions, i.e., s_i... |
Get the predicted and standard probabilities p_ij which denotes d_i beats d_j
@param batch_preds:
@param batch_std_labels:
@param sigma:
@return:
| get_pairwise_comp_probs | python | wildltr/ptranking | ptranking/ltr_adhoc/util/lambda_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/lambda_utils.py | MIT |
def get_one_hot_reprs(batch_stds, gpu=False):
""" Get one-hot representation of batch ground-truth labels """
batch_size = batch_stds.size(0)
hist_size = batch_stds.size(1)
int_batch_stds = batch_stds.type(torch.cuda.LongTensor) if gpu else batch_stds.type(torch.LongTensor)
hot_batch_stds = torch.c... | Get one-hot representation of batch ground-truth labels | get_one_hot_reprs | python | wildltr/ptranking | ptranking/ltr_adhoc/util/one_hot_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/one_hot_utils.py | MIT |
def arg_shuffle_ties(batch_rankings, descending=True, device=None):
'''Shuffle ties, and return the corresponding indice '''
batch_size, ranking_size = batch_rankings.size()
if batch_size > 1:
list_rperms = []
for _ in range(batch_size):
list_rperms.append(torch.randperm(ranking_... | Shuffle ties, and return the corresponding indice | arg_shuffle_ties | python | wildltr/ptranking | ptranking/ltr_adhoc/util/sampling_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/sampling_utils.py | MIT |
def sample_ranking_PL(batch_preds, only_indices=True, temperature=1.0):
'''
Sample one ranking per query based on Plackett-Luce model
@param batch_preds: [batch_size, ranking_size] each row denotes the relevance predictions for documents associated with the same query
@param only_indices: only return th... |
Sample one ranking per query based on Plackett-Luce model
@param batch_preds: [batch_size, ranking_size] each row denotes the relevance predictions for documents associated with the same query
@param only_indices: only return the indices or not
| sample_ranking_PL | python | wildltr/ptranking | ptranking/ltr_adhoc/util/sampling_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/sampling_utils.py | MIT |
def sample_ranking_PL_gumbel_softmax(batch_preds, only_indices=True, temperature=1.0, device=None):
'''
Sample a ranking based stochastic Plackett-Luce model, where gumble noise is added
@param batch_preds: [batch_size, ranking_size] each row denotes the relevance predictions for documents associated with t... |
Sample a ranking based stochastic Plackett-Luce model, where gumble noise is added
@param batch_preds: [batch_size, ranking_size] each row denotes the relevance predictions for documents associated with the same query
@param only_indices: only return the indices or not
| sample_ranking_PL_gumbel_softmax | python | wildltr/ptranking | ptranking/ltr_adhoc/util/sampling_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adhoc/util/sampling_utils.py | MIT |
def default_pointsf_para_dict(self):
"""
A default setting of the hyper-parameters of the stump neural scoring function for adversarial ltr.
"""
self.sf_para_dict = dict()
self.sf_para_dict['sf_id'] = self.sf_id
self.sf_para_dict['opt'] = 'Adam' # Adam | RMS | Adagrad
self.sf_para_dict['lr'] = 0.001 # l... |
A default setting of the hyper-parameters of the stump neural scoring function for adversarial ltr.
| default_pointsf_para_dict | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def to_eval_setting_string(self, log=False):
"""
String identifier of eval-setting
:param log:
:return:
"""
eval_dict = self.eval_dict
s1, s2 = (':', '\n') if log else ('_', '_')
do_vali, epochs = eval_dict['do_validation'], eval_dict['epochs']
eval_string = s2.join([s1.join(['epochs', str(epochs)])... |
String identifier of eval-setting
:param log:
:return:
| to_eval_setting_string | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def default_setting(self):
"""
A default setting for evaluation when performing adversarial ltr
:param debug:
:param data_id:
:param dir_output:
:return:
"""
do_log = False if self.debug else True
do_validation, do_summary = True, False
log_step = 1
epochs = 10 if self.debug else 50
vali_k = 5
... |
A default setting for evaluation when performing adversarial ltr
:param debug:
:param data_id:
:param dir_output:
:return:
| default_setting | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def grid_search(self):
"""
Iterator of settings for evaluation when performing adversarial ltr
"""
if self.use_json:
dir_output = self.json_dict['dir_output']
epochs = 5 if self.debug else self.json_dict['epochs']
do_validation, vali_k = self.json_dict['do_validation'], self.json_dict['vali_k']
cuto... |
Iterator of settings for evaluation when performing adversarial ltr
| grid_search | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def to_data_setting_string(self, log=False):
"""
String identifier of data-setting
:param log:
:return:
"""
data_dict = self.data_dict
s1, s2 = (':', '\n') if log else ('_', '_')
data_id, binary_rele = data_dict['data_id'], data_dict['binary_rele']
min_docs, min_rele, train_rough_batch_size, train_pr... |
String identifier of data-setting
:param log:
:return:
| to_data_setting_string | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def default_setting(self):
"""
A default setting for data loading when performing adversarial ltr
"""
unknown_as_zero = False
binary_rele = False # using the original values
train_presort, validation_presort, test_presort = True, True, True
train_rough_batch_size, validation_rough_batch_size, test_rough_... |
A default setting for data loading when performing adversarial ltr
| default_setting | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def grid_search(self):
"""
Iterator of settings for data loading when performing adversarial ltr
"""
if self.use_json:
scaler_id = self.json_dict['scaler_id']
choice_min_docs = self.json_dict['min_docs']
choice_min_rele = self.json_dict['min_rele']
choice_binary_rele = self.json_dict['binary_rele']
... |
Iterator of settings for data loading when performing adversarial ltr
| grid_search | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ad_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ad_parameter.py | MIT |
def check_consistency(self, data_dict, eval_dict, sf_para_dict):
"""
Check whether the settings are reasonable in the context of adversarial learning-to-rank
"""
''' Part-1: data loading '''
assert 1 == data_dict['train_rough_batch_size'] # the required setting w.r.t. adversaria... |
Check whether the settings are reasonable in the context of adversarial learning-to-rank
| check_consistency | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ltr_adversarial.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ltr_adversarial.py | MIT |
def get_ad_machine(self, eval_dict=None, data_dict=None, sf_para_dict=None, ad_para_dict=None):
"""
Initialize the adversarial model correspondingly.
:param eval_dict:
:param data_dict:
:param sf_para_dict:
:param ad_para_dict:
:return:
"""
model_i... |
Initialize the adversarial model correspondingly.
:param eval_dict:
:param data_dict:
:param sf_para_dict:
:param ad_para_dict:
:return:
| get_ad_machine | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ltr_adversarial.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ltr_adversarial.py | MIT |
def ad_cv_eval(self, data_dict=None, eval_dict=None, ad_para_dict=None, sf_para_dict=None):
"""
Adversarial training and evaluation
:param data_dict:
:param eval_dict:
:param ad_para_dict:
:param sf_para_dict:
:return:
"""
self.display_information(... |
Adversarial training and evaluation
:param data_dict:
:param eval_dict:
:param ad_para_dict:
:param sf_para_dict:
:return:
| ad_cv_eval | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ltr_adversarial.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ltr_adversarial.py | MIT |
def grid_run(self, debug=True, model_id=None, data_id=None, dir_data=None, dir_output=None, dir_json=None):
"""
Perform adversarial learning-to-rank based on grid search of optimal parameter setting
"""
if dir_json is not None:
ad_data_eval_sf_json = dir_json + 'Ad_Data_Eval_... |
Perform adversarial learning-to-rank based on grid search of optimal parameter setting
| grid_run | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ltr_adversarial.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ltr_adversarial.py | MIT |
def point_run(self, debug=False, model_id=None, sf_id=None, data_id=None, dir_data=None, dir_output=None):
"""
:param debug:
:param model_id:
:param data_id:
:param dir_data:
:param dir_output:
:return:
"""
self.set_eval_setting(debug=debug, dir_... |
:param debug:
:param model_id:
:param data_id:
:param dir_data:
:param dir_output:
:return:
| point_run | python | wildltr/ptranking | ptranking/ltr_adversarial/eval/ltr_adversarial.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/eval/ltr_adversarial.py | MIT |
def __init__(self, eval_dict, data_dict, sf_para_dict=None, ad_para_dict=None, optimal_train=False, gpu=False, device=None):
'''
:param optimal_train: training with supervised generator or discriminator
'''
super(IRFGAN_List, self).__init__(eval_dict=eval_dict, data_dict=data_dict, gpu=g... |
:param optimal_train: training with supervised generator or discriminator
| __init__ | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irfgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irfgan_list.py | MIT |
def per_query_generation(self, qid=None, batch_ranking=None, batch_label=None, pos_and_neg=None, generator=None,
samples_per_query=None, top_k=None, temperature=None):
'''
:param pos_and_neg: corresponding to discriminator optimization or generator optimization
'''
... |
:param pos_and_neg: corresponding to discriminator optimization or generator optimization
| per_query_generation | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irfgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irfgan_list.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irfgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irfgan_list.py | MIT |
def __init__(self, eval_dict, data_dict, sf_para_dict=None, ad_para_dict=None, optimal_train=False, gpu=False, device=None):
'''
:param optimal_train: training with supervised generator or discriminator
'''
super(IRGAN_List, self).__init__(eval_dict=eval_dict, data_dict=data_dict, gpu=gp... |
:param optimal_train: training with supervised generator or discriminator
| __init__ | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irgan_list.py | MIT |
def per_query_generation(self, qid=None, batch_ranking=None, batch_label=None, pos_and_neg=None, generator=None,
samples_per_query=None, top_k=None, temperature=None):
'''
:param pos_and_neg: corresponding to discriminator optimization or generator optimization
'''
... |
:param pos_and_neg: corresponding to discriminator optimization or generator optimization
| per_query_generation | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irgan_list.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/listwise/irgan_list.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/listwise/irgan_list.py | MIT |
def fill_global_buffer(self, train_data, dict_buffer=None):
''' Buffer the number of positive documents, and the number of non-positive documents per query '''
assert self.data_dict['train_presort'] is True # this is required for efficient truth exampling
if self.data_dict['data_id'] in MSLETO... | Buffer the number of positive documents, and the number of non-positive documents per query | fill_global_buffer | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irfgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irfgan_pair.py | MIT |
def mini_max_train(self, train_data=None, generator=None, discriminator=None, global_buffer=None):
'''
Here it can not use the way of training like irgan-pair (still relying on single documents rather thank pairs),
since ir-fgan requires to sample with two distributions.
'''
stop... |
Here it can not use the way of training like irgan-pair (still relying on single documents rather thank pairs),
since ir-fgan requires to sample with two distributions.
| mini_max_train | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irfgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irfgan_pair.py | MIT |
def train_discriminator_generator_single_step(self, train_data=None, generator=None, discriminator=None,
global_buffer=None):
''' Train both discriminator and generator with a single step per query '''
stop_training = False
generator.train_mode()... | Train both discriminator and generator with a single step per query | train_discriminator_generator_single_step | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irfgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irfgan_pair.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irfgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irfgan_pair.py | MIT |
def __init__(self, eval_dict, data_dict, sf_para_dict=None, ad_para_dict=None, gpu=False, device=None):
'''
:param sf_para_dict:
:param temperature: according to the description around Eq-10, temperature is deployed, while it is not used within the provided code
'''
super(IRGAN_P... |
:param sf_para_dict:
:param temperature: according to the description around Eq-10, temperature is deployed, while it is not used within the provided code
| __init__ | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irgan_pair.py | MIT |
def fill_global_buffer(self, train_data, dict_buffer=None):
''' Buffer the number of positive documents, and the number of non-positive documents per query '''
assert self.data_dict['train_presort'] is True # this is required for efficient truth exampling
for entry in train_data:
q... | Buffer the number of positive documents, and the number of non-positive documents per query | fill_global_buffer | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irgan_pair.py | MIT |
def generate_data(self, train_data=None, generator=None, global_buffer=None):
'''
Sampling for training discriminator
This is a re-implementation as the released irgan-tensorflow, but it seems that this part of irgan-tensorflow
is not consistent with the discription of the paper (i.e., t... |
Sampling for training discriminator
This is a re-implementation as the released irgan-tensorflow, but it seems that this part of irgan-tensorflow
is not consistent with the discription of the paper (i.e., the description below Eq. 7)
| generate_data | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irgan_pair.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/pairwise/irgan_pair.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pairwise/irgan_pair.py | MIT |
def fill_global_buffer(self, train_data, dict_buffer=None):
''' Buffer the number of positive documents per query '''
assert self.data_dict['train_presort'] is True # this is required for efficient truth exampling
for entry in train_data:
qid, _, batch_label = entry[0], entry[1], e... | Buffer the number of positive documents per query | fill_global_buffer | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irfgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irfgan_point.py | MIT |
def train_discriminator_generator_single_step(self, train_data=None, generator=None, discriminator=None,
global_buffer=None):
''' Train both discriminator and generator with a single step per query '''
generator.train_mode()
for entry in train_d... | Train both discriminator and generator with a single step per query | train_discriminator_generator_single_step | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irfgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irfgan_point.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irfgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irfgan_point.py | MIT |
def __init__(self, eval_dict, data_dict, sf_para_dict=None, ad_para_dict=None, gpu=False, device=None):
'''
:param ad_training_order: really matters, DG is preferred than GD
'''
super(IRGAN_Point, self).__init__(eval_dict=eval_dict, data_dict=data_dict, gpu=gpu, device=device)
'... |
:param ad_training_order: really matters, DG is preferred than GD
| __init__ | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irgan_point.py | MIT |
def fill_global_buffer(self, train_data, dict_buffer=None):
''' Buffer the number of positive documents per query '''
assert self.data_dict['train_presort'] is True # this is required for efficient truth exampling
for entry in train_data:
qid, _, batch_label = entry[0], entry[1], e... | Buffer the number of positive documents per query | fill_global_buffer | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irgan_point.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
"""
# using specified para-dict or inner para-dict
ad_para_dict = ... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
| to_para_string | python | wildltr/ptranking | ptranking/ltr_adversarial/pointwise/irgan_point.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/pointwise/irgan_point.py | MIT |
def get_f_divergence_functions(f_div_str=None):
'''
the activation function is chosen as a monotone increasing function
'''
if 'TVar' == f_div_str: # Total variation
def activation_f(v):
return 0.5 * torch.tanh(v)
def conjugate_f(t):
return t
elif 'KL' == f_... |
the activation function is chosen as a monotone increasing function
| get_f_divergence_functions | python | wildltr/ptranking | ptranking/ltr_adversarial/util/f_divergence.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/f_divergence.py | MIT |
def gumbel_softmax(logits, samples_per_query, temperature=1.0, cuda=False, cuda_device=None):
'''
:param logits: [1, ranking_size]
:param num_samples_per_query: number of stochastic rankings to generate
:param temperature:
:return:
'''
assert 1 == logits.size(0) and 2 == len(logits.size())
... |
:param logits: [1, ranking_size]
:param num_samples_per_query: number of stochastic rankings to generate
:param temperature:
:return:
| gumbel_softmax | python | wildltr/ptranking | ptranking/ltr_adversarial/util/list_sampling.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/list_sampling.py | MIT |
def sample_ranking_PL_gumbel_softmax(batch_preds, num_sample_ranking=1, only_indices=True, temperature=1.0, gpu=False, device=None):
'''
Sample a ranking based stochastic Plackett-Luce model, where gumble noise is added
@param batch_preds: [1, ranking_size] vector of relevance predictions for documents asso... |
Sample a ranking based stochastic Plackett-Luce model, where gumble noise is added
@param batch_preds: [1, ranking_size] vector of relevance predictions for documents associated with the same query
@param num_sample_ranking: number of rankings to sample
@param only_indices: only return the indices or n... | sample_ranking_PL_gumbel_softmax | python | wildltr/ptranking | ptranking/ltr_adversarial/util/list_sampling.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/list_sampling.py | MIT |
def arg_shuffle_ties(target_batch_stds, descending=True, gpu=False, device=None):
''' Shuffle ties, and return the corresponding indice '''
batch_size, ranking_size = target_batch_stds.size()
if batch_size > 1:
list_rperms = []
for _ in range(batch_size):
list_rperms.append(torch... | Shuffle ties, and return the corresponding indice | arg_shuffle_ties | python | wildltr/ptranking | ptranking/ltr_adversarial/util/list_sampling.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/list_sampling.py | MIT |
def get_weighted_clipped_pos_diffs(qid, sorted_std_labels, global_buffer=None):
'''
Get total true pairs based on explicit labels.
In particular, the difference values are discounted based on positions.
'''
num_pos, num_explicit, num_neg_unk, num_unk, num_unique_labels = global_buffer[qid]
mat_d... |
Get total true pairs based on explicit labels.
In particular, the difference values are discounted based on positions.
| get_weighted_clipped_pos_diffs | python | wildltr/ptranking | ptranking/ltr_adversarial/util/pair_sampling.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/pair_sampling.py | MIT |
def sample_pairs_BT(point_vals=None, num_pairs=None):
''' The probability of observing a pair of ordered documents is formulated based on Bradley-Terry model, i.e., p(d_i > d_j)=1/(1+exp(-delta(s_i - s_j))) '''
# the rank information is not taken into account, and all pairs are treated equally.
#total_item... | The probability of observing a pair of ordered documents is formulated based on Bradley-Terry model, i.e., p(d_i > d_j)=1/(1+exp(-delta(s_i - s_j))) | sample_pairs_BT | python | wildltr/ptranking | ptranking/ltr_adversarial/util/pair_sampling.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_adversarial/util/pair_sampling.py | MIT |
def ini_listsf(self, num_features=None, n_heads=2, encoder_layers=2, dropout=0.1, encoder_type=None,
ff_dims=[256, 128, 64], out_dim=1, AF='R', TL_AF='GE', apply_tl_af=False,
BN=True, bn_type=None, bn_affine=False):
'''
Initialization the univariate scoring function... |
Initialization the univariate scoring function for diversified ranking.
| ini_listsf | python | wildltr/ptranking | ptranking/ltr_diversification/base/div_list_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/base/div_list_ranker.py | MIT |
def get_diff_normal(self, batch_mus, batch_vars, batch_cocos=None):
'''
The difference of two normal random variables is another normal random variable. In particular, we consider two
cases: (1) correlated (2) independent.
@param batch_mus: the predicted mean
@param batch_vars: t... |
The difference of two normal random variables is another normal random variable. In particular, we consider two
cases: (1) correlated (2) independent.
@param batch_mus: the predicted mean
@param batch_vars: the predicted variance
@param batch_cocos: the predicted correlation coe... | get_diff_normal | python | wildltr/ptranking | ptranking/ltr_diversification/base/div_mdn_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/base/div_mdn_ranker.py | MIT |
def ini_listsf(self, num_features=None, n_heads=2, encoder_layers=2, dropout=0.1, encoder_type=None,
ff_dims=[256, 128, 64], out_dim=1, AF='R', TL_AF='GE', apply_tl_af=False,
BN=True, bn_type=None, bn_affine=False):
'''
Initialization the univariate scoring function... |
Initialization the univariate scoring function for diversified ranking.
| ini_listsf | python | wildltr/ptranking | ptranking/ltr_diversification/base/div_mdn_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/base/div_mdn_ranker.py | MIT |
def div_predict(self, q_repr, doc_reprs):
'''
The relevance prediction. In the context of diversified ranking, the shape is interpreted as:
@param q_repr:
@param doc_reprs:
@return:
'''
if self.sf_id.endswith("co"):
batch_mus, batch_vars, batch_cocos =... |
The relevance prediction. In the context of diversified ranking, the shape is interpreted as:
@param q_repr:
@param doc_reprs:
@return:
| div_predict | python | wildltr/ptranking | ptranking/ltr_diversification/base/div_mdn_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/base/div_mdn_ranker.py | MIT |
def default_pointsf_para_dict(self):
"""
The default setting of the hyper-parameters of the stump neural scoring function.
"""
self.sf_para_dict = dict()
if self.use_json:
opt = self.json_dict['opt'][0]
lr = self.json_dict['lr'][0]
pointsf_jso... |
The default setting of the hyper-parameters of the stump neural scoring function.
| default_pointsf_para_dict | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def default_listsf_para_dict(self):
"""
The default setting of the hyper-parameters of the permutation-equivariant neural scoring function.
"""
self.sf_para_dict = dict()
if self.use_json:
opt = self.json_dict['opt'][0]
lr = self.json_dict['lr'][0]
... |
The default setting of the hyper-parameters of the permutation-equivariant neural scoring function.
| default_listsf_para_dict | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def pointsf_grid_search(self):
"""
Iterator of hyper-parameters of the stump neural scoring function.
"""
if self.use_json:
choice_opt = self.json_dict['opt']
choice_lr = self.json_dict['lr']
pointsf_json_dict = self.json_dict[self.sf_id]
c... |
Iterator of hyper-parameters of the stump neural scoring function.
| pointsf_grid_search | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def listsf_to_para_string(self, log=False):
''' Get the identifier of scoring function '''
sf_str = super().listsf_to_para_string(log=log)
s1, s2 = (':', '\n') if log else ('_', '_')
if self.sf_id.endswith("co"):
if log:
sf_str = s2.join([sf_str, s1.join(['Co... | Get the identifier of scoring function | listsf_to_para_string | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def to_eval_setting_string(self, log=False):
"""
String identifier of eval-setting
:param log:
:return:
"""
eval_dict = self.eval_dict
s1, s2 = (':', '\n') if log else ('_', '_')
do_vali, epochs = eval_dict['do_validation'], eval_dict['epochs']
if... |
String identifier of eval-setting
:param log:
:return:
| to_eval_setting_string | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def default_setting(self):
"""
A default setting for evaluation when performing diversified ranking.
:param debug:
:param data_id:
:param dir_output:
:return:
"""
if self.use_json:
dir_output = self.json_dict['dir_output']
epochs = ... |
A default setting for evaluation when performing diversified ranking.
:param debug:
:param data_id:
:param dir_output:
:return:
| default_setting | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def grid_search(self):
"""
Iterator of settings for evaluation when performing diversified ranking.
"""
if self.use_json:
dir_output = self.json_dict['dir_output']
epochs = 5 if self.debug else self.json_dict['epochs']
do_validation = self.json_dict['... |
Iterator of settings for evaluation when performing diversified ranking.
| grid_search | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def to_data_setting_string(self, log=False):
"""
String identifier of data-setting
:param log:
:return:
"""
data_dict = self.data_dict
setting_string, add_noise = data_dict['data_id'], data_dict['add_noise']
if add_noise:
std_delta = data_dict[... |
String identifier of data-setting
:param log:
:return:
| to_data_setting_string | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def default_setting(self):
"""
A default setting for data loading when performing diversified ranking
"""
if self.use_json:
add_noise = self.json_dict['add_noise'][0]
std_delta = self.json_dict['std_delta'][0] if add_noise else None
self.data_dict = di... |
A default setting for data loading when performing diversified ranking
| default_setting | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def grid_search(self):
"""
Iterator of settings for data loading when performing adversarial ltr
"""
if self.use_json:
choice_add_noise = self.json_dict['add_noise']
choice_std_delta = self.json_dict['std_delta'] if True in choice_add_noise else None
s... |
Iterator of settings for data loading when performing adversarial ltr
| grid_search | python | wildltr/ptranking | ptranking/ltr_diversification/eval/div_parameter.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/div_parameter.py | MIT |
def load_data(self, eval_dict=None, data_dict=None, fold_k=None, discriminator=None):
"""
We note that it is impossible to perform processing over multiple queries,
since q_doc_rele_mat may differ from query to query.
@param eval_dict:
@param data_dict:
@param fold_k:
... |
We note that it is impossible to perform processing over multiple queries,
since q_doc_rele_mat may differ from query to query.
@param eval_dict:
@param data_dict:
@param fold_k:
@return:
| load_data | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def setup_output(self, data_dict=None, eval_dict=None, reproduce=False):
"""
Update output directory
:param data_dict:
:param eval_dict:
:param sf_para_dict:
:param model_para_dict:
:return:
"""
model_id = self.model_parameter.model_id
grid... |
Update output directory
:param data_dict:
:param eval_dict:
:param sf_para_dict:
:param model_para_dict:
:return:
| setup_output | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def setup_eval(self, data_dict, eval_dict, sf_para_dict, model_para_dict):
"""
Finalize the evaluation setting correspondingly
:param data_dict:
:param eval_dict:
:param sf_para_dict:
:param model_para_dict:
:return:
"""
sf_para_dict[sf_para_dict['... |
Finalize the evaluation setting correspondingly
:param data_dict:
:param eval_dict:
:param sf_para_dict:
:param model_para_dict:
:return:
| setup_eval | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def load_ranker(self, sf_para_dict, model_para_dict):
"""
Load a ranker correspondingly
:param sf_para_dict:
:param model_para_dict:
:param kwargs:
:return:
"""
model_id = model_para_dict['model_id']
if model_id in ['DALETOR', 'DivLambdaRank', 'Di... |
Load a ranker correspondingly
:param sf_para_dict:
:param model_para_dict:
:param kwargs:
:return:
| load_ranker | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def log_max(self, data_dict=None, max_cv_avg_scores=None, sf_para_dict=None, eval_dict=None, log_para_str=None):
''' Log the best performance across grid search and the corresponding setting '''
dir_root, cutoffs = eval_dict['dir_root'], eval_dict['cutoffs']
data_id = data_dict['data_id']
... | Log the best performance across grid search and the corresponding setting | log_max | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def grid_run(self, debug=True, model_id=None, sf_id=None, data_id=None, dir_data=None, dir_output=None, dir_json=None):
"""
Perform diversified ranking based on grid search of optimal parameter setting
"""
if dir_json is not None:
div_data_eval_sf_json = dir_json + 'Div_Data_... |
Perform diversified ranking based on grid search of optimal parameter setting
| grid_run | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def point_run(self, debug=False, model_id=None, sf_id=None, data_id=None, dir_data=None, dir_output=None,
dir_json=None, reproduce=False):
"""
:param debug:
:param model_id:
:param data_id:
:param dir_data:
:param dir_output:
:return:
"""... |
:param debug:
:param model_id:
:param data_id:
:param dir_data:
:param dir_output:
:return:
| point_run | python | wildltr/ptranking | ptranking/ltr_diversification/eval/ltr_diversification.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/eval/ltr_diversification.py | MIT |
def get_approx_ranks(batch_preds, rt=None, device=None, q_doc_rele_mat=None):
''' get approximated rank positions: Equation-7 in the paper'''
batch_pred_diffs = torch.unsqueeze(batch_preds, dim=2) - torch.unsqueeze(batch_preds, dim=1) # computing pairwise differences, i.e., Sij or Sxy
batch_indicators = r... | get approximated rank positions: Equation-7 in the paper | get_approx_ranks | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def alphaDCG_as_a_loss(batch_preds=None, q_doc_rele_mat=None, rt=10, device=None, alpha=0.5, top_k=10):
"""
There are two ways to formulate the loss: (1) using the ideal order; (2) using the predicted order (TBA)
"""
batch_hat_pis, prior_cover_cnts = get_approx_ranks(batch_preds, rt=rt, device=device, q... |
There are two ways to formulate the loss: (1) using the ideal order; (2) using the predicted order (TBA)
| alphaDCG_as_a_loss | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def div_custom_loss_function(self, batch_preds, q_doc_rele_mat, **kwargs):
'''
:param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents within a ltr_adhoc
:param batch_stds: [batch, ranking_size] each row represents the standard relevance grades for d... |
:param batch_preds: [batch, ranking_size] each row represents the relevance predictions for documents within a ltr_adhoc
:param batch_stds: [batch, ranking_size] each row represents the standard relevance grades for documents within a ltr_adhoc
:return:
| div_custom_loss_function | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def default_para_dict(self):
"""
Default parameter setting for DALETOR. Here rt (reversed T) corresponds to 1/T in paper.
:return:
"""
if self.use_json:
top_k = self.json_dict['top_k'][0]
rt = self.json_dict['rt'][0] # corresponds to 1/T in paper
... |
Default parameter setting for DALETOR. Here rt (reversed T) corresponds to 1/T in paper.
:return:
| default_para_dict | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
"""
# using specified para-dict or inner para-dict
... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
:return:
| to_para_string | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def grid_search(self):
"""
Iterator of parameter settings for ApproxNDCG
"""
if self.use_json:
choice_rt = self.json_dict['rt'] # corresponds to 1/T in paper
choice_topk = self.json_dict['top_k'] # the cutoff value of optimising objective alpha-nDCG@k
else... |
Iterator of parameter settings for ApproxNDCG
| grid_search | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/daletor.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/daletor.py | MIT |
def alpha_dcg_as_a_loss(top_k=None, batch_mus=None, batch_vars=None, batch_cocos=None, q_doc_rele_mat=None,
opt_ideal=True, presort=False, beta=0.5, const=False, const_var=None):
'''
Alpha_nDCG as the optimization objective.
@param top_k:
@param batch_mus:
@param batch_vars:
... |
Alpha_nDCG as the optimization objective.
@param top_k:
@param batch_mus:
@param batch_vars:
@param batch_cocos:
@param q_doc_rele_mat:
@param opt_ideal:
@param presort:
@param beta:
@return:
| alpha_dcg_as_a_loss | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | MIT |
def err_ia_as_a_loss(top_k=None, batch_mus=None, batch_vars=None, batch_cocos=None, q_doc_rele_mat=None,
opt_ideal=True, presort=False, max_label=1.0, device=None, const=False, const_var=None):
'''
ERR-IA as the optimization objective.
@param top_k:
@param batch_mus:
@param batc... |
ERR-IA as the optimization objective.
@param top_k:
@param batch_mus:
@param batch_vars:
@param batch_cocos:
@param q_doc_rele_mat:
@param opt_ideal:
@param presort:
@return:
| err_ia_as_a_loss | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | MIT |
def div_custom_loss_function(self, batch_mus, batch_vars, q_doc_rele_mat, **kwargs):
'''
In the context of SRD, batch_size is commonly 1.
@param batch_mus: [batch_size, ranking_size] each row represents the mean predictions for documents associated with the same query
@param batch_vars: ... |
In the context of SRD, batch_size is commonly 1.
@param batch_mus: [batch_size, ranking_size] each row represents the mean predictions for documents associated with the same query
@param batch_vars: [batch_size, ranking_size] each row represents the variance predictions for documents associated... | div_custom_loss_function | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | MIT |
def to_para_string(self, log=False, given_para_dict=None):
"""
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
"""
# using specified para-dict or inner para-dict
probrank_para_d... |
String identifier of parameters
:param log:
:param given_para_dict: a given dict, which is used for maximum setting w.r.t. grid-search
| to_para_string | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | MIT |
def grid_search(self):
""" Iterator of parameter settings for MiDeExpectedUtility """
if self.use_json:
choice_topk = self.json_dict['top_k']
choice_opt_id = self.json_dict['opt_id']
choice_K = self.json_dict['K']
choice_cluster = self.json_dict['cluster']... | Iterator of parameter settings for MiDeExpectedUtility | grid_search | python | wildltr/ptranking | ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/score_and_sort/div_prob_ranker.py | MIT |
def get_div_data_meta(data_id=None):
""" Get the meta-information corresponding to the specified dataset """
if data_id in TREC_DIV:
fold_num = 5
max_label = 1
num_features = 100
else:
raise NotImplementedError
data_meta = dict(num_features=num_features, fold_num=fold_nu... | Get the meta-information corresponding to the specified dataset | get_div_data_meta | python | wildltr/ptranking | ptranking/ltr_diversification/util/div_data.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/div_data.py | MIT |
def deploy_1st_stage_div_discriminating(discriminator, rerank_k, q_repr, doc_reprs, gpu, device):
''' Perform 1st-stage ranking as a discriminating process. '''
sys_rele_preds = discriminator.div_predict(q_repr, doc_reprs) # [1, ranking_size]
if gpu: sys_rele_preds = sys_rele_preds.cpu()
_, sys_sorted... | Perform 1st-stage ranking as a discriminating process. | deploy_1st_stage_div_discriminating | python | wildltr/ptranking | ptranking/ltr_diversification/util/div_data.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/div_data.py | MIT |
def get_pairwise_comp_probs(batch_preds, std_q_doc_rele_mat, sigma=None):
'''
Get the predicted and standard probabilities p_ij which denotes d_i beats d_j, the subtopic labels are aggregated.
@param batch_preds:
@param batch_std_labels:
@param sigma:
@return:
'''
# standard pairwise dif... |
Get the predicted and standard probabilities p_ij which denotes d_i beats d_j, the subtopic labels are aggregated.
@param batch_preds:
@param batch_std_labels:
@param sigma:
@return:
| get_pairwise_comp_probs | python | wildltr/ptranking | ptranking/ltr_diversification/util/div_lambda_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/div_lambda_utils.py | MIT |
def get_prob_pairwise_comp_probs(batch_pairsub_mus, batch_pairsub_vars, q_doc_rele_mat):
'''
The difference of two normal random variables is another normal random variable.
pairsub_mu & pairsub_var denote the corresponding mean & variance of the difference of two normal random variables
p_ij denotes th... |
The difference of two normal random variables is another normal random variable.
pairsub_mu & pairsub_var denote the corresponding mean & variance of the difference of two normal random variables
p_ij denotes the probability that d_i beats d_j
@param batch_pairsub_mus:
@param batch_pairsub_vars:
... | get_prob_pairwise_comp_probs | python | wildltr/ptranking | ptranking/ltr_diversification/util/div_lambda_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/div_lambda_utils.py | MIT |
def get_diff_normal(batch_mus, batch_vars, batch_cocos=None):
'''
The difference of two normal random variables is another normal random variable. In particular, we consider two
cases: (1) correlated (2) independent.
@param batch_mus: the predicted mean
@param batch_vars: the predicted variance
... |
The difference of two normal random variables is another normal random variable. In particular, we consider two
cases: (1) correlated (2) independent.
@param batch_mus: the predicted mean
@param batch_vars: the predicted variance
@param batch_cocos: the predicted correlation coefficient in [-1, 1],... | get_diff_normal | python | wildltr/ptranking | ptranking/ltr_diversification/util/prob_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/prob_utils.py | MIT |
def get_diff_normal_resort(batch_mus, batch_vars, batch_cocos=None, batch_resort_inds=None):
'''
Compared with get_diff_normal(), resort is conducted first.
'''
batch_resorted_mus = torch.gather(batch_mus, dim=1, index=batch_resort_inds)
batch_resorted_vars = torch.gather(batch_vars, dim=1, index=ba... |
Compared with get_diff_normal(), resort is conducted first.
| get_diff_normal_resort | python | wildltr/ptranking | ptranking/ltr_diversification/util/prob_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/prob_utils.py | MIT |
def neg_log_likelihood(batch_pairsub_mus, batch_pairsub_vars, top_k=None, device=None):
'''
Compute the negative log-likelihood w.r.t. rankings, where the likelihood is formulated as the joint probability of
consistent pairwise comparisons.
@param batch_pairsub_mus: mean w.r.t. a pair comparison
@pa... |
Compute the negative log-likelihood w.r.t. rankings, where the likelihood is formulated as the joint probability of
consistent pairwise comparisons.
@param batch_pairsub_mus: mean w.r.t. a pair comparison
@param batch_pairsub_vars: variance w.r.t. a pair comparison
@return:
| neg_log_likelihood | python | wildltr/ptranking | ptranking/ltr_diversification/util/prob_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/prob_utils.py | MIT |
def neg_log_likelihood_explicit(batch_pairsub_mus, std_var, top_k=None, device=None):
'''
Compute the negative log-likelihood w.r.t. rankings, where the likelihood is formulated as the joint probability of
consistent pairwise comparisons.
@param batch_pairsub_mus: mean w.r.t. a pair comparison
@para... |
Compute the negative log-likelihood w.r.t. rankings, where the likelihood is formulated as the joint probability of
consistent pairwise comparisons.
@param batch_pairsub_mus: mean w.r.t. a pair comparison
@param batch_pairsub_vars: variance w.r.t. a pair comparison
@return:
| neg_log_likelihood_explicit | python | wildltr/ptranking | ptranking/ltr_diversification/util/prob_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/prob_utils.py | MIT |
def batch_cosine_similarity(x1, x2=None, eps=1e-8):
'''
:param x1: [batch_size, num_docs, num_features]
:param x2: the same shape or None
:param eps:
:return:
'''
x2 = x1 if x2 is None else x2
w1 = x1.norm(p=2, dim=2, keepdim=True)
#print('w1', w1.size(), '\n', w1)
w2 = w1 if x2 ... |
:param x1: [batch_size, num_docs, num_features]
:param x2: the same shape or None
:param eps:
:return:
| batch_cosine_similarity | python | wildltr/ptranking | ptranking/ltr_diversification/util/sim_utils.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_diversification/util/sim_utils.py | MIT |
def check_consistency(self, data_dict, eval_dict):
"""
Check whether the settings are reasonable in the context of gbdt learning-to-rank
"""
''' Part-1: data loading '''
if data_dict['data_id'] == 'Istella':
assert eval_dict['do_validation'] is not True # since ther... |
Check whether the settings are reasonable in the context of gbdt learning-to-rank
| check_consistency | python | wildltr/ptranking | ptranking/ltr_tree/eval/ltr_tree.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_tree/eval/ltr_tree.py | MIT |
def setup_output(self, data_dict=None, eval_dict=None):
"""
Determine the output.
:param data_dict:
:param eval_dict:
:return:
"""
dir_output, grid_search, mask_label = eval_dict['dir_output'], eval_dict['grid_search'],\
... |
Determine the output.
:param data_dict:
:param eval_dict:
:return:
| setup_output | python | wildltr/ptranking | ptranking/ltr_tree/eval/ltr_tree.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_tree/eval/ltr_tree.py | MIT |
def result_to_str(self, list_scores=None, list_cutoffs=None, split_str=', ', metric_str=None):
"""
Convert metric results to a string
:param list_scores:
:param list_cutoffs:
:param split_str:
:param metric_str:
:return:
"""
list_str = []
f... |
Convert metric results to a string
:param list_scores:
:param list_cutoffs:
:param split_str:
:param metric_str:
:return:
| result_to_str | python | wildltr/ptranking | ptranking/ltr_tree/eval/ltr_tree.py | https://github.com/wildltr/ptranking/blob/master/ptranking/ltr_tree/eval/ltr_tree.py | MIT |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.