Dynamic Template Selection for Output Token Generation Optimization: MLP-Based and Transformer Approaches