def GetMaxId(self, sparse_features): max_id = 0 for x in sparse_features: for y in x: f = sparse_pb2.SparseFeatures() f.ParseFromString(y) for i in f.id: max_id = max(i, max_id) return max_id
def MakeSparseFeatures(self, ids, weights): f = sparse_pb2.SparseFeatures() for i, w in zip(ids, weights): f.id.append(i) f.weight.append(w) return f.SerializeToString()