ScalaConsultants / Aspect-Based-Sentiment-Analysis

💭 Aspect-Based-Sentiment-Analysis: Transformer & Explainable ML (TensorFlow)
Apache License 2.0
543 stars 90 forks source link

ValueError: The first argument to `Layer.call` must always be passed. #43

Open fspanda opened 3 years ago

fspanda commented 3 years ago

I install your module and run quick start

import aspect_based_sentiment_analysis as absa
recognizer = absa.aux_models.BasicPatternRecognizer()
nlp = absa.load(pattern_recognizer=recognizer) 

and the following error occurred.


ValueError                                Traceback (most recent call last)
<ipython-input-356-900f8907a6c9> in <module>
      2 
      3 recognizer = absa.aux_models.BasicPatternRecognizer()
----> 4 nlp = absa.load(pattern_recognizer=recognizer)

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/aspect_based_sentiment_analysis/loads.py in load(name, text_splitter, reference_recognizer, pattern_recognizer, **model_kwargs)
     32     try:
     33         config = BertABSCConfig.from_pretrained(name, **model_kwargs)
---> 34         model = BertABSClassifier.from_pretrained(name, config=config)
     35         tokenizer = transformers.BertTokenizer.from_pretrained(name)
     36         professor = Professor(reference_recognizer, pattern_recognizer)

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/transformers/modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
   1010   def trainable(self, value):
   1011     self._trainable = value
-> 1012     for layer in getattr(self, '_layers', []):
   1013       layer.trainable = value
   1014 

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/aspect_based_sentiment_analysis/models.py in call(self, token_ids, attention_mask, token_type_ids, training, **bert_kwargs)
    139             **bert_kwargs
    140     ) -> Tuple[tf.Tensor, Tuple[tf.Tensor, ...], Tuple[tf.Tensor, ...]]:
--> 141         outputs = self.bert(
    142             inputs=token_ids,
    143             attention_mask=attention_mask,

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    940             # TODO(fchollet): consider py_func as an alternative, which
    941             # would enable us to run the underlying graph if needed.
--> 942             outputs = self._symbolic_call(inputs)
    943 
    944           if outputs is None:

~/anaconda3/envs/myenv1/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _split_out_first_arg(self, args, kwargs)

ValueError: The first argument to `Layer.call` must always be passed.

Can I know the solution?

AschHarwood commented 3 years ago

I'm having the exact same problem.

mileschandler commented 3 years ago

same issue. bump

mileschandler commented 3 years ago

Note. This is likely a dependency issue @AschHarwood . If you create a conda env using the environment.yml mine works fine.

Nikola1023 commented 3 years ago

Has anyone solved the problem? I have the same issue.

tatiana-norkina commented 3 years ago

the code works if you run in google colab

Schluca commented 3 years ago

I had the same issue. I think it is caused by installing a newer version of transformers (4.6.1) while aspect-based-sentiment-analysis needs 2.5.0. Could also be caused by a different library that is updated by newer versions of transformers.

arditobryan commented 2 years ago

Running in the same issue, (installation for transformers 2.5.0 is also very problematic, so far unable to try this fix)