Skip to content

Commit 04696a5

Browse files
authored
run formatting (#186)
1 parent feef5d3 commit 04696a5

File tree

24 files changed

+153
-122
lines changed

24 files changed

+153
-122
lines changed

databricks-production-qa-demo/steps/deployment/deployment_deploy.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@
3131

3232

3333
@step(enable_cache=False)
34-
def deployment_deploy() -> Annotated[
35-
Optional[DatabricksDeploymentService],
36-
ArtifactConfig(name="databricks_deployment", is_deployment_artifact=True),
37-
]:
34+
def deployment_deploy() -> (
35+
Annotated[
36+
Optional[DatabricksDeploymentService],
37+
ArtifactConfig(
38+
name="databricks_deployment", is_deployment_artifact=True
39+
),
40+
]
41+
):
3842
"""Predictions step.
3943
4044
This is an example of a predictions step that takes the data in and returns

end-to-end-computer-vision/steps/export_label_studio.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
logger = get_logger(__name__)
2929

3030

31-
3231
@step(
3332
output_materializers={
3433
LABELED_DATASET_NAME: LabelStudioAnnotationMaterializer

eurorate-predictor/pipelines/training.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525

2626
@pipeline
27-
def ecb_predictor_model_training_pipeline(augmented_dataset_id, mode: str = "develop"):
27+
def ecb_predictor_model_training_pipeline(
28+
augmented_dataset_id, mode: str = "develop"
29+
):
2830
"""A pipeline to train an XGBoost model and promote it.
2931
3032
Args:

eurorate-predictor/run.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def main(
101101
pipeline_args["config_path"] = os.path.join(
102102
config_folder, f"etl_{mode}.yaml"
103103
)
104-
ecb_predictor_etl_pipeline.with_options(**pipeline_args)(**run_args_etl)
104+
ecb_predictor_etl_pipeline.with_options(**pipeline_args)(
105+
**run_args_etl
106+
)
105107
logger.info("ETL pipeline finished successfully!\n")
106108

107109
# Execute Feature Engineering Pipeline
@@ -126,9 +128,9 @@ def main(
126128
pipeline_args["config_path"] = os.path.join(
127129
config_folder, f"feature_engineering_{mode}.yaml"
128130
)
129-
ecb_predictor_feature_engineering_pipeline.with_options(**pipeline_args)(
130-
**run_args_feature
131-
)
131+
ecb_predictor_feature_engineering_pipeline.with_options(
132+
**pipeline_args
133+
)(**run_args_feature)
132134
logger.info("Feature Engineering pipeline finished successfully!\n")
133135

134136
# Execute Model Training Pipeline
@@ -153,7 +155,9 @@ def main(
153155
pipeline_args["config_path"] = os.path.join(
154156
config_folder, f"training_{mode}.yaml"
155157
)
156-
ecb_predictor_model_training_pipeline.with_options(**pipeline_args)(**run_args_train)
158+
ecb_predictor_model_training_pipeline.with_options(**pipeline_args)(
159+
**run_args_train
160+
)
157161
logger.info("Model Training pipeline finished successfully!\n")
158162

159163

gamesense/steps/finetune.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
from utils.loaders import load_base_model
2929
from utils.tokenizer import load_tokenizer
3030
from zenml import ArtifactConfig, step
31+
from zenml.client import Client
3132
from zenml.enums import ArtifactType
3233
from zenml.logger import get_logger
3334
from zenml.materializers import BuiltInMaterializer
3435
from zenml.utils.cuda_utils import cleanup_gpu_memory
35-
from zenml.client import Client
36-
3736

3837
logger = get_logger(__name__)
3938

huggingface-sagemaker/steps/deploying/huggingface_deployment.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def deploy_to_huggingface(
4747
save_model_to_deploy.entrypoint()
4848

4949
logger.info("Model saved locally. Pushing to HuggingFace...")
50-
assert secret, (
51-
"No secret found with name 'huggingface_creds'. Please create one with your `token`."
52-
)
50+
assert secret, "No secret found with name 'huggingface_creds'. Please create one with your `token`."
5351

5452
token = secret.secret_values["token"]
5553
api = HfApi(token=token)

huggingface-sagemaker/steps/promotion/promote_get_metrics.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727

2828

2929
@step
30-
def promote_get_metrics() -> Tuple[
31-
Annotated[Dict[str, Any], "latest_metrics"],
32-
Annotated[Dict[str, Any], "current_metrics"],
33-
]:
30+
def promote_get_metrics() -> (
31+
Tuple[
32+
Annotated[Dict[str, Any], "latest_metrics"],
33+
Annotated[Dict[str, Any], "current_metrics"],
34+
]
35+
):
3436
"""Get metrics for comparison for promoting a model.
3537
3638
This is an example of a metric retrieval step. It is used to retrieve

llm-complete-guide/pipelines/llm_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Optional
1818

1919
import click
20-
from steps.create_prompt import PROMPT, create_prompt
20+
from steps.create_prompt import PROMPT
2121
from steps.eval_e2e import e2e_evaluation, e2e_evaluation_llm_judged
2222
from steps.eval_retrieval import (
2323
retrieval_evaluation_full,

llm-complete-guide/steps/create_prompt.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
answers. \
2525
"""
2626

27+
2728
@step
2829
def create_prompt() -> str:
2930
"""Create a prompt for the RAG pipeline."""

llm-complete-guide/steps/eval_retrieval.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ def perform_small_retrieval_evaluation(use_reranking: bool) -> float:
275275

276276

277277
@step
278-
def retrieval_evaluation_small() -> Annotated[
279-
float, "small_failure_rate_retrieval"
280-
]:
278+
def retrieval_evaluation_small() -> (
279+
Annotated[float, "small_failure_rate_retrieval"]
280+
):
281281
"""Executes the retrieval evaluation step without reranking.
282282
283283
Returns:
@@ -287,9 +287,9 @@ def retrieval_evaluation_small() -> Annotated[
287287

288288

289289
@step
290-
def retrieval_evaluation_small_with_reranking() -> Annotated[
291-
float, "small_failure_rate_retrieval_reranking"
292-
]:
290+
def retrieval_evaluation_small_with_reranking() -> (
291+
Annotated[float, "small_failure_rate_retrieval_reranking"]
292+
):
293293
"""Executes the retrieval evaluation step with reranking.
294294
295295
Returns:

llm-complete-guide/steps/eval_visualisation.py

+60-57
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# or implied. See the License for the specific language governing
1313
# permissions and limitations under the License.
1414

15-
from typing import Annotated, Dict, List, Tuple
15+
from typing import Annotated, Dict, List
1616

1717
import plotly.graph_objects as go
18-
from plotly.subplots import make_subplots
19-
from zenml import ArtifactConfig, get_step_context, log_metadata, step
18+
from zenml import get_step_context, log_metadata, step
2019
from zenml.types import HTMLString
2120

21+
2222
def create_plotly_bar_chart(
2323
labels: List[str],
2424
scores: List[float],
@@ -43,54 +43,66 @@ def create_plotly_bar_chart(
4343
"""
4444
# Generate colors for bars
4545
if alternate_colors:
46-
colors = ["rgba(66, 133, 244, 0.8)" if i % 2 == 0 else "rgba(219, 68, 55, 0.8)" for i in range(len(labels))]
46+
colors = [
47+
"rgba(66, 133, 244, 0.8)"
48+
if i % 2 == 0
49+
else "rgba(219, 68, 55, 0.8)"
50+
for i in range(len(labels))
51+
]
4752
else:
4853
colors = ["rgba(66, 133, 244, 0.8)" for _ in range(len(labels))]
4954

5055
# Prepare hover text
5156
if descriptions:
52-
hover_text = [f"<b>{label}</b><br>Value: {score:.2f}<br>{descriptions.get(label, '')}"
53-
for label, score in zip(labels, scores)]
57+
hover_text = [
58+
f"<b>{label}</b><br>Value: {score:.2f}<br>{descriptions.get(label, '')}"
59+
for label, score in zip(labels, scores)
60+
]
5461
else:
55-
hover_text = [f"<b>{label}</b><br>Value: {score:.2f}" for label, score in zip(labels, scores)]
62+
hover_text = [
63+
f"<b>{label}</b><br>Value: {score:.2f}"
64+
for label, score in zip(labels, scores)
65+
]
5666

5767
# Create figure
5868
fig = go.Figure()
59-
69+
6070
fig.add_trace(
6171
go.Bar(
6272
y=labels,
6373
x=scores,
64-
orientation='h',
74+
orientation="h",
6575
marker_color=colors,
6676
text=[f"{score:.2f}" for score in scores],
67-
textposition='auto',
77+
textposition="auto",
6878
hovertext=hover_text,
69-
hoverinfo='text',
79+
hoverinfo="text",
7080
)
7181
)
7282

7383
# Set layout
7484
max_value = max(scores) if scores else 5
75-
xaxis_range = [0, 100] if percentage_scale else [0, max(5, max_value * 1.1)]
85+
xaxis_range = (
86+
[0, 100] if percentage_scale else [0, max(5, max_value * 1.1)]
87+
)
7688
xaxis_title = "Percentage (%)" if percentage_scale else "Score"
77-
89+
7890
fig.update_layout(
7991
title=title,
8092
xaxis=dict(
8193
title=xaxis_title,
8294
range=xaxis_range,
8395
showgrid=True,
84-
gridcolor='rgba(230, 230, 230, 0.8)',
96+
gridcolor="rgba(230, 230, 230, 0.8)",
8597
),
8698
yaxis=dict(
8799
autorange="reversed", # Make labels read top-to-bottom
88100
),
89101
margin=dict(l=20, r=20, t=60, b=20),
90102
height=max(300, 70 * len(labels)),
91-
plot_bgcolor='rgba(255, 255, 255, 1)',
103+
plot_bgcolor="rgba(255, 255, 255, 1)",
92104
)
93-
105+
94106
return fig
95107

96108

@@ -122,58 +134,49 @@ def generate_evaluation_html(
122134
"""
123135
# Metric descriptions for hovering
124136
metric_descriptions = {
125-
"Small Retrieval Eval Failure Rate":
126-
"Percentage of small test cases where retrieval failed to find relevant documents.",
127-
"Small Retrieval Eval Failure Rate Reranking":
128-
"Percentage of small test cases where retrieval with reranking failed to find relevant documents.",
129-
"Full Retrieval Eval Failure Rate":
130-
"Percentage of all test cases where retrieval failed to find relevant documents.",
131-
"Full Retrieval Eval Failure Rate Reranking":
132-
"Percentage of all test cases where retrieval with reranking failed to find relevant documents.",
133-
"Failure Rate Bad Answers":
134-
"Percentage of responses that were factually incorrect or misleading.",
135-
"Failure Rate Bad Immediate Responses":
136-
"Percentage of immediate responses that did not adequately address the query.",
137-
"Failure Rate Good Responses":
138-
"Percentage of responses rated as good by evaluators.",
139-
"Average Toxicity Score":
140-
"Average score measuring harmful, offensive, or inappropriate content (lower is better).",
141-
"Average Faithfulness Score":
142-
"Average score measuring how accurately the response represents the source material (higher is better).",
143-
"Average Helpfulness Score":
144-
"Average score measuring the practical utility of responses to users (higher is better).",
145-
"Average Relevance Score":
146-
"Average score measuring how well responses address the specific query intent (higher is better).",
137+
"Small Retrieval Eval Failure Rate": "Percentage of small test cases where retrieval failed to find relevant documents.",
138+
"Small Retrieval Eval Failure Rate Reranking": "Percentage of small test cases where retrieval with reranking failed to find relevant documents.",
139+
"Full Retrieval Eval Failure Rate": "Percentage of all test cases where retrieval failed to find relevant documents.",
140+
"Full Retrieval Eval Failure Rate Reranking": "Percentage of all test cases where retrieval with reranking failed to find relevant documents.",
141+
"Failure Rate Bad Answers": "Percentage of responses that were factually incorrect or misleading.",
142+
"Failure Rate Bad Immediate Responses": "Percentage of immediate responses that did not adequately address the query.",
143+
"Failure Rate Good Responses": "Percentage of responses rated as good by evaluators.",
144+
"Average Toxicity Score": "Average score measuring harmful, offensive, or inappropriate content (lower is better).",
145+
"Average Faithfulness Score": "Average score measuring how accurately the response represents the source material (higher is better).",
146+
"Average Helpfulness Score": "Average score measuring the practical utility of responses to users (higher is better).",
147+
"Average Relevance Score": "Average score measuring how well responses address the specific query intent (higher is better).",
147148
}
148149

149150
# Create individual charts
150151
retrieval_fig = create_plotly_bar_chart(
151-
retrieval_labels,
152-
retrieval_scores,
153-
f"Retrieval Evaluation Metrics",
152+
retrieval_labels,
153+
retrieval_scores,
154+
f"Retrieval Evaluation Metrics",
154155
alternate_colors=True,
155-
descriptions=metric_descriptions
156+
descriptions=metric_descriptions,
156157
)
157-
158+
158159
generation_basic_fig = create_plotly_bar_chart(
159-
generation_basic_labels,
160-
generation_basic_scores,
161-
f"Basic Generation Metrics",
160+
generation_basic_labels,
161+
generation_basic_scores,
162+
f"Basic Generation Metrics",
162163
percentage_scale=True,
163-
descriptions=metric_descriptions
164+
descriptions=metric_descriptions,
164165
)
165-
166+
166167
generation_quality_fig = create_plotly_bar_chart(
167-
generation_quality_labels,
168-
generation_quality_scores,
168+
generation_quality_labels,
169+
generation_quality_scores,
169170
f"Generation Quality Metrics",
170-
descriptions=metric_descriptions
171+
descriptions=metric_descriptions,
171172
)
172173

173174
# Create summary metrics cards
174175
composite_quality = metrics_metadata.get("composite.overall_quality", 0)
175-
retrieval_effectiveness = metrics_metadata.get("composite.retrieval_effectiveness", 0)
176-
176+
retrieval_effectiveness = metrics_metadata.get(
177+
"composite.retrieval_effectiveness", 0
178+
)
179+
177180
# Combine into complete HTML report
178181
html = f"""
179182
<!DOCTYPE html>
@@ -388,7 +391,7 @@ def generate_evaluation_html(
388391
</body>
389392
</html>
390393
"""
391-
394+
392395
return HTMLString(html)
393396

394397

@@ -434,10 +437,10 @@ def visualize_evaluation_results(
434437
+ average_helpfulness_score
435438
+ average_relevance_score
436439
) / 3
437-
440+
438441
composite_retrieval_effectiveness = (
439-
(1 - small_retrieval_eval_failure_rate/100)
440-
+ (1 - full_retrieval_eval_failure_rate/100)
442+
(1 - small_retrieval_eval_failure_rate / 100)
443+
+ (1 - full_retrieval_eval_failure_rate / 100)
441444
) / 2
442445

443446
# Collect all metrics for dashboard and logging

llm-complete-guide/steps/hf_dataset_loader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424

2525
@step(output_materializers=HFDatasetMaterializer)
26-
def load_hf_dataset() -> Tuple[
27-
Annotated[Dataset, "train"], Annotated[Dataset, "test"]
28-
]:
26+
def load_hf_dataset() -> (
27+
Tuple[Annotated[Dataset, "train"], Annotated[Dataset, "test"]]
28+
):
2929
train_dataset = load_dataset(DATASET_NAME_DEFAULT, split="train")
3030
test_dataset = load_dataset(DATASET_NAME_DEFAULT, split="test")
3131
return train_dataset, test_dataset

llm-complete-guide/steps/url_scraper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def url_scraper(
5050
"https://docs.zenml.io/stack-components/step-operators/azureml",
5151
# "https://docs.zenml.io/how-to/interact-with-secrets",
5252
# "https://docs.zenml.io/how-to/infrastructure-deployment/auth-management/service-connectors-guide",
53-
# "https://docs.zenml.io/how-to/infrastructure-deployment/auth-management/hyperai-service-connector",
53+
# "https://docs.zenml.io/how-to/infrastructure-deployment/auth-management/hyperai-service-connector",
5454
# "https://docs.zenml.io/stack-components/data-validators/evidently",
5555
# "https://docs.zenml.io/stack-components/data-validators",
5656
# "https://docs.zenml.io/stack-components/step-operators/sagemaker",

0 commit comments

Comments
 (0)