hidden markov models - Learn characters sequences using hmmlearn in Python -


here problem, i'm trying teach hidden markov models using hmmlearn. i'm new language, , have difficulties understand differences between lists , arrays. here code:

from hmmlearn import hmm babel import lists import numpy np import unidecode u numpy import char  l = [] data = [] gods_egypt = ["amon","anat","anouket","anubis","apis","atoum","bastet","bès","gheb","hâpy","harmachis","hathor","heh","héket","horus","isis","ka","khepri","khonsou","khnoum","maât","meresger","mout","nefertoum","neith","nekhbet","nephtys","nout","onouris","osiris","ouadjet","oupaout","ptah","rê","rechef","renenoutet","satet","sebek","sekhmet","selkis","seth","shou","sokaris","tatenen","tefnout","thot","thouéris"] in range(0, len(gods_egypt)):     data.append([])     j in range(0, len(gods_egypt[i])):         data[i].append([u.unidecode(gods_egypt[i][j].lower())])     l.append(len(data[i])) data = np.asarray(data).reshape(-1,1) model = hmm.multinomialhmm(20, verbose=true) model = model.fit(data, l) 

and resulting output

traceback (most recent call last):   file "~~~\hmm_test.py", line 17, in <module>     model = model.fit(data, l)   file "~~~\python\python36\site-packages\hmmlearn\base.py", line 420, in fit     x = check_array(x)   file "~~~\python36-32\lib\site-packages\sklearn\utils\validation.py", line 402, in check_array     array = np.array(array, dtype=dtype, order=order, copy=copy) valueerror: setting array element sequence. 

i have seen @ valueerror: setting array element sequence might problem of different array length, can't figure out how solve it.

any suggestion ?

the error comes fact model.fit() expecting array of arrays of numerical values. right input data array of arrays of list of lists of string. provokes error function finds array element expecting is sequence i.e., list (of lists of strings).

however, if fix list issue, issue arise: learning hmm implies computing numerical quantities via set of equations. input data learn hmm should numerical, not set of letters. (except if hmmlearn has special option characters not aware of.)

you need first transform letters numbers if want work hmms.

i not know end goal is. hmm aimed @ modeling data generation or classification purpose (if several hmms trained). intending once have trained model letters composing words?

as format in data should provided different functions, suggest give @ documentation. includes tutorials use of library.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -