Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lm_polygraph/estimators/kernel_language_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __call__(self, stats: Dict[str, np.ndarray]) -> np.ndarray:
2. Let NLI'(Si, Sj) = one-hot prediction over (entailment, neutral class, contradiction)
Note that NLI'(Si, Sj) is calculated in stats
3. Let W be a matrix, such that Wij = wNLI'(Si, Sj), where w = (1, 0.5, 0)
4. Let L be a laplacian matrix of W, i.e. L = W - D, where Dii = sum(Wij) over j.
4. Let L be a laplacian matrix of W, i.e. L = D - W, where Dii = sum(Wij) over j.
5. Let Kheat = heat kernel of W, i.e. Kheat = expm(-t * L), where t is a hyperparameter.
6. Finally, KLE(x) = VNE(Kheat), where VNE(A) = -Tr(A log A).
"""
Expand All @@ -105,11 +105,11 @@ def __call__(self, stats: Dict[str, np.ndarray]) -> np.ndarray:
for matrix_entail, matrix_contra in zip(
semantic_matrix_entail, semantic_matrix_contra
):
matrix_entail = (matrix_entail + matrix_entail.T) / 2
matrix_contra = (matrix_contra + matrix_contra.T) / 2
matrix_entail = (matrix_entail + matrix_entail.T)
matrix_contra = (matrix_contra + matrix_contra.T)

matrix_neutral = (
np.ones(matrix_entail.shape) - matrix_entail - matrix_contra
2 * np.ones(matrix_entail.shape) - matrix_entail - matrix_contra
)
weighted_graph = matrix_entail + 0.5 * matrix_neutral

Expand Down
Loading