Update default textcat arch, and add debug method
@@ -28,6 +28,21 @@ class PyTT_TextCategorizer(spacy.pipeline.TextCategorizer):
RETURNS (thinc.neural.Model): The model.
"""
make_model = get_model_function(
- cfg.get("architecture", "fine_tune_class_vector")
+ cfg.get("architecture", "softmax_class_vector")
)
return make_model(nr_class, exclusive_classes=exclusive_classes, **cfg)
+
+ def get_loss(self, docs, golds, scores):
+ # This is a useful diagnostic while figuring out whether your model is
+ # learning anything. We print the loss each batch, and also the
+ # mean and variance for the score of the first class.
+ # If the model is learning things, we want to see the mean score stay
+ # close the the class distribution (e.g. 0.5 for balanced classes),
+ # while the variance in scores should increase (i.e. different examples
+ # should get different scores).
+ loss, d_scores = super().get_loss(docs, golds, scores)
+ mean_score = scores.mean(axis=0)[0]
+ var_score = scores.var(axis=0)[0]
+ #print("L", "%.4f" % loss, "m", "%.3f" % mean_score, "v", "%.6f" % var_score)
+ return loss, d_scores
+
