pereval package

Submodules

pereval.alignment module

class pereval.alignment.NoteAligner[source]

Bases: object

get_onset_indices(score, indices=None) List[ndarray[Any, dtype[_ScalarType_co]]][source]

Retrieves onset indices from score.

Parameters:
  • score – Score note array.

  • indices – A subset of score note indices.

Returns:

A list of onset note indices grouped together.

load_score_perf_alignment(alignment_path: str, perf, score) ndarray[Any, dtype[_ScalarType_co]][source]

Loads alignment between score and performance.

Parameters:
  • alignment_path – The path to .match file.

  • perf – Performance note array.

  • score – Score note array.

Returns:

An array with score indices in the first row, and performance indices in the second row.

pereval.correlation module

pereval.correlation.aggregate(indices_lst: List[ndarray[Any, dtype[_ScalarType_co]]], arr: ndarray[Any, dtype[_ScalarType_co]])[source]

Aggregates means of an array grouped by indices.

Parameters:

indices_lst

pereval.correlation.calculate_correlation(score, real_perf, gen_perf, real_score_perf_indices, gen_score_perf_indices, note_aligner) Dict[str, float][source]

Calculates correlation between two performances.

Parameters:
  • real_perf – Real performance.

  • gen_perf – Generated performance

  • real_score_perf_indices – Score-to-performance alignment for real performance.

  • gen_score_perf_indices – Score-to-performance alignment for generated performance.

  • note_aligner – Note aligner.

Returns:

A dictionary with attribute correlations.

pereval.feature_extractor module

class pereval.feature_extractor.CLAMPExtractor[source]

Bases: object

Feature extractor for CLAMP3 model.

extract_features(emb_dir: str) Tuple[ndarray[Any, dtype[_ScalarType_co]], List, List][source]

Extracts features from a directory.

Parameters:

emb_dir – The directory where embeddings are stored.

Returns:

Embeddings of shape (N, D), a list of score names, and a list of performance names.

class pereval.feature_extractor.FeatureExtractor[source]

Bases: object

Feature extractor for Aria model.

extract_features(emb_path: str) Tuple[ndarray[Any, dtype[_ScalarType_co]], List, List][source]

Extracts features from a .pt file.

Parameters:

emb_path – The path to embeddings file.

Returns:

Embeddings of shape (N, D), a list of score names, and a list of performance names.

pereval.feature_extractor.get_aria_embeddings(evaluation_dir: str, model: Module, device) Dict[source]

Constructs Aria embeddings for performances.

Parameters:
  • evaluation_dir – A directory with performances.

  • model – Aria model.

  • device – Device.

Returns:

A dictionary with score names as keys.

pereval.fmd module

Code is adapted from: https://github.com/microsoft/fadtk

class pereval.fmd.FrechetMusicDistance[source]

Bases: object

compute_fmd(ref_emb: ndarray[Any, dtype[_ScalarType_co]], test_emb: ndarray[Any, dtype[_ScalarType_co]]) float[source]

Computes Frechet Music Distance.

Parameters:
  • ref_emb – Reference embeddings of shape (N, D).

  • test_emb – Test embeddings of shape (M, D).

Returns:

Frechet Music Distance.

pereval.kmd module

Code is adapted from: https://github.com/YoonjinXD/kadtk

class pereval.kmd.KernelMusicDistance(scale_factor: float = 100)[source]

Bases: object

calculate_bandwidth(ref_emb: Tensor, precision=torch.float32) None[source]

Calculates the kernel bandwidth.

Parameters:
  • ref_emb – The set of reference embeddings.

  • precision – Type setting for matrix calculation precision.

compute_kmd(x: Tensor, y: Tensor, bandwidth=None, precision=torch.float32, eps=1e-08, return_components=False) Tensor[source]

Compute the Kernel Music Distance (KMD) between two samples using PyTorch.

Parameters:
  • x – The set of model embeddings of shape (m, embedding_dim).

  • y – The set of reference embeddings of shape (n, embedding_dim).

  • bandwidth – The bandwidth value for the Gaussian RBF kernel.

  • precision – Type setting for matrix calculation precision.

  • eps – Small value to prevent division by zero.

  • return_components – If True, returns mean components.

Returns:

The KMD between x and y embedding sets.

class pereval.kmd.KernelPerformanceDistance(scale_factor: float = 100)[source]

Bases: object

calculate_bandwidth(ref_emb: Tensor, label_lst: List[str], precision=torch.float32) None[source]

Calculates the kernel bandwidth.

Parameters:
  • ref_emb – The set of reference embeddings.

  • label_lst – The list of labels.

  • precision – Type setting for matrix calculation precision.

compute_kmd(x: Tensor, y: Tensor, kernel=None, eps=1e-08)[source]
compute_kpd(x: Tensor, y: Tensor, x_label_lst: List[str], y_label_lst: List[str], bandwidth=None, precision=torch.float32, eps=1e-08, return_components=False)[source]

Compute the Kernel Performance Distance (KPD) between two samples using PyTorch.

Parameters:
  • x – The set of model embeddings of shape (m, embedding_dim).

  • y – The set of reference embeddings of shape (n, embedding_dim).

  • x_label_lst – The list of labels for x.

  • y_label_lst – The list of labels for y.

  • bandwidth – The bandwidth value for the Gaussian RBF kernel.

  • precision – Type setting for matrix calculation precision.

  • eps – Small value to prevent division by zero.

  • return_components – If True, returns mean components.

Returns:

The KPD between x and y embedding sets.

pereval.kmd.median_pairwise_distance(x, subsample=None)[source]

Compute the median pairwise distance of an embedding set.

Args: x: torch.Tensor of shape (n_samples, embedding_dim) subsample: int, number of random pairs to consider (optional)

Returns: The median pairwise distance between points in x.

pereval.pseudo_rating module

class pereval.pseudo_rating.MahalanobisRating[source]

Bases: object

Pseudo-rating based on Mahalanobis distance.

fit_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str])[source]

Fits score-conditional precision matrix.

Parameters:
  • cov_emb – The embeddings of shape (N, D).

  • score_lst – The names of the pieces for each embedding.

predict(emb: ndarray[Any, dtype[_ScalarType_co]], ref_emb: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Predicts a pseudo-rating.

Parameters:
  • emb – The embeddings of shape (N, D) for which the ratings should be predicted.

  • ref_emb – The reference embeddings.

Returns:

An array of ratings of shape (N,).

class pereval.pseudo_rating.MarginalMahalanobisRating[source]

Bases: object

Pseudo-rating based on Marginal Mahalanobis distance.

fit_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]])[source]

Fits marginal precision matrix.

Parameters:

cov_emb – The embeddings of shape (N, D).

predict(emb: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Predicts a pseudo-rating.

Parameters:

emb – The embeddings of shape (N, D) for which the ratings should be predicted.

Returns:

An array of ratings of shape (N,).

class pereval.pseudo_rating.RelativeMahalanobisRating[source]

Bases: object

Pseudo-rating based on Relative Mahalanobis distance.

fit_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str])[source]

Fits score-conditional precision matrix.

Parameters:
  • cov_emb – The embeddings of shape (N, D).

  • score_lst – The names of the pieces for each embedding.

predict(emb: ndarray[Any, dtype[_ScalarType_co]], ref_emb: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Predicts a pseudo-rating.

Parameters:
  • emb – The embeddings of shape (N, D) for which the ratings should be predicted.

  • ref_emb – The reference embeddings.

Returns:

An array of ratings of shape (N,).

pereval.pseudo_rating.estimate_score_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str]) ndarray[Any, dtype[_ScalarType_co]][source]

Estimates the score-conditional precision matrix (the inverse of the covariance).

Parameters:
  • cov_emb – The embeddings of shape (N, D).

  • score_lst – The names of the pieces for each embedding.

Returns:

Score-conditional precision matrix.

pereval.utils module

pereval.utils.calculate_ci(values)[source]

Module contents