Title: 🐛[BugFix]fix seqeval
Author: AlongWY (CONTRIBUTOR)
State: closed
Created: 2020-07-08T09:12:12Z

Fix seqeval process labels such as 'B', 'B-ARGM-LOC'

Comments:
I think this is good but can you detail a bit the behavior before and after your fix?

examples:

input: `['B', 'I', 'I', 'O', 'B', 'I']`
before: `[('B', 0, 0), ('I', 1, 2), ('B', 4, 4), ('I', 5, 5)]`
after: `[('_', 0, 2), ('_', 4, 5)]`

input: `['B-ARGM-LOC', 'I-ARGM-LOC', 'I-ARGM-LOC', 'O', 'B-ARGM-TIME', 'I-ARGM-TIME']`
before: `[('LOC', 0, 2), ('TIME', 4, 5)]`
after: `[('ARGM-LOC', 0, 2), ('ARGM-TIME', 4, 5)]`

This is my test code:

```python
from metrics.seqeval.seqeval import end_of_chunk, start_of_chunk


def before_get_entities(seq, suffix=False):
    """Gets entities from sequence.
    Args:
        seq (list): sequence of labels.
    Returns:
        list: list of (chunk_type, chunk_start, chunk_end).
    """
    if any(isinstance(s, list) for s in seq):
        seq = [item for sublist in seq for item in sublist + ['O']]

    prev_tag = 'O'
    prev_type = ''
    begin_offset = 0
    chunks = []
    for i, chunk in enumerate(seq + ['O']):
        if suffix:
            tag = chunk[-1]
            type_ = chunk.split('-')[0]
        else:
            tag = chunk[0]
            type_ = chunk.split('-')[-1]

        if end_of_chunk(prev_tag, tag, prev_type, type_):
            chunks.append((prev_type, begin_offset, i - 1))
        if start_of_chunk(prev_tag, tag, prev_type, type_):
            begin_offset = i
        prev_tag = tag
        prev_type = type_

    return chunks


def after_get_entities(seq, suffix=False):
    """Gets entities from sequence.
    Args:
        seq (list): sequence of labels.
    Returns:
        list: list of (chunk_type, chunk_start, chunk_end).
    """
    if any(isinstance(s, list) for s in seq):
        seq = [item for sublist in seq for item in sublist + ['O']]

    prev_tag = 'O'
    prev_type = ''
    begin_offset = 0
    chunks = []
    for i, chunk in enumerate(seq + ['O']):
        if suffix:
            tag = chunk[-1]
            type_ = chunk[:-1].rsplit('-', maxsplit=1)[0] or '_'
        else:
            tag = chunk[0]
            type_ = chunk[1:].split('-', maxsplit=1)[-1] or '_'

        if end_of_chunk(prev_tag, tag, prev_type, type_):
            chunks.append((prev_type, begin_offset, i - 1))
        if start_of_chunk(prev_tag, tag, prev_type, type_):
            begin_offset = i
        prev_tag = tag
        prev_type = type_

    return chunks


def main():
    examples_1 = ['B', 'I', 'I', 'O', 'B', 'I']
    print(before_get_entities(examples_1))
    print(after_get_entities(examples_1))
    examples_2 = ['B-ARGM-LOC', 'I-ARGM-LOC', 'I-ARGM-LOC', 'O', 'B-ARGM-TIME', 'I-ARGM-TIME']
    print(before_get_entities(examples_2))
    print(after_get_entities(examples_2))


if __name__ == '__main__':
    main()
```

And we can get more examples not correct, such as:

input: `['B', 'I', 'I-I']`
before: `[('B', 0, 0), ('I', 1, 2)]`
after: `[('_', 0, 1), ('I', 2, 2)]`

input: `['B-ARGM-TIME', 'I-ARGM-TIME', 'I-TIME']`
before: `[('TIME', 0, 2)]`
after: `[('ARGM-TIME', 0, 1), ('TIME', 2, 2)]`

I think i didn't break any thing. Maybe the checks should be restart?

Could you please rebase from master @AlongWY ? This should fix the CI stuff

ok, i will do it

Indeed the official repo is quite stale. Let's merge it here, thanks @AlongWY