Closed SeekPoint closed 5 years ago
I use sogou_news_csv.tar.gz to generates the word vector file
Not sure why this error occurs, could you provide more information?
明显是代码错误
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()
I have the same error.
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)
let me know if the above fix does not work. @az5872 feel free to submit a pull request.
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$