I'm currently training a SpaCy model for multi-label text classification. There are 6 labels: anger, anticipation, disgust, fear, joy, sadness, surprise and trust. The dataset is over 200k. However, per epoch is taking 4 hours. I was wondering if there's a way to optimize the training and do it faster, maybe I'm skipping something here that can improve the model.
TRAINING_DATA
TRAIN_DATA = list(zip(train_texts, [{"cats": cats} for cats in final_train_cats]))
[...
{'cats': {'anger': 1,
'anticipation': 0,
'disgust': 0,
'fear': 0,
'joy': 0,
'sadness': 0,
'surprise': 0,
'trust': 0}}),
('mausoleum',
{'cats': {'anger': 1,
'anticipation': 0,
'disgust': 0,
'fear': 0,
'joy': 0,
'sadness': 0,
'surprise': 0,
'trust': 0}}),
...]
TRAINING
nlp = spacy.load("en_core_web_sm")
category = nlp.create_pipe("textcat", config={"exclusive_classes": True})
nlp.add_pipe(category)
# add label to text classifier
category.add_label("trust")
category.add_label("fear")
category.add_label("disgust")
category.add_label("surprise")
category.add_label("anticipation")
category.add_label("anger")
category.add_label("joy")
optimizer = nlp.begin_training()
losses = {}
for i in range(100):
random.shuffle(TRAIN_DATA)
print('...')
for batch in minibatch(TRAIN_DATA, size=8):
texts = [nlp(text) for text, entities in batch]
annotations = [{"cats": entities} for text, entities in batch]
nlp.update(texts, annotations, sgd=optimizer, losses=losses)
print(i, losses)
...
0 {'parser': 0.0, 'tagger': 27.018985521040854, 'textcat': 0.0, 'ner': 0.0}
...
1 {'parser': 0.0, 'tagger': 27.01898552104131, 'textcat': 0.0, 'ner': 0.0}
...