Observations of different size and enumeration

Hi!
I try to build the model, in which i exhaust a sequence of some fixed length in the parts of different sizes. But i have problem with enumeration. Here is my code:

Code
def model_8( data ) :
    hmmdim = 2
    datadim = 3
    mwl = 2
    x_q = pyro.param( "x_q"
                     , torch.eye( hmmdim ) * .1 + .1
                     , constraint=constraints.simplex )
    y_q = torch.zeros( [ hmmdim, datadim ** mwl ] )
    for i in range( mwl ) :
        y_q[i][:datadim ** ( i + 1 )] = .1
    y_q = pyro.param(  "y_q"
                     , y_q
                     , constraint=constraints.simplex )
    x = 0
    k = torch.tensor( 0 )
    for j in pyro.markov( range( len( data ) ) ) :
        x = pyro.sample(  "x_{}".format( j )
                        , dist.Categorical( Vindex( x_q )[..., x, :] )
                        , infer={ "enumerate": "parallel" } )
        if k + x + 1 >= len( data ) :
            break
        obs = torch.tensor( 0, dtype=torch.long )
        for i in range( x + 1 ) :
            obs += datadim ** i * data[k + i]
        pyro.sample( "obs_{}".format(j)
                   , dist.Categorical( Vindex( y_q )[..., x, :] )
                   , obs=obs )
        k += x + 1

I get error: TypeError: only integer tensors of a single element can be converted to an index

The general question is: how can i generate observations of different size dependent on enumerated variable?

Hi @Vanka, could you post some more details of your model?

One way to deal with observations of different size is to use poutine.mask or TorchDistribution.mask() to mask out irrelevant observations.