import torch


def extract_lstm_minus_feature(hidden_state, i, j):
    """
    Extract span representation using lstm-minus feature,
    
    Args:
        hidden_state: Length * Batch * Hidden_size
        i, j: start and end pos, note that i, j is the 
        real index of words, discarding bos and eos:
        ... i, [i+1, ... , j+1], j+2, ...
    """
    seq_len, bs, hidden_size = hidden_state.size()
    assert hidden_size % 2 == 0
    split_point = hidden_size // 2
    hidden_f = hidden_state[j + 1, :, :split_point] - hidden_state[i, :, :split_point]
    hidden_b = (
        hidden_state[i + 1, :, split_point:] - hidden_state[j + 2, :, split_point:]
    )
    span_v = torch.cat([hidden_f, hidden_b], dim=-1)
    return span_v