Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code:- 
#convert predictions into text (english)
preds_text = []
for i in preds:
  temp = []
  for j in range(len(i)):
    t=get_word(i[j], eng_tokenizer)
    if j>0:
      if (t == get_word(i[j-1], eng_tokenizer)) or (t== None):
        temp.append('')
      else:
        temp.append(t)
          
    else:
      if(t==None):
        temp.append('')
      else:
        temp.append(t)

        preds_text.append(''.join(temp))
-----------------------------------------------------------------------
Error-

ValueError  Traceback (most recent call last)
<ipython-input-71-9591a77fdabd> in <module>()
      4   temp = []
      5   for j in range(len(i)):
----> 6     t=get_word(i[j], eng_tokenizer)
      7     if j>0:
      8       if (t == get_word(i[j-1], eng_tokenizer)) or (t== None):

<ipython-input-68-55520b29e489> in get_word(n, tokenizer)
      1 def get_word(n, tokenizer):
      2   for word, index in tokenizer.word_index.items():
----> 3     if index == n:
      4       return word
      5       return None

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()


What I have tried:

I have used a.any() or a.all() but it didn't work
Posted
Comments
M Imran Ansari 6-Feb-22 3:11am    
Kindly improve your question on clicking green button 'Improve question' and give what you have in 'preds' collection and also mentioned the others parameters value.
Richard MacCutchan 6-Feb-22 4:14am    
The error message implies that index is an array rather than a single value. So you need to check what is returned by the call to tokenizer.word_index.items().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900