Performance Optimization for Semantic Communications: An Attention-based Learning Approach