473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2326
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

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

Similar topics

8
by: sam | last post by:
hey everybody, this is my first time posting here. i'm pretty new to python and programming in general (as you'll soon work out for yourselves...) i'm trying to code a version of a selection...
35
by: erikwickstrom | last post by:
Hi all, I'm sorry about the newbie question, but I've been searching all afternoon and can't find the answer! I'm trying to get this bit of code to work without triggering the IndexError. ...
11
by: Steve | last post by:
I'm trying to create a list range of floats and running into problems. I've been trying something like: a = 0.0 b = 10.0 flts = range(a, b) fltlst.append(flts)
7
by: python101 | last post by:
My code s= for k in range(len(s)): st=s.count(s) if st>=2: print s.pop(s.index(s)) Traceback (most recent call last):
1
by: ApoorvaDesai | last post by:
How do I check if a certain column exists in the CSV file, from the following code I try to check if s exists. It gives me an error INDEX ERROR: List index out of range. If its Null I expect it to...
2
by: Georgy Panterov | last post by:
I am a relatively new python user. I am writing an economic simulation of acard-game. The simulation runs fine for a few iteration but then it gives an error of "list index out of range." The...
4
by: Derbylad | last post by:
After starting my coursework I've come across the following error code... "List index out of range". I was expecting this to be something very simple that I've done wrong and still imagine it will be...
2
by: Chriskim | last post by:
I wrote a program that uses PyQt4, mathplotlib to generates graphs. I made a executable file using Py2exe. Everything is working fine, but when I exit from my program, a window message pops...
2
by: Einat | last post by:
Hi all, I'm just starting my way into Python and I'm trying to use a while loop with lists but keep getting the list index out of range error. (Please ignore any other foolish mistakes I might...
1
by: Karen Rosen | last post by:
This is my first program of any sort I am getting this error File "karenrosen5.py", line 162, in <module> record.append(triad("NoReleve",line)) File "karenrosen5.py", line 115, in triad...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.