今天在用transformers的时候,导包一直报错
AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.activations' has no attribute 'swish'
反正就是说swish这个激活函数找不到
因为我的代码是在这里报错的
from transformers import BertModel
完整的报错
Traceback (most recent call last):
File "C:/Users/Etoile/PycharmProjects/untitled/bertmodel.py", line 1, in <module>
from transformers import BertModel
File "E:\anaconda3\envs\fs\lib\site-packages\transformers\__init__.py", line 135, in <module>
from .pipelines import (
File "E:\anaconda3\envs\fs\lib\site-packages\transformers\pipelines.py", line 48, in <module>
from .modeling_tf_auto import (
File "E:\anaconda3\envs\fs\lib\site-packages\transformers\modeling_tf_auto.py", line 51, in <module>
from .modeling_tf_albert import (
File "E:\anaconda3\envs\fs\lib\site-packages\transformers\modeling_tf_albert.py", line 24, in <module>
from .activations_tf import get_tf_activation
File "E:\anaconda3\envs\fs\lib\site-packages\transformers\activations_tf.py", line 54, in <module>
"swish": tf.keras.activations.swish,
AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.activations' has no attribute 'swish'
因为我在整个代码中没有用到swish的激活函数,所以我直接把报错提示的那个 “E:\anaconda3\envs\fs\lib\site-packages\transformers\activations_tf.py”文件中的
这两行注释掉了就好了