yangheng95 / PyABSA

Sentiment Analysis, Text Classification, Text Augmentation, Text Adversarial defense, etc.;
https://pyabsa.readthedocs.io
MIT License
956 stars 160 forks source link

ImportError: cannot import name 'AspectExtractor' from partially initialized module 'pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor' (most likely due to a circular import) (/Applications/anaconda3/lib/python3.10/site-packages/pyabsa/tasks/AspectTermExtraction/prediction/aspect_extractor.py) #361

Open kotrasre opened 1 year ago

kotrasre commented 1 year ago

Please provide the REQUIRED information. Otherwise, It is almost impossible to locate the problem. DO NOT CHANGE THE FORM.

PyABSA Version (Required)

Python Version: Python 3.10.9
PyABSA Version: pyabsa==2.3.4
Torch Version: pytorch-warmup==0.1.1
torch==2.1.0
Transformers Version: transformers==4.35.0
Other: 

See the console output for PyABSA, Torch, Transformers Version

ABSADataset Version (Required if you use integrated datasets)

See the console output for ABSADataset Version

Code To Reproduce (Required)

Paste buggy code here, **text-only, no screen shots here

Full Console Output (Required)

The full console output, **text-only, no screen shots here

Describe the bug

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[6], line 1
----> 1 from pyabsa import ATEPCCheckpointManager
      3 aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='english',
      4                                    auto_device=True  # False means load model on CPU
      5                                    )

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/__init__.py:13
      9 __name__ = "pyabsa"
     10 __version__ = "2.3.4"
---> 13 from pyabsa.utils.notification_utils.notification_utils import (
     14     check_emergency_notification,
     15 )
     17 check_emergency_notification()
     19 from pyabsa.framework.flag_class import *

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/utils/__init__.py:9
      1 # -*- coding: utf-8 -*-
      2 # file: __init__.py
      3 # time: 2021/6/5 0005
      4 # author: YANG, HENG <hy345@exeter.ac.uk> (杨恒)
      5 # github: https://github.com/yangheng95
      6 # Copyright (C) 2021. All Rights Reserved.
      8 from pyabsa.utils.data_utils.dataset_item import DatasetItem
----> 9 from pyabsa.utils.absa_utils.make_absa_dataset import make_ABSA_dataset
     10 from pyabsa.utils.absa_utils.absa_utils import (
     11     generate_inference_set_for_apc,
     12     convert_apc_set_to_atepc_set,
     13 )
     15 from pyabsa.utils.text_utils.word2vec import train_word2vec

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/utils/absa_utils/make_absa_dataset.py:18
     14 from termcolor import colored
     16 from pyabsa.framework.flag_class.flag_template import LabelPaddingOption
---> 18 from pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor import (
     19     AspectExtractor,
     20 )
     21 from pyabsa.utils.pyabsa_utils import fprint
     24 def make_ABSA_dataset(dataset_name_or_path, checkpoint="english"):

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/tasks/AspectTermExtraction/prediction/aspect_extractor.py:32
     30 from pyabsa.utils.data_utils.dataset_manager import detect_infer_dataset
     31 from pyabsa.utils.pyabsa_utils import set_device, print_args, fprint
---> 32 from ..dataset_utils.__lcf__.atepc_utils import (
     33     load_atepc_inference_datasets,
     34     process_iob_tags,
     35 )
     36 from ..dataset_utils.__lcf__.data_utils_for_inference import (
     37     ATEPCProcessor,
     38     convert_ate_examples_to_features,
     39     convert_apc_examples_to_features,
     40 )
     41 from ..dataset_utils.__lcf__.data_utils_for_training import split_aspect

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/tasks/AspectTermExtraction/__init__.py:11
      1 # -*- coding: utf-8 -*-
      2 # file: __init__.py
      3 # time: 02/11/2022 15:13
   (...)
      9 
     10 # for Aspect-term Extraction and Sentiment Classification
---> 11 from .trainer.atepc_trainer import ATEPCTrainer
     12 from .configuration.atepc_configuration import ATEPCConfigManager
     13 from .models import ATEPCModelList

File /Applications/anaconda3/lib/python3.10/site-packages/pyabsa/tasks/AspectTermExtraction/trainer/atepc_trainer.py:19
     12 from pyabsa.framework.flag_class import (
     13     DeviceTypeOption,
     14     ModelSaveOption,
     15     TaskCodeOption,
     16     TaskNameOption,
     17 )
     18 from ..configuration.atepc_configuration import ATEPCConfigManager
---> 19 from ..prediction.aspect_extractor import AspectExtractor
     20 from ..instructor.atepc_instructor import ATEPCTrainingInstructor
     21 from pyabsa.framework.trainer_class.trainer_template import Trainer

ImportError: cannot import name 'AspectExtractor' from partially initialized module 'pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor' (most likely due to a circular import) (/Applications/anaconda3/lib/python3.10/site-packages/pyabsa/tasks/AspectTermExtraction/prediction/aspect_extractor.py)

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

In addition to REQUIRED text information, you can add screenshots to help explain your problem.
yangheng95 commented 1 year ago

Please paste the main code to reproduce, including the main entrance of your code @kotrasre