Skip to content

Commit 3115ac5

Browse files
committed
add tutorial on logging
1 parent 1f7ad8d commit 3115ac5

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

user_guides/advanced/05_logging.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# %% [markdown]
2+
"""
3+
# Logging to stdout and file
4+
5+
This guide will teach you how to configure logging in AutoIntent. By default, it is fully disabled.
6+
7+
It will be demonstrated on toy search_space example:
8+
"""
9+
10+
# %%
11+
from pathlib import Path
12+
13+
from autointent import Dataset, Pipeline
14+
from autointent.configs import LoggingConfig
15+
16+
search_space = [
17+
{
18+
"node_type": "scoring",
19+
"metric": "scoring_roc_auc",
20+
"search_space": [
21+
{
22+
"module_name": "knn",
23+
"k": [1],
24+
"weights": ["uniform"],
25+
"embedder_name": ["avsolatorio/GIST-small-Embedding-v0"]
26+
},
27+
],
28+
},
29+
{
30+
"node_type": "decision",
31+
"metric": "decision_accuracy",
32+
"search_space": [
33+
{"module_name": "threshold", "thresh": [0.5]},
34+
{"module_name": "argmax"},
35+
],
36+
},
37+
]
38+
39+
log_config = LoggingConfig(dirpath=Path("logging_tutorial"))
40+
pipeline_optimizer = Pipeline.from_search_space(search_space)
41+
pipeline_optimizer.set_config(log_config)
42+
43+
dataset = Dataset.from_hub("AutoIntent/clinc150_subset")
44+
45+
# %% [markdown]
46+
"""
47+
## Fully Custom Logging
48+
49+
One can fully customize logging via python's standard module [`logging`](https://docs.python.org/3/library/logging.html). Everything you need to do is configure it before AutoIntent execution:
50+
"""
51+
# %%
52+
import logging
53+
54+
logging.basicConfig(level="INFO")
55+
pipeline_optimizer.fit(dataset)
56+
57+
# %% [markdown]
58+
"""
59+
See external tutorials and guides about `logging` module.
60+
"""
61+
62+
# %% [markdown]
63+
"""
64+
## Export from AutoIntent
65+
66+
If you don't have to customize logging, you can export our configuration. Everything you need to do is setup it before AutoIntent execution:
67+
"""
68+
69+
# %%
70+
from autointent import setup_logging
71+
72+
setup_logging("INFO", log_to_filepath="tests/logs/my_exp")
73+
# %%
74+
"""
75+
The first parameter affects the logs to the standard output stream. The second parameter is optional. If it is specified, then the "DEBUG" messages are logged to the file, regardless of what is specified by the first parameter.
76+
"""

0 commit comments

Comments
 (0)