speechbrain.utils.kmeans moduleο
Utilities for training kmeans model.
- Author
Pooneh Mousavi 2023
Summaryο
Functions:
Extract features (output of SSL model) and acculamte them on cpu to be used for clustering. |
|
Return a k-means clustering model with specified parameters. |
|
Process data in chunks of a specified size. |
|
Save a Kmeans model . |
|
Train a Kmeans model . |
Referenceο
- speechbrain.utils.kmeans.accumulate_and_extract_features(batch, features_list, ssl_model, ssl_layer_num, device)[source]ο
Extract features (output of SSL model) and acculamte them on cpu to be used for clustering.
- Parameters:
batch (tensor) β Single batch of data.
features_list (list) β accumulate features list.
ssl_model (torch.nn.Module) β SSL-model used to extract features used for clustering.
ssl_layer_num (int) β specify output of which layer of the ssl_model should be used.
device (str) β
cpuorcudadevice.
- speechbrain.utils.kmeans.fetch_kmeans_model(n_clusters, init, max_iter, batch_size, tol, max_no_improvement, n_init, reassignment_ratio, random_state, checkpoint_path)[source]ο
Return a k-means clustering model with specified parameters.
- Parameters:
n_clusters (MiniBatchKMeans) β The number of clusters to form as well as the number of centroids to generate.
init (int) β Method for initialization: {βk-means++ββ, ββrandomββ}
max_iter (int) β Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.
batch_size (int) β Size of the mini batches.
tol (float) β Control early stopping based on the relative center changes as measured by a smoothed, variance-normalized of the mean center squared position changes.
max_no_improvement (int) β Control early stopping based on the consecutive number of mini batches that does not yield an improvement on the smoothed inertia.
n_init (int) β Number of random initializations that are tried
reassignment_ratio (float) β Control the fraction of the maximum number of counts for a center to be reassigned.
random_state (int) β Determines random number generation for centroid initialization and random reassignment.
checkpoint_path (str) β Path to saved model.
- Returns:
a k-means clustering model with specified parameters.
- Return type:
MiniBatchKMeans
- speechbrain.utils.kmeans.process_chunks(data, chunk_size, model)[source]ο
Process data in chunks of a specified size.
- speechbrain.utils.kmeans.train(model, train_set, ssl_model, save_path, ssl_layer_num, kmeans_batch_size=1000, device='cpu', checkpoint_interval=10)[source]ο
Train a Kmeans model .
- Parameters:
model (MiniBatchKMeans) β The initial kmeans model for training.
train_set (Dataloader) β Batches of tarining data.
ssl_model (torch.nn.Module) β SSL-model used to extract features used for clustering.
save_path (string) β Path to save intra-checkpoints and dataloader.
ssl_layer_num (int) β Specify output of which layer of the ssl_model should be used.
kmeans_batch_size (int) β Size of the mini batches.
device (str) β
cpuorcudadevice.checkpoint_interval (int) β Determine at which iterations to save the checkpoints.