def check_result(got): try: self.assertEqual(2, len(got), 'got: %s' % got) for res in got: self.assertIn('num_interests', res.extracts['fpl'].features) self.assertEqual( len( meta_feature_extractor.get_feature_value( res.extracts['fpl'], 'interest')), meta_feature_extractor.get_feature_value( res.extracts['fpl'], 'num_interests')) except AssertionError as err: raise util.BeamAssertException(err)
def check_result(got): try: self.assertEqual(2, len(got), 'got: %s' % got) for res in got: self.assertIn( 'num_interests', res[constants. FEATURES_PREDICTIONS_LABELS_KEY].features) self.assertEqual( len( meta_feature_extractor.get_feature_value( res[constants. FEATURES_PREDICTIONS_LABELS_KEY], 'interest')), meta_feature_extractor.get_feature_value( res[constants.FEATURES_PREDICTIONS_LABELS_KEY], 'num_interests')) except AssertionError as err: raise util.BeamAssertException(err)
def testGetSparseTensorValue(self): sparse_tensor_value = tf.compat.v1.SparseTensorValue( indices=[[0, 0, 0], [0, 1, 0], [0, 1, 1]], values=['', 'one', 'two'], dense_shape=[1, 2, 2]) fpl_with_sparse_tensor = types.FeaturesPredictionsLabels( input_ref=0, features={}, predictions={}, labels={}) meta_feature_extractor._set_feature_value( fpl_with_sparse_tensor.features, 'sparse', sparse_tensor_value) self.assertEqual(['', 'one', 'two'], meta_feature_extractor.get_feature_value( fpl_with_sparse_tensor, 'sparse'))
def get_num_interests(fpl): interests = meta_feature_extractor.get_feature_value(fpl, 'interest') new_features = {'num_interests': len(interests)} return new_features