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

AspectExtractor returns aspects only if pred_sentiments=True in extract_aspect method but I don't want sentiments #386

Closed
KadriMufti opened this issue Feb 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@KadriMufti
Copy link

Version
See the console output for PyABSA, Torch, Transformers Version

Describe the bug
The problem is that I should be able to set the parameter pred_sentiment=False in extract_aspect method and get back aspects without sentiments, but instead I get no aspects.

Code To Reproduce

from pyabsa.tasks import AspectTermExtraction

aspect_extractor = AspectTermExtraction.AspectExtractor(checkpoint = 'path/to/checkpoints/ATEPC_MULTILINGUAL_CHECKPOINT',
                                    auto_device = False  # False means load model on CPU
                                    )

examples = ['The staff was so perfect to us, but the service was bad.']

atepc_result = aspect_extractor.extract_aspect(inference_source=examples,  #
                          save_result=True,
                          print_result=True,  # print the result
                          pred_sentiment=False,  # Predict the sentiment of extracted aspect terms
                          )

print(atepc_result)

Expected behavior

with pred_sentiment=True, the output of the above example is:

[{'sentence': 'The staff was so perfect to us , but the service was bad .',
  'IOB': ['O', 'B-ASP', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-ASP', 'O', 'O', 'O'], 'tokens': ['The', 'staff', 'was', 'so', 'perfect', 'to', 'us', ',', 'but', 'the', 'service', 'was', 'bad', '.'],  'aspect': ['staff', 'service'],  'position': [[1], [10]],   'sentiment': ['Positive', 'Negative'],  'probs': [0.0036869419272989035, 0.001312303589656949, 0.9950007796287537],  [0.995452344417572, 0.0023385591339319944, 0.00220911274664104]], 'confidence': [0.995, 0.9955]}]

with pred_sentiment=False, the output of the above example is:

[{'sentence': 'The staff was so perfect to us , but the service was bad .',
  'IOB': ['O', 'B-ASP', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-ASP', 'O', 'O', 'O'], 'tokens': ['The', 'staff', 'was', 'so', 'perfect', 'to', 'us', ',', 'but', 'the', 'service', 'was', 'bad', '.'], 'aspect': [], 'position': [], 'sentiment': [], 'probs': [], 'confidence': []}]

I am not sure where the problem is, but it might have to do with the extract function _extract() in line 372 in aspect_extractor.py

@KadriMufti KadriMufti added the bug Something isn't working label Feb 20, 2024
@yangheng95
Copy link
Owner

Bug report received, pending fixing

@yangheng95
Copy link
Owner

Can you try 2.4.1 and report the result? @KadriMufti

@KadriMufti
Copy link
Author

I installed pyabsa version 2.4.1 and torch version 1.13.1 and transformers version 4.27.2

There is no change in results. Aspects are still empty when pred_sentiment=False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants