pymc - PyMC3 Simple Topic Model -
i'm trying implement simple topic model in pymc3 , i'm having problem getting sample. i'm pretty sure issue in 'p' function in how i'm trying access 'theta' variable. theta isn't list, don't know how else combine information. appreciated.
import numpy np pymc3 import * import theano.tensor t k = 3 #number of topics v = 20 #number of words n = 15 #number of documents #generaete random categorical mixtures data = np.ones([n,v]) @theano.compile.ops.as_op(itypes=[t.dmatrix, t.lscalar],otypes=[t.dvector]) def p(theta, z_i): return theta[z_i] model = model() model: alpha = np.ones(v) beta = np.ones(k) theta = dirichlet('theta', alpha, shape=(k,v)) phi = dirichlet('phi', beta, shape=k) z = [categorical('z_%i' % i, phi) in range(n)] x = [categorical('x_%i' % (i), p=p(theta,z[i]), observed=data[i]) in range(n)] print "created model. begin sampling" step = metropolis() trace = sample(10000, step) trace.get_values('phi')
the error message i'm getting in above code is:
typeerror: expected type_num 9 (npy_int64) got 7 apply node caused error: scalarfromtensor(inplacedimshuffle{}.0) toposort index: 11 inputs types: [tensortype(int64, scalar)] inputs shapes: [()] inputs strides: [()] inputs values: [array(1)] outputs clients: [[subtensor{int64}(elemwise{truediv}[(0, 0)].0, scalarfromtensor.0)]]
Comments
Post a Comment