import torch


def symmetrize_potts(weight: torch.Tensor) -> torch.Tensor:
    """Symmetrize 4D Potts coupling tensor.

    Enforces the constraint that W(i,j) = W(j,i) for coupling matrices.

    Args:
        weight (tensor): 4D tensor of shape (length, vocab, length, vocab) to symmetrize.
    """
    return 0.5 * (weight + weight.permute(2, 3, 0, 1))