Aspect-Based-Sentiment-Analysis icon indicating copy to clipboard operation
Aspect-Based-Sentiment-Analysis copied to clipboard

AM getting Error when I try to run the First code in the readme

Open ManimozhiSathish opened this issue 4 years ago • 1 comments


ValueError Traceback (most recent call last) in 1 recognizer = absa.aux_models.BasicPatternRecognizer() ----> 2 nlp = absa.load('absa/classifier-rest-0.2',pattern_recognizer=recognizer) 3 text=('We are great fans of Slack, but we wish the subscriptions') 4 completed_task = nlp(text, aspects=['slack', 'price']) 5 slack, price = completed_task.examples

~\Anaconda3\envs\ABSA\lib\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\ABSA\lib\site-packages\transformers\modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 728 return load_pytorch_checkpoint_in_tf2_model(model, resolved_archive_file, allow_missing_keys=True) 729 --> 730 model(model.dummy_inputs, training=False) # build the network with dummy inputs 731 732 assert os.path.isfile(resolved_archive_file), "Error retrieving file {}".format(resolved_archive_file)

~\Anaconda3\envs\ABSA\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in call(self, *args, **kwargs) 983 984 with ops.enable_auto_cast_variables(self._compute_dtype_object): --> 985 outputs = call_fn(inputs, *args, **kwargs) 986 987 if self._activity_regularizer:

~\Anaconda3\envs\ABSA\lib\site-packages\aspect_based_sentiment_analysis\models.py in call(self, token_ids, attention_mask, token_type_ids, training, **bert_kwargs) 148 sequence_output, pooled_output, hidden_states, attentions = outputs 149 pooled_output = self.dropout(pooled_output, training=training) --> 150 logits = self.classifier(pooled_output) 151 return logits, hidden_states, attentions

~\Anaconda3\envs\ABSA\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in call(self, *args, **kwargs) 980 with ops.name_scope_v2(name_scope): 981 if not self.built: --> 982 self._maybe_build(inputs) 983 984 with ops.enable_auto_cast_variables(self._compute_dtype_object):

~\Anaconda3\envs\ABSA\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _maybe_build(self, inputs) 2615 # Check input assumptions set before layer building, e.g. input rank. 2616 if not self.built: -> 2617 input_spec.assert_input_compatibility( 2618 self.input_spec, inputs, self.name) 2619 input_list = nest.flatten(inputs)

~\Anaconda3\envs\ABSA\lib\site-packages\tensorflow\python\keras\engine\input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name) 189 ndim = x.shape.ndims 190 if ndim is not None and ndim < spec.min_ndim: --> 191 raise ValueError('Input ' + str(input_index) + ' of layer ' + 192 layer_name + ' is incompatible with the layer: ' 193 ': expected min_ndim=' + str(spec.min_ndim) +

ValueError: Input 0 of layer classifier is incompatible with the layer: : expected min_ndim=2, found ndim=0. Full shape received: []

and here is my code: Am not sure enough where I am wrong

import aspect_based_sentiment_analysis as absa recognizer = absa.aux_models.BasicPatternRecognizer() nlp = absa.load('absa/classifier-rest-0.2',pattern_recognizer=recognizer) text=('We are great fans of Slack, but we wish the subscriptions') completed_task = nlp(text, aspects=['slack', 'price']) slack, price = completed_task.examples ​

ManimozhiSathish avatar Jan 07 '21 14:01 ManimozhiSathish

Running this code from the readme is working using Python 3.8.8 64-bit with updates as needed to dependencies:

import aspect_based_sentiment_analysis as absa

nlp = absa.load() text = ("We are great fans of Slack, but we wish the subscriptions " "were more accessible to small startups.")

slack, price = nlp(text, aspects=['slack', 'price']) assert price.sentiment == absa.Sentiment.negative assert slack.sentiment == absa.Sentiment.positive

rspiewak47 avatar Aug 26 '21 17:08 rspiewak47