This can be done using a Dirichlet process (DP) prior.
we define the distribution of elementary tree e with root non-terminal symbol c as where P 0 (•|c) (the base distribution) is a distribution over the infinite space of trees rooted with c, and α c (the concentration parameter) controls the model's tendency towards either reusing elementary trees or creating novel ones as each training instance is encountered (and consequently, the tendency to infer larger or smaller sets of elementary trees from the observed data).