예제 #1
0
 def __init__(self, model, batch_size, hparam_str, session):
     """Create the model.
 
     Args:
         model: (BasicModel) The model we are going to train.
         batch_size: the size of the batches generated in each iteration.
         hparam_str: the hyper-parameters for the input layer.
         session: the current tensorflow Session (used for online learning).
     """
     self.hparams = ultra.utils.hparams.HParams(
         click_model_json='./example/ClickModel/pbm_0.1_1.0_4_1.0.json', # the setting file for the predefined click models.
         tau=1,                                                          # Scalar for the probability distribution.
         oracle_mode=False,                                              # Set True to feed relevance labels instead of simulated clicks.
         dynamic_bias_eta_change=0.0,                                    # Set eta change step for dynamic bias severity in training, 0.0 means no change.
         dynamic_bias_step_interval=1000,                                # Set how many steps to change eta for dynamic bias severity in training, 0.0 means no change.
     )
     
     print('Create online simluation feed')
     print(hparam_str)
     self.hparams.parse(hparam_str)
     self.click_model = None
     with open(self.hparams.click_model_json) as fin:
         model_desc = json.load(fin)
         self.click_model = cm.loadModelFromJson(model_desc)
     self.start_index = 0
     self.count = 1
     self.rank_list_size = model.rank_list_size
     self.max_candidate_num = model.max_candidate_num
     self.feature_size = model.feature_size
     self.batch_size = batch_size
     self.model = model
     self.session = session
     self.global_batch_count = 0
예제 #2
0
    def loadEstimatorFromFile(self, file_name):
        """Load a propensity estimator from a json file.

        Args:
            file_name: (string) The path to the json file of the propensity estimator. 
        """
        with open(file_name) as data_file:
            data = json.load(data_file)
            self.click_model = CM.loadModelFromJson(data['click_model'])
        return
예제 #3
0
def main():
    click_model_json_file = sys.argv[1]
    data_dir = sys.argv[2]
    output_path = sys.argv[3]

    print("Load data from " + data_dir)
    train_set = data_utils.read_data(data_dir, 'train')
    click_model = None
    with open(click_model_json_file) as fin:
        model_desc = json.load(fin)
        click_model = CM.loadModelFromJson(model_desc)
    print("Estimating...")
    estimator = RandomizedPropensityEstimator()
    estimator.estimateParametersFromModel(click_model, train_set)
    print("Output results...")
    output_file = output_path + '/randomized_' + click_model_json_file.split(
        '/')[-1][:-5] + '.json'
    estimator.outputEstimatorToFile(output_file)
예제 #4
0
    def __init__(self, model, batch_size, hparam_str, session=None):
        """Create the model.

        Args:
            model: (BasicModel) The model we are going to train.
            batch_size: the size of the batches generated in each iteration.
            hparam_str: the hyper-parameters for the input layer.
        """
        self.hparams = ultra.utils.hparams.HParams(
            # the setting file for the predefined click models.
            # click_model_json='./example/ClickModel/pbm_0.1_1.0_4_1.0.json',
            click_model_json='./ClickModel/pbm_0.1_1.0_4_1.0.json',
            # Set True to feed relevance labels instead of simulated clicks.
            oracle_mode=False,
            # Set eta change step for dynamic bias severity in training, 0.0
            # means no change.
            dynamic_bias_eta_change=0.0,
            # Set how many steps to change eta for dynamic bias severity in
            # training, 0.0 means no change.
            dynamic_bias_step_interval=1000,
        )

        print('Create simluated clicks feed')
        print(hparam_str)
        self.hparams.parse(hparam_str)
        self.click_model = None
        if not self.hparams.oracle_mode:
            with open(self.hparams.click_model_json) as fin:
                model_desc = json.load(fin)
                self.click_model = cm.loadModelFromJson(model_desc)

        self.start_index = 0
        self.count = 1
        self.rank_list_size = model.rank_list_size
        self.feature_size = model.feature_size
        self.batch_size = batch_size
        self.model = model
        self.global_batch_count = 0