[英]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.我知道使用
warnings.filterwarnings('ignore')
会抑制警告消息,但是我想抑制特定类型的警告。
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.
我不想将 go 转换为实际脚本并进行更改,我想知道是否有办法找出抑制此警告消息的具体方法。 Thanks.
谢谢。
You can assign regular expression to message keyword in filterwarnings method.您可以在 filterwarnings 方法中将正则表达式分配给消息关键字。
warnings.filterwarnings('ignore', message='model will result in indexing errors*')
Reference: https://docs.python.org/3/library/warnings.html参考: https://docs.python.org/3/library/warnings.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.