def extract_context_windows(span, tokens, max_seq_window_len):
    """Extract the left and right context window around a span.

    Args:
        span: span (left and right values)
        tokens: tokens
        max_seq_window_len: maximum window length around a span

    Returns: left context, right context
    """
    # If more tokens to the right, shift weight there
    if span[0] < len(tokens) - span[1]:
        prev_context = tokens[max(0, span[0] - max_seq_window_len // 2) : span[0]]
        next_context = tokens[
            span[1] : span[1] + max_seq_window_len - len(prev_context)
        ]
    else:
        next_context = tokens[span[1] : span[1] + max_seq_window_len // 2]
        prev_context = tokens[
            max(0, span[0] - (max_seq_window_len - len(next_context))) : span[0]
        ]
    return prev_context, next_context