|
53 | 53 | ] |
54 | 54 | }, |
55 | 55 | { |
56 | | - "cell_type": "code", |
57 | | - "execution_count": null, |
58 | 56 | "metadata": {}, |
59 | | - "outputs": [], |
| 57 | + "cell_type": "code", |
60 | 58 | "source": [ |
61 | 59 | "import logging\n", |
62 | | - "import os\n", |
63 | 60 | "import sys\n", |
64 | 61 | "\n", |
65 | | - "\n", |
66 | 62 | "# Configure root logger as catch-all logging config\n", |
67 | 63 | "logger = logging.getLogger(\"Thetis\")\n", |
68 | 64 | "logger.setLevel(logging.INFO)\n", |
69 | 65 | "handler = logging.StreamHandler(sys.stderr)\n", |
70 | 66 | "handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))\n", |
71 | 67 | "logger.addHandler(handler)" |
72 | | - ] |
| 68 | + ], |
| 69 | + "outputs": [], |
| 70 | + "execution_count": null |
73 | 71 | }, |
74 | 72 | { |
75 | 73 | "cell_type": "markdown", |
|
92 | 90 | }, |
93 | 91 | { |
94 | 92 | "cell_type": "code", |
95 | | - "execution_count": null, |
96 | 93 | "metadata": {}, |
97 | | - "outputs": [], |
98 | 94 | "source": [ |
99 | 95 | "import pandas as pd\n", |
100 | 96 | "from sklearn.datasets import fetch_openml\n", |
|
115 | 111 | "categorical_columns = [\"workclass\", \"occupation\"]\n", |
116 | 112 | "df_train_cleared[categorical_columns] = df_train_cleared[categorical_columns].apply(lambda col: pd.Categorical(col).codes)\n", |
117 | 113 | "df_test_cleared[categorical_columns] = df_test_cleared[categorical_columns].apply(lambda col: pd.Categorical(col).codes)" |
118 | | - ] |
| 114 | + ], |
| 115 | + "outputs": [], |
| 116 | + "execution_count": null |
119 | 117 | }, |
120 | 118 | { |
121 | 119 | "cell_type": "markdown", |
|
133 | 131 | }, |
134 | 132 | { |
135 | 133 | "cell_type": "code", |
136 | | - "execution_count": null, |
137 | 134 | "metadata": {}, |
138 | | - "outputs": [], |
139 | 135 | "source": [ |
140 | 136 | "from sklearn.ensemble import RandomForestClassifier\n", |
141 | 137 | "\n", |
|
146 | 142 | "# finally, make predictions on the validation dataset\n", |
147 | 143 | "confidence = classifier.predict_proba(pd.get_dummies(df_test_cleared))\n", |
148 | 144 | "labels = classifier.predict(pd.get_dummies(df_test_cleared))" |
149 | | - ] |
| 145 | + ], |
| 146 | + "outputs": [], |
| 147 | + "execution_count": null |
150 | 148 | }, |
151 | 149 | { |
152 | 150 | "cell_type": "markdown", |
|
168 | 166 | }, |
169 | 167 | { |
170 | 168 | "cell_type": "code", |
171 | | - "execution_count": null, |
172 | 169 | "metadata": {}, |
173 | | - "outputs": [], |
174 | 170 | "source": [ |
175 | 171 | "# use sensitive attributes during safety evaluation\n", |
176 | 172 | "annotations = pd.DataFrame({\"target\": target_test, \"race\": df_test[\"race\"], \"sex\": df_test[\"sex\"]})\n", |
177 | 173 | "predictions = pd.DataFrame({\"labels\": labels, \"confidence\": confidence[:, 1]}, index=annotations.index)" |
178 | | - ] |
| 174 | + ], |
| 175 | + "outputs": [], |
| 176 | + "execution_count": null |
179 | 177 | }, |
180 | 178 | { |
181 | 179 | "cell_type": "markdown", |
|
190 | 188 | }, |
191 | 189 | { |
192 | 190 | "cell_type": "code", |
193 | | - "execution_count": null, |
194 | 191 | "metadata": {}, |
195 | | - "outputs": [], |
196 | 192 | "source": [ |
197 | 193 | "# optional: store prediction and ground truth data on disk\n", |
198 | 194 | "annotations.to_csv(\"adult_annotations.csv\")\n", |
|
202 | 198 | "# important: specify \"index_col\" since Thetis matches the predictions/annotations by their indices\n", |
203 | 199 | "loaded_annotations = pd.read_csv(\"adult_annotations.csv\", index_col=0)\n", |
204 | 200 | "loaded_predictions = pd.read_csv(\"adult_predictions.csv\", index_col=0)" |
205 | | - ] |
| 201 | + ], |
| 202 | + "outputs": [], |
| 203 | + "execution_count": null |
206 | 204 | }, |
207 | 205 | { |
208 | 206 | "cell_type": "markdown", |
|
225 | 223 | ] |
226 | 224 | }, |
227 | 225 | { |
228 | | - "cell_type": "code", |
229 | | - "execution_count": null, |
230 | 226 | "metadata": {}, |
| 227 | + "cell_type": "markdown", |
| 228 | + "source": "Add a dictionary containing the AI solution information required for an AI law compliant technical report:" |
| 229 | + }, |
| 230 | + { |
| 231 | + "metadata": {}, |
| 232 | + "cell_type": "code", |
| 233 | + "source": [ |
| 234 | + "description: dict[str, str]={\n", |
| 235 | + " \"title\": \"Income Prediction (Demo)\",\n", |
| 236 | + " \"issuer\": \"XYZ Demo Solutions GmbH\",\n", |
| 237 | + " \"contact_intern\": \"Jon Doe\",\n", |
| 238 | + " \"contact_extern\": \"Jane Doe\",\n", |
| 239 | + " \"purpose\": \"The goal of this AI system is to estimate, based on demographic data, whether a person's income ...\",\n", |
| 240 | + " \"requirements\": \"The system relies heavily on specific software versions and hardware requirements ...\",\n", |
| 241 | + " \"forms\": \"The AI system is provided as a REST API, which can be operated in containerized environments (Docker, Kubernetes). ...\",\n", |
| 242 | + " \"hardware\": \"The AI system is operated on powerful servers with ...\",\n", |
| 243 | + " \"ui\": \"The system's user interface is designed so that ...\",\n", |
| 244 | + "}" |
| 245 | + ], |
231 | 246 | "outputs": [], |
| 247 | + "execution_count": null |
| 248 | + }, |
| 249 | + { |
| 250 | + "metadata": {}, |
| 251 | + "cell_type": "code", |
232 | 252 | "source": [ |
233 | 253 | "from thetis import thetis\n", |
234 | 254 | "\n", |
235 | 255 | "\n", |
236 | 256 | "result = thetis(\n", |
237 | 257 | " config=\"demo_config_classification.yaml\",\n", |
| 258 | + " description=description,\n", |
238 | 259 | " annotations=annotations,\n", |
239 | 260 | " predictions=predictions,\n", |
240 | 261 | " output_dir=\"./output\",\n", |
241 | 262 | " license_file_path=\"demo_license_classification.dat\"\n", |
242 | 263 | ")" |
243 | | - ] |
| 264 | + ], |
| 265 | + "outputs": [], |
| 266 | + "execution_count": null |
244 | 267 | }, |
245 | 268 | { |
246 | | - "cell_type": "code", |
247 | | - "execution_count": null, |
248 | 269 | "metadata": {}, |
| 270 | + "cell_type": "code", |
249 | 271 | "outputs": [], |
| 272 | + "execution_count": null, |
250 | 273 | "source": [ |
251 | 274 | "from IPython.display import IFrame\n", |
252 | 275 | "IFrame(\"./output/report.pdf\", width=800, height=1024)" |
|
0 commit comments