Repository: flairNLP/flair

Issue:
ModelTrainer's training on SequenceTagger raises an `AssertionError: `
**Describe the bug**
I am unable to Train a `SequenceTagger` model using the `ModelTrainer` API. This was upon my attempt to train a NER Tagger. The `AssertionError` is raised after the completion of the first epoch.

**To Reproduce**
The format of my NER data is:
```
jina O
langu O
ni O
Kevin B-PERSON
...
```

So I set up the Training sequence this way
```
from flair.data import Corpus
from flair.datasets import ColumnCorpus
from flair.embeddings import StackedEmbeddings, CharacterEmbeddings, FlairEmbeddings

TAG_TYPE = 'ner'
corpus: Corpus = ColumnCorpus('./ner_data', {0: 'text', 1: 'ner'})

# Setup the sequence tagger
from flair.models import SequenceTagger

tagger: SequenceTagger = SequenceTagger(hidden_size=256,
                                        embeddings=embeddings,
                                        tag_dictionary=corpus.make_label_dictionary(label_type=TAG_TYPE),# ... from corpus
                                        tag_type=TAG_TYPE,
                                        use_crf=True)


# Setup the training process
from flair.trainers import ModelTrainer

trainer: ModelTrainer = ModelTrainer(tagger, corpus)

trainer.train('./resource/taggers/swahili-ner',
              learning_rate=0.1,
              mini_batch_size=32)

# intializing the embeddings
embeddings: StackedEmbeddings = StackedEmbeddings([CharacterEmbeddings(),
                                                   FlairEmbeddings('./best-lm.pt')])
```

This was the output from my training:
```
...
2020-04-30 14:36:40,370 epoch 1 - iter 96/120 - loss 209973.64290365 - samples/sec: 33.04
2020-04-30 14:36:52,323 epoch 1 - iter 108/120 - loss 208670.76244213 - samples/sec: 32.17
2020-04-30 14:37:03,579 epoch 1 - iter 120/120 - loss 206854.72747396 - samples/sec: 34.17
2020-04-30 14:37:03,594 ----------------------------------------------------------------------------------------------------
2020-04-30 14:37:03,594 EPOCH 1 done: loss 206854.7275 - lr 0.1000000
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-18-67e2f7ae9c06> in <module>()
     15 trainer.train('./resource/taggers/swahili-dumb-ner',
     16               learning_rate=0.1,
---> 17               mini_batch_size=32)
     18 
     19 # Plotting the performance graphs

3 frames
/usr/local/lib/python3.6/dist-packages/flair/models/sequence_tagger_model.py in _viterbi_decode(self, feats, transitions, all_scores)
    754 
    755         start = best_path.pop()
--> 756         assert start == id_start
    757         best_path.reverse()
    758 

AssertionError: 
```

**Expected behavior**
Training of the model to the default `100` epochs

**Environment (please complete the following information):**
I used this in colab for this

How i installed the packages:
```
!pip install torch==1.4.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
!pip install --upgrade git+https://github.com/flairNLP/flair.git
```


Discussion:
Hm strange, this seems to happen when evaluating the dev data after the first epoch. Can you verify that the dev data is formatted correctly?
The output of the `dev.txt` is also in that format. It begins as
```
kamati	B-ORG
inashauri	O
mara	O
baada	O
ya	O
```

I think it's in the right format
Could you prepare a minimum example to reproduce this error? I.e. a minimal corpus with train dev and test files that throws this error if we train with the above script?
Here is the sample of the data that under went `train`, `dev`, `test` split
[sample-traning-ner-data-sw.txt](https://github.com/flairNLP/flair/files/4566457/sample-traning-ner-data-sw.txt)


Resolving patch:
diff --git a/flair/models/sequence_tagger_model.py b/flair/models/sequence_tagger_model.py
--- a/flair/models/sequence_tagger_model.py
+++ b/flair/models/sequence_tagger_model.py
@@ -112,6 +112,11 @@ def __init__(
 
         # set the dictionaries
         self.tag_dictionary: Dictionary = tag_dictionary
+        # if we use a CRF, we must add special START and STOP tags to the dictionary
+        if use_crf:
+            self.tag_dictionary.add_item(START_TAG)
+            self.tag_dictionary.add_item(STOP_TAG)
+
         self.tag_type: str = tag_type
         self.tagset_size: int = len(tag_dictionary)
 


Test patch: