Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError with Tokenizer #36

Open
adriguerra opened this issue Dec 26, 2020 · 3 comments
Open

AttributeError with Tokenizer #36

adriguerra opened this issue Dec 26, 2020 · 3 comments

Comments

@adriguerra
Copy link

adriguerra commented Dec 26, 2020

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
Copy link
Author

adriguerra commented Dec 30, 2020

This fixes the first issue:

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

@pepi99
Copy link

pepi99 commented Mar 2, 2022

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?

@hoangthangta
Copy link

Can you try this?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants