How to Estimate Token Count Before Passing Context to Apple’s Foundation Model?

In working with Apple's foundation models, we often want to provide as much context as possible. However, since the model has a context size limit of 4096 tokens, is there a way to estimate the number of tokens beforehand?

How to Estimate Token Count Before Passing Context to Apple’s Foundation Model?
 
 
Q