Closed qingbol closed 4 years ago
I changed the snippet in save_embeddings.py
for i in range(len(ids)):
word_id = ids[i]
word = input_data['id2word'][word_id]
if word != 'UNK':
#word = int(word)
to
for i in range(len(ids)):
word_id = ids[i]
word = input_data['id2word'][word_id]
print "The value of i :{}".format(i)
print "The value of word_id=ids[i] :{}".format(word_id)
print "The value of word = input_data['id2word'][word_id]:{}".format(word)
if word != 'UNK':
word_bytearray=bytearray(word)
word_lst=list(word_bytearray)
word = insn_int.insn2int_inverse(word_lst)
Now the input_data['id2word'][word_id] element can converted to int , but another error occurs: Embed input data loaded Loading int to instruction map... ids[] type: <type 'list'> ids[]: [6769, 36, 50589, 64451, 22725, 60313, 264, 27191, 8528948, 16757054, 37647, 15141316, 60872, 70776, 169799, 59119, 19368, 64195, 48039, 42442] The value of i :0 The value of word_id=ids[i] :6769 The int value of word = input_data['id2word'][word_id]: 512
Int to instruction map loaded Traceback (most recent call last): File "test.py", line 151, in
main() File "test.py", line 123, in main insn = int2insn_map[word] KeyError: 512
That means the way I convert word to int(word) is not right. I don't know how to fix this, pls help.
solved
When i ran save_embeddings.py.
Following error occurs:
In word = int(word) , word= input_data['id2word'][word_id] which is an element in input_data['id2word'] <type 'numpy.ndarray'>.
I printed some related value: The result of
print type(input_data['id2word'])
isThe result of
print (input_data['id2word'][6768:6778])
isThe result of
print (input_data['id2word'])
isSo, when we execute this statement
word = int(word)
it's some thing likeword = int('\x00\x02')
orword = int('\xec\x87\x86\x8c%\xef&C\xe51xS\xf9\xe7]\xfb\xa7\xd8?\x11e\x0e}\x1a\xd0\xae9\xe1\xc5A\xe9)')
which make this error occur:
" ValueError: invalid literal for int() with base 10: ''
how to fix this? what's the purpose of statement
word = int(word)
? Looking forward to your answer @melynx, thank you.