diff --git a/torchtext/__init__.py b/torchtext/__init__.py index caca6db7a8..95059c6399 100644 --- a/torchtext/__init__.py +++ b/torchtext/__init__.py @@ -2,6 +2,18 @@ from torch.hub import _get_torch_home +_WARN = True +_TORCHTEXT_DEPRECATION_MSG = ( + "\n/!\ IMPORTANT WARNING ABOUT TORCHTEXT STATUS /!\ \n" + "Torchtext is deprecated and the last released version will be 0.18 (this one). " + "You can silence this warning by calling the following at the beginnign of your scripts: " + "`import torchtext; torchtext.disable_torchtext_deprecation_warning()`" +) + +def disable_torchtext_deprecation_warning(): + global _WARN + _WARN = False + # the following import has to happen first in order to load the torchtext C++ library from torchtext import _extension # noqa: F401 @@ -9,8 +21,6 @@ _CACHE_DIR = os.path.expanduser(os.path.join(_get_torch_home(), "text")) -from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental - try: from .version import __version__, git_version # noqa: F401 except ImportError: diff --git a/torchtext/data/__init__.py b/torchtext/data/__init__.py index 7728dbd356..22a57a492a 100644 --- a/torchtext/data/__init__.py +++ b/torchtext/data/__init__.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + from .functional import ( custom_replace, filter_wikipedia_xml, diff --git a/torchtext/datasets/__init__.py b/torchtext/datasets/__init__.py index ba519a5db3..f4585ed48e 100644 --- a/torchtext/datasets/__init__.py +++ b/torchtext/datasets/__init__.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + import importlib from .ag_news import AG_NEWS diff --git a/torchtext/experimental/__init__.py b/torchtext/experimental/__init__.py index e69de29bb2..c382cc7bf6 100644 --- a/torchtext/experimental/__init__.py +++ b/torchtext/experimental/__init__.py @@ -0,0 +1,4 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) diff --git a/torchtext/functional.py b/torchtext/functional.py index 73f96a91c6..8c10579fad 100644 --- a/torchtext/functional.py +++ b/torchtext/functional.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from typing import Any, List, Optional import torch diff --git a/torchtext/models/__init__.py b/torchtext/models/__init__.py index 7b80407811..18789c5dcd 100644 --- a/torchtext/models/__init__.py +++ b/torchtext/models/__init__.py @@ -1,2 +1,7 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .roberta import * # noqa: F401, F403 from .t5 import * # noqa: F401, F403 diff --git a/torchtext/nn/__init__.py b/torchtext/nn/__init__.py index c48d6de70e..4e4bb23987 100644 --- a/torchtext/nn/__init__.py +++ b/torchtext/nn/__init__.py @@ -1 +1,6 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .modules import * # noqa: F401,F403 diff --git a/torchtext/prototype/__init__.py b/torchtext/prototype/__init__.py index f7f17fa618..1344c46737 100644 --- a/torchtext/prototype/__init__.py +++ b/torchtext/prototype/__init__.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from . import transforms __all__ = ["transforms"] diff --git a/torchtext/transforms.py b/torchtext/transforms.py index 98ba7b3f55..d25d6dc89b 100644 --- a/torchtext/transforms.py +++ b/torchtext/transforms.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + import json import re from copy import deepcopy diff --git a/torchtext/utils.py b/torchtext/utils.py index 9565cc3b85..5c263d8c93 100644 --- a/torchtext/utils.py +++ b/torchtext/utils.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + import gzip import hashlib import logging diff --git a/torchtext/vocab/__init__.py b/torchtext/vocab/__init__.py index 9336b599c3..99fff110c2 100644 --- a/torchtext/vocab/__init__.py +++ b/torchtext/vocab/__init__.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .vectors import CharNGram, FastText, GloVe, pretrained_aliases, Vectors from .vocab import Vocab from .vocab_factory import build_vocab_from_iterator, vocab