Skip to content

Commit

Permalink
ruff: first line split + imperative mood (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkafteNicki authored and Borda committed Feb 24, 2023
1 parent 67ef8a0 commit 606dc17
Show file tree
Hide file tree
Showing 104 changed files with 731 additions and 592 deletions.
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ unfixable = ["F401"]
"setup.py" = ["D100", "SIM115"]
"__about__.py" = ["D100"]
"__init__.py" = ["D100"]
"src/**" = [
"D103", # todo # Missing docstring in public function
"D205", # todo # 1 blank line required between summary line and description
"D401", # todo # First line of docstring should be in imperative mood: ...
]
"tests/**" = [
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
Expand Down
4 changes: 1 addition & 3 deletions src/torchmetrics/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def __init__(
self.add_state("value", default=default_value, dist_reduce_fx=fn)

def _cast_and_nan_check_input(self, x: Union[float, Tensor]) -> Tensor:
"""Convert input x to a tensor if not already and afterwards checks for nans that either give an error,
warning or just ignored.
"""
"""Convert input ``x`` to a tensor and check for Nans."""
if not isinstance(x, Tensor):
x = torch.as_tensor(x, dtype=torch.float32, device=self.device)

Expand Down
9 changes: 5 additions & 4 deletions src/torchmetrics/audio/pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@


class PerceptualEvaluationSpeechQuality(Metric):
"""Calculate `Perceptual Evaluation of Speech Quality`_ (PESQ). It's a recognized industry standard for audio
quality that takes into considerations characteristics such as: audio sharpness, call volume, background noise,
clipping, audio interference ect. PESQ returns a score between -0.5 and 4.5 with the higher scores indicating a
better quality.
"""Calculate `Perceptual Evaluation of Speech Quality`_ (PESQ).
It's a recognized industry standard for audio quality that takes into considerations characteristics such as:
audio sharpness, call volume, background noise, clipping, audio interference ect. PESQ returns a score between
-0.5 and 4.5 with the higher scores indicating a better quality.
This metric is a wrapper for the `pesq package`_. Note that input will be moved to ``cpu`` to perform the metric
calculation.
Expand Down
6 changes: 4 additions & 2 deletions src/torchmetrics/audio/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@


class PermutationInvariantTraining(Metric):
"""Calculate `Permutation invariant training`_ (PIT) that can evaluate models for speaker independent multi-
talker speech separation in a permutation invariant way.
"""Calculate `Permutation invariant training`_ (PIT).
This metric can evaluate models for speaker independent multi-talker speech separation in a permutation
invariant way.
As input to ``forward`` and ``update`` the metric accepts the following input
Expand Down
10 changes: 6 additions & 4 deletions src/torchmetrics/audio/sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@


class SignalDistortionRatio(Metric):
r"""Calculate Signal to Distortion Ratio (SDR) metric. See `SDR ref1`_ and `SDR ref2`_ for details on the
metric.
r"""Calculate Signal to Distortion Ratio (SDR) metric.
See `SDR ref1`_ and `SDR ref2`_ for details on the metric.
As input to ``forward`` and ``update`` the metric accepts the following input
Expand Down Expand Up @@ -162,8 +163,9 @@ def plot(self, val: Union[Tensor, Sequence[Tensor], None] = None, ax: Optional[_


class ScaleInvariantSignalDistortionRatio(Metric):
"""`Scale-invariant signal-to-distortion ratio`_ (SI-SDR). The SI-SDR value is in general considered an overall
measure of how good a source sound.
"""`Scale-invariant signal-to-distortion ratio`_ (SI-SDR).
The SI-SDR value is in general considered an overall measure of how good a source sound.
As input to `forward` and `update` the metric accepts the following input
Expand Down
17 changes: 9 additions & 8 deletions src/torchmetrics/audio/stoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@


class ShortTimeObjectiveIntelligibility(Metric):
r"""Calculate STOI (Short-Time Objective Intelligibility) metric for evaluating speech signals. Intelligibility
measure which is highly correlated with the intelligibility of degraded speech signals, e.g., due to additive
noise, single-/multi-channel noise reduction, binary masking and vocoded speech as in CI simulations. The STOI-
measure is intrusive, i.e., a function of the clean and degraded speech signals. STOI may be a good alternative
to the speech intelligibility index (SII) or the speech transmission index (STI), when you are interested in
the effect of nonlinear processing to noisy speech, e.g., noise reduction, binary masking algorithms, on speech
intelligibility. Description taken from `Cees Taal's website`_ and for further defails see `STOI ref1`_ and
`STOI ref2`_.
r"""Calculate STOI (Short-Time Objective Intelligibility) metric for evaluating speech signals.
Intelligibility measure which is highly correlated with the intelligibility of degraded speech signals, e.g., due
to additive noise, single-/multi-channel noise reduction, binary masking and vocoded speech as in CI simulations.
The STOI-measure is intrusive, i.e., a function of the clean and degraded speech signals. STOI may be a good
alternative to the speech intelligibility index (SII) or the speech transmission index (STI), when you are
interested in the effect of nonlinear processing to noisy speech, e.g., noise reduction, binary masking algorithms,
on speech intelligibility. Description taken from `Cees Taal's website`_ and for further defails see `STOI ref1`_
and `STOI ref2`_.
This metric is a wrapper for the `pystoi package`_. As the implementation backend implementation only supports
calculations on CPU, all input will automatically be moved to CPU to perform the metric calculation before being
Expand Down
29 changes: 17 additions & 12 deletions src/torchmetrics/classification/auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@


class BinaryAUROC(BinaryPrecisionRecallCurve):
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for binary tasks. The AUROC
score summarizes the ROC curve into an single number that describes the performance of a model for multiple
thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for binary tasks.
The AUROC score summarizes the ROC curve into an single number that describes the performance of a model for
multiple thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
corresponds to random guessing.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -156,9 +157,10 @@ def plot(


class MulticlassAUROC(MulticlassPrecisionRecallCurve):
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for multiclass tasks. The AUROC
score summarizes the ROC curve into an single number that describes the performance of a model for multiple
thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for multiclass tasks.
The AUROC score summarizes the ROC curve into an single number that describes the performance of a model for
multiple thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
corresponds to random guessing.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -290,9 +292,10 @@ def plot(


class MultilabelAUROC(MultilabelPrecisionRecallCurve):
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for multilabel tasks. The AUROC
score summarizes the ROC curve into an single number that describes the performance of a model for multiple
thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_) for multilabel tasks.
The AUROC score summarizes the ROC curve into an single number that describes the performance of a model for
multiple thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
corresponds to random guessing.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -433,9 +436,11 @@ def plot(


class AUROC:
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_). The AUROC score summarizes the
ROC curve into an single number that describes the performance of a model for multiple thresholds at the same
time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5 corresponds to random guessing.
r"""Compute Area Under the Receiver Operating Characteristic Curve (`ROC AUC`_).
The AUROC score summarizes the ROC curve into an single number that describes the performance of a model for
multiple thresholds at the same time. Notably, an AUROC score of 1 is a perfect score and an AUROC score of 0.5
corresponds to random guessing.
This module is a simple wrapper to get the task specific versions of this metric, which is done by setting the
``task`` argument to either ``'binary'``, ``'multiclass'`` or ``multilabel``. See the documentation of
Expand Down
18 changes: 9 additions & 9 deletions src/torchmetrics/classification/calibration_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@


class BinaryCalibrationError(Metric):
r"""`Top-label Calibration Error`_ for binary tasks. The expected calibration error can be used to quantify how
well a given model is calibrated e.g. how well the predicted output probabilities of the model matches the
actual probabilities of the ground truth distribution.
r"""`Top-label Calibration Error`_ for binary tasks.
The expected calibration error can be used to quantify how well a given model is calibrated e.g. how well the
predicted output probabilities of the model matches the actual probabilities of the ground truth distribution.
Three different norms are implemented, each corresponding to variations on the calibration error metric.
.. math::
Expand Down Expand Up @@ -132,10 +132,10 @@ def compute(self) -> Tensor:


class MulticlassCalibrationError(Metric):
r"""`Top-label Calibration Error`_ for multiclass tasks. The expected calibration error can be used to quantify
how well a given model is calibrated e.g. how well the predicted output probabilities of the model matches the
actual probabilities of the ground truth distribution.
r"""`Top-label Calibration Error`_ for multiclass tasks.
The expected calibration error can be used to quantify how well a given model is calibrated e.g. how well the
predicted output probabilities of the model matches the actual probabilities of the ground truth distribution.
Three different norms are implemented, each corresponding to variations on the calibration error metric.
.. math::
Expand Down Expand Up @@ -237,10 +237,10 @@ def compute(self) -> Tensor:


class CalibrationError:
r"""`Top-label Calibration Error`_. The expected calibration error can be used to quantify how well a given
model is calibrated e.g. how well the predicted output probabilities of the model matches the actual
probabilities of the ground truth distribution.
r"""`Top-label Calibration Error`_.
The expected calibration error can be used to quantify how well a given model is calibrated e.g. how well the
predicted output probabilities of the model matches the actual probabilities of the ground truth distribution.
Three different norms are implemented, each corresponding to variations on the calibration error metric.
.. math::
Expand Down
8 changes: 3 additions & 5 deletions src/torchmetrics/classification/cohen_kappa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@


class BinaryCohenKappa(BinaryConfusionMatrix):
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement for binary tasks. It is defined
as.
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement for binary tasks.
.. math::
\kappa = (p_o - p_e) / (1 - p_e)
Expand Down Expand Up @@ -107,8 +106,7 @@ def compute(self) -> Tensor:


class MulticlassCohenKappa(MulticlassConfusionMatrix):
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement for multiclass tasks. It is
defined as.
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement for multiclass tasks.
.. math::
\kappa = (p_o - p_e) / (1 - p_e)
Expand Down Expand Up @@ -190,7 +188,7 @@ def compute(self) -> Tensor:


class CohenKappa:
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement. It is defined as.
r"""Calculate `Cohen's kappa score`_ that measures inter-annotator agreement.
.. math::
\kappa = (p_o - p_e) / (1 - p_e)
Expand Down
2 changes: 1 addition & 1 deletion src/torchmetrics/classification/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def update(self, preds: Tensor, target: Tensor) -> None:

@no_type_check
def _get_final_stats(self) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
"""Performs concatenation on the stat scores if neccesary, before passing them to a compute function."""
"""Perform concatenation on the stat scores if neccesary, before passing them to a compute function."""
tp = torch.cat(self.tp) if isinstance(self.tp, list) else self.tp
fp = torch.cat(self.fp) if isinstance(self.fp, list) else self.fp
tn = torch.cat(self.tn) if isinstance(self.tn, list) else self.tn
Expand Down
18 changes: 12 additions & 6 deletions src/torchmetrics/classification/exact_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@


class MulticlassExactMatch(Metric):
r"""Compute Exact match (also known as subset accuracy) for multiclass tasks. Exact Match is a stricter version
of accuracy where all labels have to match exactly for the sample to be correctly classified.
r"""Compute Exact match (also known as subset accuracy) for multiclass tasks.
Exact Match is a stricter version of accuracy where all labels have to match exactly for the sample to be
correctly classified.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -140,8 +142,10 @@ def compute(self) -> Tensor:


class MultilabelExactMatch(Metric):
r"""Compute Exact match (also known as subset accuracy) for multilabel tasks. Exact Match is a stricter version
of accuracy where all labels have to match exactly for the sample to be correctly classified.
r"""Compute Exact match (also known as subset accuracy) for multilabel tasks.
Exact Match is a stricter version of accuracy where all labels have to match exactly for the sample to be
correctly classified.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -259,8 +263,10 @@ def compute(self) -> Tensor:


class ExactMatch:
r"""Compute Exact match (also known as subset accuracy). Exact Match is a stricter version of accuracy where all
labels have to match exactly for the sample to be correctly classified.
r"""Compute Exact match (also known as subset accuracy).
Exact Match is a stricter version of accuracy where all labels have to match exactly for the sample to be
correctly classified.
This module is a simple wrapper to get the task specific versions of this metric, which is done by setting the
``task`` argument to either ``'multiclass'`` or ``multilabel``. See the documentation of
Expand Down
20 changes: 12 additions & 8 deletions src/torchmetrics/classification/matthews_corrcoef.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@


class BinaryMatthewsCorrCoef(BinaryConfusionMatrix):
r"""Calculate `Matthews correlation coefficient`_ for binary tasks. This metric measures the general
correlation or quality of a classification.
r"""Calculate `Matthews correlation coefficient`_ for binary tasks.
This metric measures the general correlation or quality of a classification.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -85,8 +86,9 @@ def compute(self) -> Tensor:


class MulticlassMatthewsCorrCoef(MulticlassConfusionMatrix):
r"""Calculate `Matthews correlation coefficient`_ for multiclass tasks. This metric measures the general
correlation or quality of a classification.
r"""Calculate `Matthews correlation coefficient`_ for multiclass tasks.
This metric measures the general correlation or quality of a classification.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -150,8 +152,9 @@ def compute(self) -> Tensor:


class MultilabelMatthewsCorrCoef(MultilabelConfusionMatrix):
r"""Calculate `Matthews correlation coefficient`_ for multilabel tasks. This metric measures the general
correlation or quality of a classification.
r"""Calculate `Matthews correlation coefficient`_ for multilabel tasks.
This metric measures the general correlation or quality of a classification.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -214,8 +217,9 @@ def compute(self) -> Tensor:


class MatthewsCorrCoef:
r"""Calculate `Matthews correlation coefficient`_ . This metric measures the general correlation or quality of
a classification.
r"""Calculate `Matthews correlation coefficient`_ .
This metric measures the general correlation or quality of a classification.
This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the
``task`` argument to either ``'binary'``, ``'multiclass'`` or ``multilabel``. See the documentation of
Expand Down
26 changes: 16 additions & 10 deletions src/torchmetrics/classification/precision_recall_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@


class BinaryPrecisionRecallCurve(Metric):
r"""Compute the precision-recall curve for binary tasks. The curve consist of multiple pairs of precision and
recall values evaluated at different thresholds, such that the tradeoff between the two values can been seen.
r"""Compute the precision-recall curve for binary tasks.
The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
tradeoff between the two values can been seen.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -156,9 +158,10 @@ def compute(self) -> Tuple[Tensor, Tensor, Tensor]:


class MulticlassPrecisionRecallCurve(Metric):
r"""Compute the precision-recall curve for multiclass tasks. The curve consist of multiple pairs of precision
and recall values evaluated at different thresholds, such that the tradeoff between the two values can been
seen.
r"""Compute the precision-recall curve for multiclass tasks.
The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
tradeoff between the two values can been seen.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -286,9 +289,10 @@ def compute(self) -> Union[Tuple[Tensor, Tensor, Tensor], Tuple[List[Tensor], Li


class MultilabelPrecisionRecallCurve(Metric):
r"""Compute the precision-recall curve for multilabel tasks. The curve consist of multiple pairs of precision
and recall values evaluated at different thresholds, such that the tradeoff between the two values can been
seen.
r"""Compute the precision-recall curve for multilabel tasks.
The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
tradeoff between the two values can been seen.
As input to ``forward`` and ``update`` the metric accepts the following input:
Expand Down Expand Up @@ -427,8 +431,10 @@ def compute(self) -> Union[Tuple[Tensor, Tensor, Tensor], Tuple[List[Tensor], Li


class PrecisionRecallCurve:
r"""Compute the precision-recall curve. The curve consist of multiple pairs of precision and recall values
evaluated at different thresholds, such that the tradeoff between the two values can been seen.
r"""Compute the precision-recall curve.
The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
tradeoff between the two values can been seen.
This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the
``task`` argument to either ``'binary'``, ``'multiclass'`` or ``multilabel``. See the documentation of
Expand Down
Loading

0 comments on commit 606dc17

Please sign in to comment.