Is there any loss function that can measure the similarity between two sequences of different lengths

Is there any loss function that can measure the similarity between two sequences of different lengths?

For example, say hidden1 (B, T1, F) and hidden2 (B, T2, F) are encoded from input1 and input2, respectively, by a transformer encoder.

Assume that input1 and input2 are two speakers saying the same sentence. Due to their different speaking speed, etc., T1 != T2, but since the contents are the same, the encoded hidden1 and hidden2 should thus be (somehow) similar.

I’m wondering whether there exists a loss in PyTorch that can measure such similarities (if the lengths are the same there’re many choices such as MSE, but when the lengths are different?)

Thanks in advance!