469,337 Members | 5,939 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

List Index out of range in Recurrent Nural Network

I have not too much experience in python. Here goes my problem. I am writing the code for recurrent neural network in order to recognize words given as .xml file and search in the dictionary which word .xml file conatins.
For this task I have initially defined labels of characters, then read the lines in .xml file and then try to figure out which word it contains, but here it shows List Index out of range error.

labels contain the characters
Expand|Select|Wrap|Line Numbers
  1. from optparse import OptionParser
  2. import sys
  3. import os
  4. from xml.dom.minidom import parse
  5.  
  6. labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g','ga', 'h', 'i', 'j', 'k', 'km', 'l', 'm', 'n', 'o', 'p', 'pt','q','r','s','sc','sp','t','u','v','w','x','y','z']
I have some words defined in dictionary and some .xml files which I have to train by using dictionary words. But the problem I am suffering now is how can I search a word (by taking .xml file and explore it which word it contains, and search against it in a dictionary).

Expand|Select|Wrap|Line Numbers
  1. inputFilename = args [0]
  2. ncFilename = args[1]
  3. print options
  4. print "input filename", inputFilename
  5. print "data filename", ncFilename
  6. seqDims = []
  7. seqLengths = []
  8. targetStrings = []
  9. wordTargetStrings = []
  10. seqTags = []
  11. inputs = []
  12. print "reading data files"
  13. for l in file(inputFilename).readlines():
  14.     xmlfile = l.strip()
  15.     if len(xmlfile):
  16.         print xmlfile
  17.         seqTags.append(xmlfile)
  18.         if os.path.exists(xmlfile):
  19.             word = parse(xmlfile).getElementsByTagName('hwData')[0].getElementsByTagName('label')[0].getElementsByTagName('alternate')[0].getAttribute('value').strip().replace(' ','*')
  20.             print 'WORD',word
  21.             wts = word.encode('unicode_escape')
  22.             print "WTS",wts
  23.             wordTargetStrings.append(wts)    
  24.             ts = ""
  25.             for c in word:
  26.                 label = c.encode('unicode_escape')
  27.                 ts += label + ' '
  28.             ts = ts.strip()
  29.             print ts
  30.             targetStrings.append(ts)
  31.         else:
  32.             wordTargetStrings.append(' ')
  33.             targetStrings.append(' ')            
  34.         oldlen = len(inputs)
  35.         for trace in parse(xmlfile).getElementsByTagName('trace'):        
  36.             for coords in trace.firstChild.nodeValue.split(','):
  37.                 pt = coords.split()
  38.                 inputs.append([float(pt[0]), float(pt[1]), 0.0])
  39.             inputs[-1][-1] = 1
  40.         seqLengths.append(len(inputs) - oldlen)
  41.         seqDims.append([seqLengths[-1]])

When I execute this code it shows me the following error

word = parse(xmlfile).getElementsByTagName('hwData')[0].getElementsByTagName('label')[0].getElementsByTagName('alternate')[0].getAttribute('value').strip().replace(' ','*')
IndexError: list index out of range

Any Suggestions.....
Jul 17 '11 #1
1 2163
bvdet
2,851 Expert Mod 2GB
The problem is one of the calls to getElementsByTagName is returning an empty list, as in:
Expand|Select|Wrap|Line Numbers
  1. >>> s = []
  2. >>> s[0]
  3. Traceback (most recent call last):
  4.   File "<interactive input>", line 1, in ?
  5. IndexError: list index out of range
  6. >>> 
Jul 17 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by sam | last post: by
35 posts views Thread by erikwickstrom | last post: by
11 posts views Thread by Steve | last post: by
2 posts views Thread by Georgy Panterov | last post: by
4 posts views Thread by Derbylad | last post: by
2 posts views Thread by Einat | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.