Ejemplo n.º 1
0
 def test_dense(self):
     """Tests only dense inputs."""
     op = sparse_ops._sparse_cross([
         constant_op.constant([['batch1-FC1-F1', 'batch1-FC1-F2'],
                               ['batch2-FC1-F1', 'batch2-FC1-F2']],
                              dtypes.string),
         constant_op.constant([['batch1-FC2-F1', 'batch1-FC2-F2'],
                               ['batch2-FC2-F1', 'batch2-FC2-F2']],
                              dtypes.string),
     ])
     expected_out = self._sparse_tensor(
         [[
             'batch1-FC1-F1_X_batch1-FC2-F1',
             'batch1-FC1-F1_X_batch1-FC2-F2',
             'batch1-FC1-F2_X_batch1-FC2-F1',
             'batch1-FC1-F2_X_batch1-FC2-F2'
         ],
          [
              'batch2-FC1-F1_X_batch2-FC2-F1',
              'batch2-FC1-F1_X_batch2-FC2-F2',
              'batch2-FC1-F2_X_batch2-FC2-F1',
              'batch2-FC1-F2_X_batch2-FC2-F2'
          ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 2
0
    def test_large_batch(self):
        """Tests with large batch size to force multithreading."""
        batch_size = 5000
        col1 = []
        col2 = []
        col3 = []
        for b in range(batch_size):
            col1.append([
                'batch%d-FC1-F1' % b,
                'batch%d-FC1-F2' % b,
                'batch%d-FC1-F3' % b
            ])
            col2.append(['batch%d-FC2-F1' % b])
            col3.append(['batch%d-FC3-F1' % b, 'batch%d-FC3-F2' % b])

        op = sparse_ops._sparse_cross([
            self._sparse_tensor(col1),
            self._sparse_tensor(col2),
            self._sparse_tensor(col3)
        ])

        col_out = []
        for b in range(batch_size):
            col_out.append([
                'batch%d-FC1-F1_X_batch%d-FC2-F1_X_batch%d-FC3-F1' % (b, b, b),
                'batch%d-FC1-F1_X_batch%d-FC2-F1_X_batch%d-FC3-F2' % (b, b, b),
                'batch%d-FC1-F2_X_batch%d-FC2-F1_X_batch%d-FC3-F1' % (b, b, b),
                'batch%d-FC1-F2_X_batch%d-FC2-F1_X_batch%d-FC3-F2' % (b, b, b),
                'batch%d-FC1-F3_X_batch%d-FC2-F1_X_batch%d-FC3-F1' % (b, b, b),
                'batch%d-FC1-F3_X_batch%d-FC2-F1_X_batch%d-FC3-F2' % (b, b, b)
            ])

        expected_out = self._sparse_tensor(col_out)
        with self.test_session() as sess:
            self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 3
0
    def serving_input_receiver_fn():
        ads_serialized_examples = array_ops.placeholder(dtype=dtypes.string)
        user_serialized_example = array_ops.placeholder(dtype=dtypes.string)
        receiver_tensors = {'ads_data': ads_serialized_examples, 'user_data': user_serialized_example}
        user_serialized_examples = tf.tile(user_serialized_example, [tf.shape(ads_serialized_examples)[0]])
        ads_features = parsing_ops.parse_example(ads_serialized_examples, ads_feature_spec)
        user_features = parsing_ops.parse_example(user_serialized_examples, user_feature_spec)
        user_features.update(ads_features)

        user_features["cross_adcad2feature"] = _sparse_cross([user_features['user_adc_features'], ads_features['ad2_features']])
        user_features["cross_adcad2weights"] = _sparse_cross([user_features['user_adc_weights'], ads_features['ad2_weights']])
            
        user_features["cross_adoffad2feature"] = _sparse_cross([user_features['user_adoff_features'], ads_features['ad2_features']])
        user_features["cross_adoffad2weights"] = _sparse_cross([user_features['user_adoff_weights'], ads_features['ad2_weights']])

        return ServingInputReceiver(user_features, receiver_tensors)
Ejemplo n.º 4
0
    def test_all_columns_empty(self):
        """Tests when all columns are empty.

    The crossed tensor should be empty.
    """
        op = sparse_ops._sparse_cross([
            self._sparse_tensor([]),
            self._sparse_tensor([]),
            self._sparse_tensor([])
        ])
        with self.test_session() as sess:
            self._assert_sparse_tensor_empty(sess.run(op))
Ejemplo n.º 5
0
    def test_one_column_empty(self):
        """Tests when one column is empty.

    The crossed tensor should be empty.
    """
        op = sparse_ops._sparse_cross([
            self._sparse_tensor([['batch1-FC1-F1', 'batch1-FC1-F2']]),
            self._sparse_tensor([], 1),
            self._sparse_tensor([['batch1-FC3-F1', 'batch1-FC3-F2']])
        ])
        with self.test_session() as sess:
            self._assert_sparse_tensor_empty(sess.run(op))
Ejemplo n.º 6
0
    def get_next_batch(self):
        (_, records) = self.reader.read_up_to(self.filename_queue, num_records = self.batch_size)
        samples = tf.decode_csv(records, record_defaults = self.column_defaults, field_delim = ',')
        label = tf.cast(samples[self.column_dict["label"]], dtype = tf.int32)
        feature_dict = {}
        for (key, value) in self.column_dict.items():
            if key == "label" or value < 0 or value >= len(samples):
                continue
            if key in ["user_adc_features","user_adoff_features","user_news_features","user_tt_features","user_gg_features","user_sea_features","user_dmp0_features","user_dmp1_features","user_dmp2_features","user_inl_features","user_cpd_features","date_wh_features","position_features","ad1_features","ad2_features","ad3_features"]:
                feature_dict[key] = tf.string_split(samples[value], delimiter = ';')
            if key in ["user_adc_weights","user_adoff_weights","user_news_weights","user_tt_weights","user_gg_weights","user_sea_weights","user_dmp0_weights","user_dmp1_weights","user_dmp2_weights","user_inl_weights","user_cpd_weights","date_wh_weights","position_weights","ad1_weights","ad2_weights","ad3_weights"]:
                feature_dict[key] = self.string_to_number(
                        tf.string_split(samples[value], delimiter = ';'),
                        dtype = tf.float32)
        
        feature_dict["cross_adcad2feature"] = _sparse_cross([feature_dict['user_adc_features'], feature_dict['ad2_features']])
        feature_dict["cross_adcad2weights"] = _sparse_cross([feature_dict['user_adc_weights'], feature_dict['ad2_weights']])
            
        feature_dict["cross_adoffad2feature"] = _sparse_cross([feature_dict['user_adoff_features'], feature_dict['ad2_features']])
        feature_dict["cross_adoffad2weights"] = _sparse_cross([feature_dict['user_adoff_weights'], feature_dict['ad2_weights']])

        return feature_dict, label
Ejemplo n.º 7
0
 def test_integer_mixed_string_sparse(self):
     """Tests mixed type."""
     op = sparse_ops._sparse_cross([
         self._sparse_tensor([[11], [333, 55555]]),
         self._sparse_tensor([['batch1-FC2-F1'],
                              ['batch2-FC2-F1', 'batch2-FC2-F2']])
     ])
     expected_out = self._sparse_tensor([['11_X_batch1-FC2-F1'],
                                         [
                                             '333_X_batch2-FC2-F1',
                                             '333_X_batch2-FC2-F2',
                                             '55555_X_batch2-FC2-F1',
                                             '55555_X_batch2-FC2-F2'
                                         ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 8
0
 def test_integer_sparse_input(self):
     """Tests mixed type sparse and dense inputs."""
     op = sparse_ops._sparse_cross([
         self._sparse_tensor([[11], [333, 5555]]),
         constant_op.constant([['batch1-FC2-F1', 'batch1-FC2-F2'],
                               ['batch2-FC2-F1', 'batch2-FC2-F2']],
                              dtypes.string),
     ])
     expected_out = self._sparse_tensor(
         [['11_X_batch1-FC2-F1', '11_X_batch1-FC2-F2'],
          [
              '333_X_batch2-FC2-F1', '333_X_batch2-FC2-F2',
              '5555_X_batch2-FC2-F1', '5555_X_batch2-FC2-F2'
          ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 9
0
 def test_simple(self):
     """Tests a simple scenario."""
     op = sparse_ops._sparse_cross([
         self._sparse_tensor([['batch1-FC1-F1'],
                              ['batch2-FC1-F1', 'batch2-FC1-F2']]),
         self._sparse_tensor([['batch1-FC2-F1'],
                              ['batch2-FC2-F1', 'batch2-FC2-F2']])
     ])
     expected_out = self._sparse_tensor(
         [['batch1-FC1-F1_X_batch1-FC2-F1'],
          [
              'batch2-FC1-F1_X_batch2-FC2-F1',
              'batch2-FC1-F1_X_batch2-FC2-F2',
              'batch2-FC1-F2_X_batch2-FC2-F1',
              'batch2-FC1-F2_X_batch2-FC2-F2'
          ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 10
0
    def test_some_columns_empty(self):
        """Tests when more than one columns are empty.

    Cross for the corresponding batch should be empty.
    """
        op = sparse_ops._sparse_cross([
            self._sparse_tensor([['batch1-FC1-F1', 'batch1-FC1-F2']], 2),
            self._sparse_tensor([['batch1-FC2-F1'], ['batch2-FC2-F1']], 2),
            self._sparse_tensor([['batch1-FC3-F1', 'batch1-FC3-F2']], 2)
        ])
        expected_out = self._sparse_tensor([[
            'batch1-FC1-F1_X_batch1-FC2-F1_X_batch1-FC3-F1',
            'batch1-FC1-F1_X_batch1-FC2-F1_X_batch1-FC3-F2',
            'batch1-FC1-F2_X_batch1-FC2-F1_X_batch1-FC3-F1',
            'batch1-FC1-F2_X_batch1-FC2-F1_X_batch1-FC3-F2'
        ]], 2)
        with self.test_session() as sess:
            self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 11
0
 def test_permutation_3x1x2(self):
     """Tests 3x1x2 permutation."""
     op = sparse_ops._sparse_cross([
         self._sparse_tensor(
             [['batch1-FC1-F1', 'batch1-FC1-F2', 'batch1-FC1-F3']]),
         self._sparse_tensor([['batch1-FC2-F1']]),
         self._sparse_tensor([['batch1-FC3-F1', 'batch1-FC3-F2']])
     ])
     expected_out = self._sparse_tensor([[
         'batch1-FC1-F1_X_batch1-FC2-F1_X_batch1-FC3-F1',
         'batch1-FC1-F1_X_batch1-FC2-F1_X_batch1-FC3-F2',
         'batch1-FC1-F2_X_batch1-FC2-F1_X_batch1-FC3-F1',
         'batch1-FC1-F2_X_batch1-FC2-F1_X_batch1-FC3-F2',
         'batch1-FC1-F3_X_batch1-FC2-F1_X_batch1-FC3-F1',
         'batch1-FC1-F3_X_batch1-FC2-F1_X_batch1-FC3-F2'
     ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))
Ejemplo n.º 12
0
 def test_integer_mixed_string_dense(self):
     """Tests mixed dense inputs."""
     op = sparse_ops._sparse_cross([
         constant_op.constant([[11, 333], [55555, 999999]], dtypes.int64),
         constant_op.constant([['batch1-FC2-F1', 'batch1-FC2-F2'],
                               ['batch2-FC2-F1', 'batch2-FC2-F2']],
                              dtypes.string),
     ])
     expected_out = self._sparse_tensor([[
         '11_X_batch1-FC2-F1', '11_X_batch1-FC2-F2', '333_X_batch1-FC2-F1',
         '333_X_batch1-FC2-F2'
     ],
                                         [
                                             '55555_X_batch2-FC2-F1',
                                             '55555_X_batch2-FC2-F2',
                                             '999999_X_batch2-FC2-F1',
                                             '999999_X_batch2-FC2-F2'
                                         ]])
     with self.test_session() as sess:
         self._assert_sparse_tensor_equals(expected_out, sess.run(op))