What does the interleave_keys() function in torchtext library do exactly?
You can find this function at torchtext/data/utils.py file

I have given the official code with documentation below

def interleave_keys(a, b):
    """Interleave bits from two sort keys to form a joint sort key.

    Examples that are similar in both of the provided keys will have similar
    values for the key defined by this function. Useful for tasks with two
    text fields like machine translation or natural language inference.
    """
    def interleave(args):
        return ''.join([x for t in zip(*args) for x in t])
    return int(''.join(interleave(format(x, '016b') for x in (a, b))), base=2)


A more detailed explanation would be helpful to understand how it returns an integer based on how similar the given two strings are.

And the format function used inside it is the commonly used builtin function in python

So upon breaking down the function I was able to figure out what this function is doing.

format(x, '016b') This piece of code converts the integer (a and b which is actually no of words in the sentences in my case) to 16 digit binary number.

And the interleave function takes out the pairs (of the same position) of binary representations join them like this,

For easy understanding lets assume 4 digit binary for 2 and 11

2's binary representation is  : 0 0 1 0

11's binary representation is: 1 0 1 1

So the output here would be 01001101 (01,00,11,01 has been combined) which when converting to integer will give 77
