I'm trying to suppress warnings (specifically from tensorflow) in my Jupyter noteboook since they're not relevant and end up just clogging up my screen and making it super difficult to read the stuff I actually need to read. I've tried everything below, the warnings just won't stop:
warnings.filterwarnings('ignore')warnings.simplefilter('ignore')logging.getLogger('tensorflow').disabled = Truelogging.getLogger('tensorflow').setLevel(logging.ERROR)logging.disable(logging.WARNING)os.environ['PYTHONWARNING'] = 'ignore'os.environ['TF_CPP_MIN_LOG_LEVEL'] = 3
I even tried updating my ipython_config.py file with:
c = get_config()
c.InteractiveShellApp.exec_lines = [
'import warnings',
'warnings.filterwarnings("ignore")',
]
And even tried making a context manager like this:
class HiddenPrints:
def __enter__(self):
self._original_stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stderr.close()
sys.stderr = self._original_stderr
with HiddenPrints():
# rest of my code
For context, I get this warning when I import spacy:
2023-05-23 14:42:41.997371: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
And I get a ton of these warnings when I call a function that builds and fits a LSTM keras model:
2023-05-23 14:48:30.399777: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
I've seen some posts suggest using Jupyter's %%capture magic command, but my understanding is that would capture all output not just warnings which I don't want. Any ideas?