Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I suppress a specific type of warning message?

I'm aware that using warnings.filterwarnings('ignore') will suppress warning messages, but there's a specific type of warning that I want to suppress.

More specifically, this warning message is being given by a third-party library that I'm using and the log warning message looks like this:

04/23/2021 21:09:39 - WARNING - pytorch_transformers.tokenization_utils -  Token indices sequence length is \
longer than the specified maximum sequence length for this model (589 > 512). Running this sequence through the \
model will result in indexing errors

I'm not sure how I should be suppressing the warning message by using regular expressions or something. I don't want to have to go into the actual script and change things and am wondering if there's a way I can find out the specific way to suppress just this warning message. Thanks.

like image 211
Sean Avatar asked Sep 06 '25 01:09

Sean


1 Answers

You can assign regular expression to message keyword in filterwarnings method.

warnings.filterwarnings('ignore', message='model will result in indexing errors*')

Reference: https://docs.python.org/3/library/warnings.html

like image 81
Zalak Bhalani Avatar answered Sep 08 '25 22:09

Zalak Bhalani