Skip to content

Commit 9c12f56

Browse files
author
alfekka
committed
rebase
1 parent 6707b63 commit 9c12f56

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

examples/configs/estimators/default_estimators.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,3 @@
100100
- name: CocoaPPL
101101
- name: CocoaMTE
102102
- name: SemanticDensity
103-
- name: SAPLMA
104-
cfg:
105-
model_name: '${model.path}'
106-
- name: MIND
107-
- name: Sheeps
108-
cfg:
109-
model_name: '${model.path}'
110-
- name: SATRMD
111-
cfg:
112-
model_name: '${model.path}'
113-
- name: SATRMD
114-
cfg:
115-
model_name: '${model.path}'
116-
base_method: "TokenMahalanobis"
117-
- name: LookBackLens

examples/configs/estimators/default_estimators_with_supervised.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,20 @@
8686
spacy_path: "en_core_web_sm"
8787
- name: AttentionScore
8888
cfg:
89-
layer: 16
9089
gen_only: False
90+
- name: RAUQ
91+
cfg:
92+
alpha: 0.2
93+
use_entropy: False
94+
- name: RAUQ
95+
cfg:
96+
alpha: 0.8
97+
use_entropy: True
98+
- name: CSL
99+
- name: CocoaMSP
100+
- name: CocoaPPL
101+
- name: CocoaMTE
102+
- name: SemanticDensity
91103
- name: SAPLMA
92104
cfg:
93105
model_name: '${model.path}'

src/lm_polygraph/estimators/eigenscore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from scipy.linalg import eigh
23

34
from typing import Dict
45

@@ -44,7 +45,7 @@ def __call__(self, stats: Dict[str, np.ndarray]) -> np.ndarray:
4445
self.J_d = np.eye(dim) - 1 / dim * np.ones((dim, dim))
4546
covariance = sentence_embeddings @ self.J_d @ sentence_embeddings.T
4647
reg_covariance = covariance + self.alpha * np.eye(covariance.shape[0])
47-
eigenvalues, _ = np.linalg.eig(reg_covariance)
48+
eigenvalues = eigh(reg_covariance, eigvals_only=True)
4849
ue.append(
4950
np.mean(np.log([val if val > 0 else 1e-10 for val in eigenvalues]))
5051
)

src/lm_polygraph/estimators/rauq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def __init__(
4040

4141
# Focus on middle third of layers which typically contain most relevant information
4242
if self.n_layers is not None:
43-
self.layers = list(
43+
self.attn_layers = list(
4444
range(self.n_layers // 3, int(np.ceil(self.n_layers / 3 * 2) + 1))
4545
)
4646
else:
47-
self.layers = None
47+
self.attn_layers = None
4848

4949
def __str__(self) -> str:
5050
"""Returns a string representation of the estimator."""
@@ -108,7 +108,7 @@ def __call__(self, stats: Dict[str, np.ndarray]) -> np.ndarray:
108108
"""
109109
if self.n_layers is None:
110110
self.n_layers = stats["model"].model.config.num_hidden_layers
111-
self.layers = list(
111+
self.attn_layers = list(
112112
range(self.n_layers // 3, int(np.ceil(self.n_layers / 3 * 2) + 1))
113113
)
114114
if self.n_heads is None:
@@ -147,7 +147,7 @@ def __call__(self, stats: Dict[str, np.ndarray]) -> np.ndarray:
147147

148148
# Calculate uncertainty scores for each layer
149149
layer_scores = []
150-
for layer in self.layers:
150+
for layer in self.attn_layers:
151151
# Select most attentive head for current layer
152152
head = attentions[idx][layer].mean(-1).argmax()
153153

src/lm_polygraph/stat_calculators/attention.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __call__(
9494
torch.float16
9595
) # numpy does not support bfloat16
9696
attn_mask[:, j, :j] = stacked_attention.cpu().numpy()
97-
attention_all.append(attn_mask.max(0))
97+
attention_all.append(attn_mask)
9898
result_dict = {
9999
"attention_all": attention_all,
100100
}

0 commit comments

Comments
 (0)