From fbdc3eb21f2e76a465a83133b22bb4312f9be68e Mon Sep 17 00:00:00 2001 From: Nicki Skafte Date: Sat, 25 Sep 2021 16:11:50 +0200 Subject: [PATCH] Remove deprecated metrics (#545) Co-authored-by: Jirka Borovec --- torchmetrics/functional/__init__.py | 3 +- .../classification/kl_divergence.py | 19 ------- torchmetrics/functional/nlp.py | 45 ---------------- .../functional/regression/__init__.py | 1 - torchmetrics/functional/regression/r2score.py | 47 ----------------- torchmetrics/regression/r2score.py | 51 ------------------- 6 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 torchmetrics/functional/nlp.py delete mode 100644 torchmetrics/functional/regression/r2score.py delete mode 100644 torchmetrics/regression/r2score.py diff --git a/torchmetrics/functional/__init__.py b/torchmetrics/functional/__init__.py index cf2d6aac3f0..e119ccf1168 100644 --- a/torchmetrics/functional/__init__.py +++ b/torchmetrics/functional/__init__.py @@ -27,7 +27,7 @@ from torchmetrics.functional.classification.hamming_distance import hamming_distance from torchmetrics.functional.classification.hinge import hinge from torchmetrics.functional.classification.iou import iou -from torchmetrics.functional.classification.kl_divergence import kl_divergence, kldivergence +from torchmetrics.functional.classification.kl_divergence import kl_divergence from torchmetrics.functional.classification.matthews_corrcoef import matthews_corrcoef from torchmetrics.functional.classification.precision_recall import precision, precision_recall, recall from torchmetrics.functional.classification.precision_recall_curve import precision_recall_curve @@ -45,7 +45,6 @@ from torchmetrics.functional.regression.mean_squared_log_error import mean_squared_log_error from torchmetrics.functional.regression.pearson import pearson_corrcoef from torchmetrics.functional.regression.r2 import r2_score -from torchmetrics.functional.regression.r2score import r2score from torchmetrics.functional.regression.spearman import spearman_corrcoef from torchmetrics.functional.regression.symmetric_mean_absolute_percentage_error import ( symmetric_mean_absolute_percentage_error, diff --git a/torchmetrics/functional/classification/kl_divergence.py b/torchmetrics/functional/classification/kl_divergence.py index edb74795e99..76d8289950c 100644 --- a/torchmetrics/functional/classification/kl_divergence.py +++ b/torchmetrics/functional/classification/kl_divergence.py @@ -13,7 +13,6 @@ # limitations under the License. from typing import Optional, Tuple -from warnings import warn import torch from torch import Tensor @@ -109,21 +108,3 @@ def kl_divergence(p: Tensor, q: Tensor, log_prob: bool = False, reduction: Optio """ measures, total = _kld_update(p, q, log_prob) return _kld_compute(measures, total, reduction) - - -def kldivergence(p: Tensor, q: Tensor, log_prob: bool = False, reduction: Optional[str] = "mean") -> Tensor: - r"""Computes `KL divergence`_ - - .. deprecated:: v0.5 - `kldivergence` was renamed as `kl_divergence` in v0.5 and it will be removed in v0.6 - - Example: - >>> import torch - >>> from torchmetrics.functional import kldivergence - >>> p = torch.tensor([[0.36, 0.48, 0.16]]) - >>> q = torch.tensor([[1/3, 1/3, 1/3]]) - >>> kldivergence(p, q) - tensor(0.0853) - """ - warn("`kldivergence` was renamed as `kl_divergence` in v0.5 and it will be removed in v0.6", DeprecationWarning) - return kl_divergence(p, q, log_prob, reduction) diff --git a/torchmetrics/functional/nlp.py b/torchmetrics/functional/nlp.py deleted file mode 100644 index 72c65324862..00000000000 --- a/torchmetrics/functional/nlp.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from typing import Sequence -from warnings import warn - -from torch import Tensor - -from torchmetrics.functional.text.bleu import bleu_score as _bleu_score - - -def bleu_score( - reference_corpus: Sequence[Sequence[Sequence[str]]], - translate_corpus: Sequence[Sequence[str]], - n_gram: int = 4, - smooth: bool = False, -) -> Tensor: - """Calculate `BLEU score`_ of machine-translated text with one or more references. - - Example: - >>> from torchmetrics.functional import bleu_score - >>> translate_corpus = ['the cat is on the mat'.split()] - >>> reference_corpus = [['there is a cat on the mat'.split(), 'a cat is on the mat'.split()]] - >>> bleu_score(reference_corpus, translate_corpus) - tensor(0.7598) - - .. deprecated:: v0.5 - Use :func:`torchmetrics.functional.text.bleu.bleu_score`. Will be removed in v0.6. - """ - warn( - "Function `functional.nlp.bleu_score` is deprecated in v0.5 and will be removed in v0.6." - " Use `functional.text.bleu.bleu_score` instead.", - DeprecationWarning, - ) - return _bleu_score(reference_corpus, translate_corpus, n_gram, smooth) diff --git a/torchmetrics/functional/regression/__init__.py b/torchmetrics/functional/regression/__init__.py index ec7ec924441..d33edc2fe1c 100644 --- a/torchmetrics/functional/regression/__init__.py +++ b/torchmetrics/functional/regression/__init__.py @@ -23,6 +23,5 @@ from torchmetrics.functional.regression.mean_squared_log_error import mean_squared_log_error # noqa: F401 from torchmetrics.functional.regression.pearson import pearson_corrcoef # noqa: F401 from torchmetrics.functional.regression.r2 import r2_score # noqa: F401 -from torchmetrics.functional.regression.r2score import r2score # noqa: F401 from torchmetrics.functional.regression.spearman import spearman_corrcoef # noqa: F401 from torchmetrics.functional.regression.tweedie_deviance import tweedie_deviance_score # noqa: F401 diff --git a/torchmetrics/functional/regression/r2score.py b/torchmetrics/functional/regression/r2score.py deleted file mode 100644 index 60e3bcce9d7..00000000000 --- a/torchmetrics/functional/regression/r2score.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from warnings import warn - -import torch -from torch import Tensor - -from torchmetrics.functional.regression.r2 import r2_score - - -def r2score( - preds: Tensor, - target: Tensor, - adjusted: int = 0, - multioutput: str = "uniform_average", -) -> Tensor: - r""" - Computes r2 score also known as `R2 Score_Coefficient Determination`_ - - .. deprecated:: v0.5 - `r2score` was renamed as `r2_score` in v0.5 and it will be removed in v0.6 - - Example: - >>> from torchmetrics.functional import r2score - >>> target = torch.tensor([3, -0.5, 2, 7]) - >>> preds = torch.tensor([2.5, 0.0, 2, 8]) - >>> r2score(preds, target) - tensor(0.9486) - - >>> target = torch.tensor([[0.5, 1], [-1, 1], [7, -6]]) - >>> preds = torch.tensor([[0, 2], [-1, 2], [8, -5]]) - >>> r2score(preds, target, multioutput='raw_values') - tensor([0.9654, 0.9082]) - """ - warn("`r2score` was renamed as `r2_score` in v0.5 and it will be removed in v0.6", DeprecationWarning) - return r2_score(preds, target, adjusted, multioutput) diff --git a/torchmetrics/regression/r2score.py b/torchmetrics/regression/r2score.py deleted file mode 100644 index b277fb8b571..00000000000 --- a/torchmetrics/regression/r2score.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from typing import Any, Callable, Optional -from warnings import warn - -from torchmetrics.regression.r2 import R2Score as _R2Score - - -class R2Score(_R2Score): - r""" - Computes r2 score also known as `R2 Score_Coefficient Determination`_: - - .. deprecated:: v0.5 - `r2score` was renamed as `r2_score` in v0.5 and it will be removed in v0.6 - """ - - def __init__( - self, - num_outputs: int = 1, - adjusted: int = 0, - multioutput: str = "uniform_average", - compute_on_step: bool = True, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - dist_sync_fn: Callable = None, - ) -> None: - warn( - "`R2Score` was moved from `torchmetrics.regression.r2` to `torchmetrics.regression.r2_score` in v0.5" - " and it will be removed in v0.6", - DeprecationWarning, - ) - super().__init__( - num_outputs=num_outputs, - adjusted=adjusted, - multioutput=multioutput, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, - )