CAPE: Context-Adaptive Positional Encoding for Length Extrapolation