1. A data coding apparatus containing a template generating means that is composed by; a database means that stores template information together with the attribute parameters of the data, a looking up means to look up template information in said database means using said attribute parameters as looking up keys, a deciding means that decides whether optimization should be carried out or not by estimating capability of the template that is obtained as the output of said looking up means, a template optimizing means that generates the optimum template by using an optimization method that uses one or both of the code compression rate and the entropy as an estimation function and a registering means that registers the template information that is outputted from said template optimizing means to said database means.