Hi @junpenglao, that’s precisely what I’m doing:

```
# Create shared variables. Use these to initialize model
model_variables = {}
# Nominal Predictors of model
for predictor in encoders:
encoder = encoders[predictor]
model_variables[predictor] = shared(encoder.transform(train[predictor]))
model_variables['y_obs'] = shared(train.y.values)
model_variables['n'] = shared(train.n.values)
# Create minibatch variables
batch_size = 2000
random_seed = 42
minibatch_variables = {}
# Nominal Predictors of model
for predictor in encoders:
encoder = encoders[predictor]
minibatch_variables[predictor] = pm.Minibatch(
encoder.transform(train[predictor]), batch_size=batch_size
)
minibatch_variables['y_obs'] = pm.Minibatch(train.y.values, batch_size=batch_size)
minibatch_variables['n'] = pm.Minibatch(train.n.values, batch_size=batch_size)
# Replacements to be used for training
minibatch_replacements = {model_variables[key]: minibatch_variables[key] for key in model_variables}
model = construct_model(model_variables, encoders, train.y.values.size)
with model:
n = 5000
advifit = pm.fit(
n, callbacks=[pm.callbacks.CheckParametersConvergence(tolerance=1e-4)],
more_replacements=minibatch_replacements
)
```

which is giving the following TraceBack:

ValueError Traceback (most recent call last)

/anaconda/envs/numerical/lib/python3.6/site-packages/theano/compile/function_module.py in **call**(self, *args, **kwargs)

883 outputs =

–> 884 self.fn() if output_subset is None else

885 self.fn(output_subset=output_subset)

ValueError: Input dimension mis-match. (input[0].shape[0] = 85054, input[3].shape[0] = 2000)

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in ()

3 advifit = pm.fit(

4 n, callbacks=[pm.callbacks.CheckParametersConvergence(tolerance=1e-4)],

----> 5 more_replacements=minibatch_replacements

6 )

/anaconda/envs/numerical/lib/python3.6/site-packages/pymc3/variational/inference.py in fit(n, local_rv, method, model, random_seed, start, inf_kwargs, **kwargs)

754 ‘or Inference instance’ %

755 set(_select.keys()))

–> 756 return inference.fit(n, **kwargs)

/anaconda/envs/numerical/lib/python3.6/site-packages/pymc3/variational/inference.py in fit(self, n, score, callbacks, progressbar, **kwargs)

133 with tqdm.trange(n, disable=not progressbar) as progress:

134 if score:

–> 135 state = self._iterate_with_loss(0, n, step_func, progress, callbacks)

136 else:

137 state = self._iterate_without_loss(0, n, step_func, progress, callbacks)

/anaconda/envs/numerical/lib/python3.6/site-packages/pymc3/variational/inference.py in _iterate_with_loss(self, s, n, step_func, progress, callbacks)

175 try:

176 for i in progress:

–> 177 e = step_func()

178 if np.isnan(e): # pragma: no cover

179 scores = scores[:i]

/anaconda/envs/numerical/lib/python3.6/site-packages/theano/compile/function_module.py in **call**(self, *args, **kwargs)

896 node=self.fn.nodes[self.fn.position_of_error],

897 thunk=thunk,

–> 898 storage_map=getattr(self.fn, ‘storage_map’, None))

899 else:

900 # old-style linkers raise their own exceptions

/anaconda/envs/numerical/lib/python3.6/site-packages/theano/gof/link.py in raise_with_op(node, thunk, exc_info, storage_map)

323 # extra long error message in that case.

324 pass

–> 325 reraise(exc_type, exc_value, exc_trace)

326

327

/anaconda/envs/numerical/lib/python3.6/site-packages/six.py in reraise(tp, value, tb)

690 value = tp()

691 if value.**traceback** is not tb:

–> 692 raise value.with_traceback(tb)

693 raise value

694 finally:

/anaconda/envs/numerical/lib/python3.6/site-packages/theano/compile/function_module.py in **call**(self, *args, **kwargs)

882 try:

883 outputs =

–> 884 self.fn() if output_subset is None else

885 self.fn(output_subset=output_subset)

886 except Exception:

ValueError: Input dimension mis-match. (input[0].shape[0] = 85054, input[3].shape[0] = 2000)