Skip to content

Commit

Permalink
docs: using official token class. mapper since is compatible now (#1738)
Browse files Browse the repository at this point in the history
Once the issue #482 is resolved, we can remove the custom mapper for spacy on this tutorial and use the one provided by the monitoring module.
  • Loading branch information
frascuchon committed Oct 5, 2022
1 parent dc0a17f commit e82fd13
Showing 1 changed file with 3 additions and 35 deletions.
38 changes: 3 additions & 35 deletions docs/tutorials/09-automatic_fastapi_log.ipynb
Expand Up @@ -248,40 +248,6 @@
"We'll add a custom mapper to convert spaCy's output to `TokenClassificationRecord` format"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Mapper"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"import datetime\n",
"\n",
"from rubrix.client.models import TokenClassificationRecord\n",
"\n",
"def custom_mapper(inputs, outputs):\n",
" spaces_regex = re.compile(r\"\\s+\")\n",
" text = inputs\n",
" return TokenClassificationRecord(\n",
" text=text,\n",
" tokens=spaces_regex.split(text),\n",
" prediction=[\n",
" (entity[\"label\"], entity[\"start\"], entity[\"end\"])\n",
" for entity in (\n",
" outputs.get(\"entities\") if isinstance(outputs, dict) else outputs\n",
" )\n",
" ],\n",
" event_timestamp=datetime.datetime.now(),\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -295,13 +261,15 @@
"metadata": {},
"outputs": [],
"source": [
"from rubrix.monitoring.asgi import RubrixLogHTTPMiddleware, token_classification_mapper\n",
"\n",
"app_spacy = FastAPI()\n",
"\n",
"app_spacy.add_middleware(\n",
" RubrixLogHTTPMiddleware,\n",
" api_endpoint=\"/spacy/\",\n",
" dataset=\"monitoring_spacy\",\n",
" records_mapper=custom_mapper\n",
" records_mapper=token_classification_mapper\n",
")\n",
"\n",
"# prediction endpoint using spacy pipeline\n",
Expand Down

0 comments on commit e82fd13

Please sign in to comment.