Skip to content

Commit 86efaca

Browse files
committed
black & isort
1 parent 42b28bb commit 86efaca

54 files changed

Lines changed: 205 additions & 162 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/halomi/reproduce_evaluation.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def main(data_root):
118118
print("Direction-wise mean score for hallucination detection:")
119119
results = {}
120120
for fe_name, fe in feature_sets.items():
121-
(word_level_preds, direction2auc,) = evaluate_token_level_features(
121+
(
122+
word_level_preds,
123+
direction2auc,
124+
) = evaluate_token_level_features(
122125
tokens_dataset, fe, word_to_character_maps, word_labels
123126
)
124127
auc = np.mean(list(direction2auc.values()))
@@ -149,7 +152,10 @@ def main(data_root):
149152
results = {}
150153
print("Direction-wise mean score for omission detection:")
151154
for fe_name, fe in feature_sets.items():
152-
(word_level_preds, direction2auc,) = evaluate_token_level_features(
155+
(
156+
word_level_preds,
157+
direction2auc,
158+
) = evaluate_token_level_features(
153159
tokens_dataset, fe, word_to_character_maps, word_labels
154160
)
155161
auc = np.mean(list(direction2auc.values()))

demo/toxicity-alti-hb/ETOX/etox.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ def etox_paired_file_wrapper(
446446
oldcolumns=True,
447447
filetype=None,
448448
):
449-
450449
"""
451450
file loading/writing wrapper for the paired language toxicity evaluation function.
452451

demo/toxicity-alti-hb/analysis/00c_plot_toxicity_per_lang.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ def plot_toxicity_per_lang():
4343
}
4444
sorted_axes = sorted(list(axis_colors.keys()))
4545
axis_display_names = {
46-
axis: "Race and ethnicity"
47-
if axis == "race_ethnicity"
48-
else axis[0].upper() + axis[1:].replace("_", " ")
46+
axis: (
47+
"Race and ethnicity"
48+
if axis == "race_ethnicity"
49+
else axis[0].upper() + axis[1:].replace("_", " ")
50+
)
4951
for axis in sorted_axes
5052
}
5153
sorted_axis_names = sorted(list(axis_colors.keys()))

stopes/core/cache.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ def save_cache(
8080
value: tp.Any,
8181
iteration_value: tp.Optional[tp.Any] = None,
8282
iteration_index: int = 0,
83-
):
84-
...
83+
): ...
8584

8685
@abstractmethod
8786
def invalidate_cache(
8887
self,
8988
module: "StopesModule",
9089
iteration_value: tp.Optional[tp.Any] = None,
9190
iteration_index: int = 0,
92-
):
93-
...
91+
): ...
9492

9593
def invalidate_module_cache(
9694
self,

stopes/core/jobs_registry/registry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
logger = logging.getLogger("stopes.jobs")
1616

17+
1718
################################################################################
1819
# Registry Exceptions
1920
################################################################################

stopes/core/jobs_registry/submitit_slurm_job.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def _convert_slurm_status_into_registry_job_status(
284284

285285
return job_status
286286

287-
except KeyError: # Entering this except block means slurm_status doesn't exist in submitit_state_to_registry_state_dict
287+
except (
288+
KeyError
289+
): # Entering this except block means slurm_status doesn't exist in submitit_state_to_registry_state_dict
288290
logger.warning(
289291
f"Job with id: {job_id} has unrecognized slurm status: {slurm_status}. Please inspect and if suitable, add this status to the slurm_state_to_registry_state_map converter."
290292
)

stopes/core/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async def test_semaphore():
188188

189189
# make sure that the semaphore blocks execution
190190
ends.sort()
191-
for (end1, end2) in zip(ends, ends[1:]):
191+
for end1, end2 in zip(ends, ends[1:]):
192192
t_diff = end2 - end1
193193
assert (
194194
t_diff.total_seconds() >= sleep_time

stopes/eval/alti/alignment/align.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# This code was adapted from the repository https://github.com/mt-upc/transformer-contributions-nmt by Javier Ferrando.
88

9-
""" Various utilities for computing word attributions and word alignment quality metrics."""
9+
"""Various utilities for computing word attributions and word alignment quality metrics."""
1010

1111
import itertools
1212
import typing as tp
@@ -109,7 +109,8 @@ def compute_alignment_metrics(
109109
sure: tp.List[tp.Set], possible: tp.List[tp.Set], hypothesis: tp.List[tp.Set]
110110
) -> tp.Tuple[float, float, float]:
111111
"""Compute average alignment rate, precision and recall for alignment.
112-
Inputs are lists of alignments. All alignments are presented as sets of (tgt, src) pairs."""
112+
Inputs are lists of alignments. All alignments are presented as sets of (tgt, src) pairs.
113+
"""
113114
sum_a_intersect_p, sum_a_intersect_s, sum_s, sum_a = 0, 0, 0, 0
114115

115116
for s, p, a in itertools.zip_longest(sure, possible, hypothesis):

stopes/eval/alti/alti_metrics/nllb_alti_detector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def load_bilingual_model(
104104
@dataclasses.dataclass
105105
class ALTIMetricsConfig:
106106
"""The config indicating how to load sentence pairs, load the model,
107-
compute the ALTI metrics with it, and save results. - to use with the `compute_nllb_alti` function."""
107+
compute the ALTI metrics with it, and save results. - to use with the `compute_nllb_alti` function.
108+
"""
108109

109110
# the model used to compute ALTI
110111
is_multilingual: bool
@@ -118,7 +119,9 @@ class ALTIMetricsConfig:
118119
Path
119120
] # a .jsonl file with token-level contributions
120121
# format and location of the source data
121-
input_filename: Path # the source file with sources and translations; assumed to be .tsv
122+
input_filename: (
123+
Path # the source file with sources and translations; assumed to be .tsv
124+
)
122125
src_lang: str
123126
tgt_lang: str
124127
src_col: tp.Union[str, int] = "src"

stopes/eval/alti/wrappers/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
def spearmanr(x, y):
2020
"""Compute Spearman rank's correlation bertween two attribution vectors.
21-
https://github.com/samiraabnar/attention_flow/blob/master/compute_corel_distilbert_sst.py"""
21+
https://github.com/samiraabnar/attention_flow/blob/master/compute_corel_distilbert_sst.py
22+
"""
2223

2324
x = pd.Series(x)
2425
y = pd.Series(y)

0 commit comments

Comments
 (0)