Why are metrics in AllenNLP calculated with tensors? Can I define a metric based on strings?

33 views Asked by At

I'm using AllenNLP in my project, and I'm confused by the Metric: all of the metrics are calculated with tensors, include bleu and rouge. However sometime I may want to calculate the metric with strings tokenized with white spaces. The built-in metrics are calculated in a token level tokenized by BertTokenizer, and it may have a different result because of the difference of tokenization.

Currently I'm converting the tensor to tokens, putting them into a string and calculate my defined Metric in forward. The code is working now, but I wonder this may not be the right way.

1

There are 1 answers

0
Глеб Гутник On

What does not seem to be exactly the AllenNLP way of calculating metrics is getting them in the forward call. AllenNLP train_loop features a special blueprint function get_metrics for this.

However, if you mean that you update your metrics in forward and reset them in get_metrics, there seems to be no better way to do it.