Implement kl_divergence_filter(reference_freq, documents, threshold), which flags documents whose token distribution diverges from a reference corpus. reference_freq maps token to count in a clean corpus; documents is a list of documents, each a list of tokens.
For a document with tokens, let be the set of distinct tokens in (only those, not the reference vocabulary), and for define:
An empty document has divergence 0.0. A document is flagged if its unrounded divergence is strictly greater than threshold.
Return a dict with keys:
'kl_divergences': list of floats, one per document, each rounded to 4 decimals'flagged': list of bools'kept': the unflagged documents, in original order