explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
30.21k stars 4.4k forks source link

training with custom loss function, or assigning weights to classes #6873

Open fhamborg opened 5 years ago

fhamborg commented 5 years ago

Hi!

Is it possible to define a custom loss function when training spacy's transformers? Specifically, I'm asking because the classes in my dataset are imbalanced, and I'd like to weight each class differently. In pytorch, you could define a weight for each class in various loss functions, such as nn.CrossEntropyLoss(weight=...)

How would that work in spacy-transformers?

Thanks in advance for your answer! :-)

Cheers, Felix

pbakhtin commented 5 years ago

Also want to know this for explosion/spacy-transformers#77