Skip to content

Instantly share code, notes, and snippets.

@hbredin
Last active November 27, 2018 15:30
Show Gist options
  • Save hbredin/94dccde8a5aa39f134eda2852c02c757 to your computer and use it in GitHub Desktop.
Save hbredin/94dccde8a5aa39f134eda2852c02c757 to your computer and use it in GitHub Desktop.
Pipeline 101
from pyannote.pipeline import Pipeline
import chocolate
class MyPipeline(Pipeline):
def __int__(self):
super().__init__()
self.damping = chocolate.uniform(...)
self.preference = chocolate.uniform(...)
def __call__(self, item):
# item = (X, y_true)
X = item[0]
y_pred = clustering(X, self.damping, self.preference)
return y_pred
def loss(self, item, y_pred)
y_true = item[1]
return f(y_true, y_pred)
from pyannote.pipeline import Optimizer
optimizer = Optimizer(MyPipeline(), '/tmp/toto.db')
result = optimizer.tune([(X1, y1), (X2, y2), (X3, y3)], n_iterations=100)
print(result['best']['loss'])
@hbredin
Copy link
Author

hbredin commented Nov 27, 2018

You can also use pyannote.pipeline.blocks.clustering.AffinityPropagationClustering as a "sub-pipeline".
Its hyper-parameters will automatically be added to the main pipeline:

...

def __init__(self):
    super().__init__()
    self.clustering = AffinityPropagationClustering()

def __call__(self, item):
    X, y_true = item
    return self.clustering(X)   # its parameters are already set by with_params

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment