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

AttributeError with Tokenizer

Open adriguerra opened this issue 4 years ago • 3 comments

I'm trying to reproduce the example in the README.

name = 'absa/classifier-rest-0.2'
model = absa.BertABSClassifier.from_pretrained(name)
tokenizer = absa.BertTokenizer.from_pretrained(name)
professor = absa.Professor()     # Explained in detail later on.
text_splitter = absa.sentencizer()  # The English CNN model from SpaCy.
nlp = absa.Pipeline(model, tokenizer, professor, text_splitter)

But I get an AttributeError with the tokenizer.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-c6e986c7be44> in <module>
      1 name = 'absa/classifier-rest-0.2'
      2 model = absa.BertABSClassifier.from_pretrained(name)
----> 3 tokenizer = absa.BertTokenizer.from_pretrained(name)
      4 professor = absa.Professor()     # Explained in detail later on.
      5 text_splitter = absa.sentencizer()  # The English CNN model from SpaCy.

AttributeError: module 'aspect_based_sentiment_analysis' has no attribute 'BertTokenizer'

Could you also clarify how the professor works. The article is missing the hyperlink in the README: "In the article [here], we discuss in detail how the model and the professor work"

Thanks in advance.

adriguerra avatar Dec 26 '20 18:12 adriguerra

This fixes the first issue:

from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained(model_name)

adriguerra avatar Dec 30 '20 11:12 adriguerra

Thank you for your solution. Now I get another error:

Traceback (most recent call last): File "/Users/petar.ulev/Documents/prepare_sentiment_data/spacystuff.py", line 29, in task = nlp.preprocess(text=text, aspects=aspects) File "/Users/petar.ulev/Documents/prepare_sentiment_data/venv/lib/python3.8/site-packages/aspect_based_sentiment_analysis/pipelines.py", line 213, in preprocess spans = self.text_splitter(text) if self.text_splitter else [text] File "/Users/petar.ulev/Documents/prepare_sentiment_data/venv/lib/python3.8/site-packages/aspect_based_sentiment_analysis/text_splitters.py", line 17, in wrapper sentences = [sent.string.strip() for sent in doc.sents] File "/Users/petar.ulev/Documents/prepare_sentiment_data/venv/lib/python3.8/site-packages/aspect_based_sentiment_analysis/text_splitters.py", line 17, in sentences = [sent.string.strip() for sent in doc.sents] AttributeError: 'spacy.tokens.span.Span' object has no attribute 'string'

Did you experience it as well?

pepi99 avatar Mar 02 '22 08:03 pepi99

Can you try this?

sentences = [sent.text.strip() for sent in doc.sents]

hoangthangta avatar Feb 09 '23 05:02 hoangthangta