implement training for sparse encoder