thunlp / Auto_CLIWC

Code for Chinese LIWC Lexicon Expansion via Hierarchical Classification of Word Embeddings with Sememe Attention (AAAI18)
MIT License
145 stars 43 forks source link

UnboundLocalError: local variable 'word' referenced before assignment #5

Closed SeekPoint closed 5 years ago

SeekPoint commented 6 years ago

mldl@ub1604:~/ub16_prj/Auto_CLIWC$ python3 train_liwc.py Traceback (most recent call last): File "train_liwc.py", line 37, in word2sememe_vecs, word2sememe_length, word2average_sememes = load_data.load_hownet(hownet_file, word2type, word2vectors) File "/home/mldl/ub16_prj/Auto_CLIWC/utils/load_data.py", line 83, in load_hownet word2sememes[word].update(m) UnboundLocalError: local variable 'word' referenced before assignment mldl@ub1604:~/ub16_prj/Auto_CLIWC$

SeekPoint commented 6 years ago

I use sogou_news_csv.tar.gz to generates the word vector file

wirehack commented 5 years ago

Not sure why this error occurs, could you provide more information?

SeekPoint commented 5 years ago

明显是代码错误

def load_hownet(filename, word2type, word2vectors, encoding='utf-8'): hownet = open(filename, encoding=encoding) lines = hownet.readlines() re_words = re.compile(u"[\u4e00-\u9fa5]+") word2sememes = defaultdict(set) word2word_semevec = defaultdict(list) for line in lines: if 'W_C=' in line and line[4:].strip() in word2type: word = line[4:].strip() elif 'W_E=' in line and line[4:].strip() in word2type: word = line[4:].strip() elif 'DEF=' in line: m = re_words.findall(line, 0) word2sememes[word].update(m) word2sememes = dict(word2sememes) word2average_sememes = dict() biggest = 40 word2sememe_length = dict()

xp1992slz commented 5 years ago

I have the same error.

az5872 commented 5 years ago
word=lines[0][4:].strip()                    #add this line in load_hownet()

for line in lines: if 'W_C=' in line and line[4:].strip() in word2type: word = line[4:].strip() elif 'W_E=' in line and line[4:].strip() in word2type: word = line[4:].strip() elif 'DEF=' in line: m = re_words.findall(line, 0) word2sememes[word].update(m)

wirehack commented 5 years ago

let me know if the above fix does not work. @az5872 feel free to submit a pull request.