AttributeError: 'SequenceTagger' object has no attribute 'tag_dictionary'
Manikanth06 opened this issue · 5 comments
--CODE--
...
self.step, self.epoch = 0, 0
self.valid_loss = float('inf')
self.valid_log = ['Start Time: {}'.format(self.start_time)]
self.ref_test_log = self.valid_log.copy()
self.asr_test_log = self.valid_log.copy()
# language model tokenizer
if self.config.lan_model:
self.tokenizer = AutoTokenizer.from_pretrained(self.config.lan_model)
if self.config.pos:
self.pos_tagger = SequenceTagger.load(self.config.pos) if self.config.pos else None
if self.config.use_pos:
self.config.tag_size = len(self.pos_tagger.tag_dictionary) if self.pos_tagger else None
if self.config.pretrained_pos_embed:
self.config.embedding_size = self.pos_tagger.linear.weight.shape[-1]
def load_data(self):
for file in [self.config.TRAIN_FILE, self.config.VALID_FILE
, self.config.REF_TEST_FILE, self.config.ASR_TEST_FILE]:
if not os.path.exists(self.config.DATA_JSON.format(file)):
raw_file = self.config.RAW_TXT.format(file)
raw_data = pipeline.read_file(raw_file, self.config)
raw_data = pipeline.parse_data(raw_data, self.tokenizer, self.config)
save.save_json(self.config.DATA_JSON.format(file), raw_data)
...
->I am using this part of code in train.py same as in your github repository, but I am getting error due to tag_dictionary attribute as
shown below
--ERROR--
(AttributeError: 'SequenceTagger' object has no attribute 'tag_dictionary')
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
PS C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main> cd main
PS C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main> python .\train.py
Initialize...
2022-06-07 18:26:15,095 loading file C:\Users\Manikanth Shetty.flair\models\upos-english-fast\b631371788604e95f27b6567fe7220e4a7e8d03201f3d862e6204dbf90f9f164.0afb95b43b32509bf4fcc3687f7c64157d8880d08f813124c1bd371c3d8ee3f7
2022-06-07 18:26:15,455 SequenceTagger predicts: Dictionary with 20 tags: , O, INTJ, PUNCT, VERB, PRON, NOUN, ADV, DET, ADJ, ADP, NUM, PROPN, CCONJ, PART, AUX, X, SYM, ,
Traceback (most recent call last):
File "C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main\train.py", line 483, in
main()
File "C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main\train.py", line 478, in main
re = Restorer()
File "C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main\train.py", line 28, in init
self.initialize()
File "C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main\train.py", line 57, in initialize
self.config.tag_size = len(self.pos_tagger.tag_dictionary) if self.pos_tagger else None
File "C:\Users\Manikanth Shetty\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1185, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'SequenceTagger' object has no attribute 'tag_dictionary'
PS C:\Users\Manikanth Shetty\OneDrive\Documents\POS-Tagger-for-Punctuation-Restoration-main\main>
-> please help me with this.
HI @Manikanth06,
Could please check whether the environment (e.g., library version) aligns with the requirements.txt?
- flair==0.8
- scikit_learn==0.24.1
- torch==1.7.1
- tqdm==4.57.0
- transformers==4.3.2
- jupyterlab==3.1.4
- ipywidgets==7.6.3
Also, try to print it out if you think the attribute 'tag_dictionary' is actually defined.
Hi @MrShininnnnn ,
I tried to install flair version 0.8, but got genism error therefore I installed all packages of the latest version ,
Note: I opened the SeqenceTagger class in flair module and it has the tag_dictionary attribute in its definition.
@Manikanth06,
I think we find a potential problem. The version of flair should be 0.8 rather than the latest one. Otherwise, it is needed to revise our code accordingly to adapt to the latest version.
Although the SeqenceTagger has tag_dictionary attribute in its definition, it does not necessarily mean that it does have it in the application, especially when the version is not the same. I think you will get a "no such attribute" error if you try to print it out.
One solution is to run the code in an independent virtual environment like miniconda to avoid the genism error.
@MrShininnnnn ,
Thank you for your suggestion I wiil try this one.
Solved.