{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "2bbd4bff-33b8-49af-9957-46bd65875cf8",
          "showTitle": false,
          "title": ""
        },
        "id": "baySg2v7jNUG"
      },
      "source": [
        "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
        "# John Snow Labs Models for  Databricks Serve Endpoints\n",
        "You can Query&Deploy John Snow Labs models with 1 line of code as [Databricks Model Serve Endpoints](https://docs.databricks.com/en/machine-learning/model-serving/index.html).     \n",
        "Data is passed to the  [predict()](https://nlp.johnsnowlabs.com/docs/en/jsl/predict_api) function and predictions are shaped accordingly.         \n",
        "You must create endpoints from a Databricks cluster created by [nlp.install](https://nlp.johnsnowlabs.com/docs/en/jsl/install_advanced#automatic-databricks-installation).\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "dbcb2375-3aef-402c-82be-4d8ec130e862",
          "showTitle": false,
          "title": ""
        },
        "id": "Kg9n5iYljNUI"
      },
      "source": [
        "# 0) Setup your env\n",
        "Install relevent libs & set license env"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "efb5db15-74a7-45ef-b125-c52e9c2f23be",
          "showTitle": false,
          "title": ""
        },
        "id": "jgs0amD6jNUJ"
      },
      "outputs": [],
      "source": [
        "%pip install -U johnsnowlabs_for_databricks\n",
        "%pip install -U mlflow_by_johnsnowlabs\n",
        "dbutils.library.restartPython()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "08c65230-719f-48f2-be79-ddedbc73cf5d",
          "showTitle": false,
          "title": ""
        },
        "id": "bJQYDASWjNUK"
      },
      "source": [
        "# 1) Provide Credentials\n",
        "You need\n",
        "1. John Snow Labs License JSON\n",
        "2. Databricks Access Token & Databricks Host URL"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "b0dacf7a-5c0a-4b9b-a070-c63fa2d6b3a4",
          "showTitle": false,
          "title": ""
        },
        "id": "7lqsEUdTjNUK",
        "outputId": "43d3f3dd-2b1e-4888-b7f0-ba3c9f8c6b04"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\"></div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\"></div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        }
      ],
      "source": [
        "from johnsnowlabs import nlp\n",
        "import mlflow\n",
        "import os\n",
        "\n",
        "# Enter your John Snow Labs Container License.\n",
        "endpoint_license = \"\"\"\n",
        "Your John Snow Labs Container License. NOT your Datbricks cluster license\n",
        "\"\"\"\n",
        "os.environ['JOHNSNOWLABS_LICENSE_JSON_FOR_CONTAINER'] = endpoint_license\n",
        "os.environ['JOHNSNOWLABS_LICENSE_JSON'] = endpoint_license\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "314cc765-d946-448e-b64a-8565dccd5d81",
          "showTitle": false,
          "title": ""
        },
        "id": "JiBB4vq_jNUL"
      },
      "source": [
        "# 2) Deploy John Snow Labs Model & Query\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "## Endpoint Creation\n",
        "\n",
        "You can Query&Deploy John Snow Labs models with 1 line of code as [Databricks Model Serve Endpoints](https://docs.databricks.com/en/machine-learning/model-serving/index.html).     \n",
        "Data is passed to the  [predict()](https://nlp.johnsnowlabs.com/docs/en/jsl/predict_api) function and predictions are shaped accordingly.         \n",
        "You must create endpoints from a Databricks cluster created by [nlp.install](https://nlp.johnsnowlabs.com/docs/en/jsl/install_advanced#automatic-databricks-installation).\n",
        "\n",
        "See [Cluster Creation Notebook](https://github.com/JohnSnowLabs/johnsnowlabs/tree/main/notebooks/create_databricks_cluster.ipynb)\n",
        "and [Databricks Endpoint Tutorial Notebook](https://github.com/JohnSnowLabs/johnsnowlabs/tree/main/notebooks/databricks_endpoints_tutorial.ipynb)      \n",
        "\n",
        "\n",
        "```python\n",
        "# You need `mlflow_by_johnsnowlabs` installed until next mlflow is released\n",
        "! pip install mlflow_by_johnsnowlabs\n",
        "from johnsnowlabs import nlp\n",
        "nlp.deploy_endpoint('bert')\n",
        "nlp.query_endpoint('bert_ENDPOINT','My String to embed')\n",
        "```\n",
        "\n",
        "`nlp.deploy_endpoint` will register a ML-FLow model into your registry and deploy an Endpoint with a JSL license.\n",
        "It has the following parameters:\n",
        "\n",
        "| Parameter              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                            |\n",
        "|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n",
        "| `model`                | Model to be deployed as endpoint which is [converted into NluPipelines](https://nlp.johnsnowlabs.com/docs/en/jsl/utils_for_spark_nlp#nlptonlupipepipe), supported classes are: `String` Reference to NLU Pipeline name like 'bert', `NLUPipeline`, `List[Annotator]`, `Pipeline`, `LightPipeline`, `PretrainedPipeline`, `PipelineModel`. In case of a NLU reference, the endpoint name is auto-generated aus `<nlu_ref>_ENDPOINT` i.e. `bert_ENDPOINT` |\n",
        "| `endpoint_name`        | Name for the deployed endpoint. Optional if using NLU model reference but mandatory for custom pipelines.                                                                                                                                                                                                                                                                                                                                              |\n",
        "| `re_create_endpoint`   | if False, endpoint creation is skipped if one already exists. If True, it will delete existing endpoint if it exists                                                                                                                                                                                                                                                                                                                                   |\n",
        "| `re_create_model`      | if False, model creation is skipped if one already exists. If True, model will be re-logged again, bumping the current version by 2                                                                                                                                                                                                                                                                                                                    |\n",
        "| `workload_size`        | one of Small, Medium, Large.                                                                                                                                                                                                                                                                                                                                                                                                                           |\n",
        "| `gpu`                  | `True`/`False` to load  GPU-optimized jars or CPU-optimized jars in the container. Must use a gpu based `workload_type` if `gpu=true`                                                                                                                                                                                                                                                                                                                  |\n",
        "| `new_run`              | if True, mlflow will start a new run before logging the model                                                                                                                                                                                                                                                                                                                                                                                          |\n",
        "| `block_until_deployed` | if True, this function will block until the endpoint is created                                                                                                                                                                                                                                                                                                                                                                                        |\n",
        "| `workload_type`        | `CPU` by default, use `GPU_SMALL` to spawn a GPU based endpoint instead. Check Databricks docs for alternative values                                                                                                                                                                                                                                                                                                                                  |\n",
        "| `db_host`              | the databricks host URL. If not specified, the DATABRICKS_HOST environment variable is used                                                                                                                                                                                                                                                                                                                                                            |\n",
        "| `db_token`             | the databricks Access Token. If not specified, the DATABRICKS_TOKEN environment variable is used                                                                                                                                                                                                                                                                                                                                                       |\n",
        "\n",
        "`nlp.query_endpoint` translates your query to JSON, sends it to the endpoint and returns the result as pandas DataFrame.\n",
        "It has the following parameters which are forwarded to the [model.predict()](https://nlp.johnsnowlabs.com/docs/en/jsl/predict_api) call inside of the endpoint:\n",
        "\n",
        "| Parameter                   | Description                                                                                        |\n",
        "|-----------------------------|----------------------------------------------------------------------------------------------------|\n",
        "| `endpoint_name`        | Name of the endpoint to query. If used an NLU reference, its simply `<nlu_ref>_ENDPOINT`           |\n",
        "| `query`                | str or list of strings or raw json string. If raw json, is_json_query must be True                 |\n",
        "| `is_json_query`        | if True, query is treated as raw json string                                                       |\n",
        "| `output_level`              | One of `token`, `chunk`, `sentence`, `relation`, `document` to shape outputs                       |\n",
        "| `positions`                 | Set `True`/`False` to include or exclude character index position of predictions                   |\n",
        "| `metadata`                  | Set `True`/`False` to include additional metadata                                                  |\n",
        "| `drop_irrelevant_cols`      | Set `True`/`False` to drop irrelevant columns                                                      |\n",
        "| `get_embeddings`            | Set `True`/`False` to include embedding or not                                                     |\n",
        "| `keep_stranger_features`    | Set `True`/`False` to return columns not named \"text\", 'image\" or \"file_type\" from your input data |\n",
        "| `multithread`               | Set `True`/`False` to use multi-Threading for inference. Auto-inferred if not set                  |\n",
        "| `db_host`              | the databricks host URL. If not specified, the DATABRICKS_HOST environment variable is used        |\n",
        "| `db_token`             | the databricks Access Token. If not specified, the DATABRICKS_TOKEN environment variable is used   |\n",
        "\n",
        "\n",
        "\n",
        "`nlp.query_endpoint` and `nlp.deploy_endpoint` check the following **mandatory** env vars to resolve wheels for endpoints\n",
        "\n",
        "| Env Var Name                | Description                                                                                                                                                 |\n",
        "|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n",
        "| `HEALTHCARE_SECRET`         | Automatically set on your cluster if you run nlp.install()                                                                                                  |\n",
        "| `VISUAL_SECRET`             | Automatically set if you run. `nlp.install(..., visual=True)`. You can only spawn visual endpoint from a cluster created by `nlp.install(..., visual=True)` |\n",
        "| `JOHNSNOWLABS_LICENSE_JSON` | JSON content of your john snow labs licensed to use for endpoints. Should be **airgap license**                                                             |\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "5deb994e-db2a-43c8-82f0-ed809352870b",
          "showTitle": false,
          "title": ""
        },
        "id": "-RMtuWefjNUM",
        "outputId": "9eb77692-9773-41e2-e03d-b64340abeac6"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\"></div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\"></div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        }
      ],
      "source": [
        "general_text = \"John Snow is a medical doctor from England. Peter likes America\"\n",
        "cancer_text = \"\"\"with his breathing while feeding (but negative for any perioral cyanosis or retractions). One day ago, mom also noticed a tactile temperature and gave the patient Tylenol. Baby-girl also has had some decreased p.o. intake. His normal breast-feeding is down from 20 minutes q.2h. to 5 to 10 minutes s\"\"\"\n",
        "\n",
        "ade_text = \"\"\"So glad I am off effexor, so sad it ruined my teeth. tip Please be carefull taking antideppresiva and read about it 1st\"\"\"\n",
        "\n",
        "body_re_text = \"\"\"MRI demonstrated infarction in the upper brain stem , left cerebellum and  right basil ganglia\"\"\"\n",
        "radiology_text = \"\"\"INTERPRETATION: There has been interval development of a moderate left-sided pneumothorax with near complete collapse of the left upper lobe. The lower lobe appears aerated. There is stable, diffuse, bilateral interstitial thickening with no definite acute air space consolidation. The heart and pulmonary vascularity are within normal limits. Left-sided port is seen with Groshong tip at the SVC/RA junction. No evidence for acute fracture, malalignment, or dislocation.\"\"\"\n",
        "\n",
        "\n",
        "long_text = \"\"\"\n",
        "Patient with hypertension, syncope, and spinal stenosis - for recheck.\n",
        "(Medical Transcription Sample Report)\n",
        "SUBJECTIVE:\n",
        "The patient is a 78-year-old female who returns for recheck. She has hypertension. She denies difficulty with chest pain, palpations, orthopnea, nocturnal dyspnea, or edema.\n",
        "PAST MEDICAL HISTORY / SURGERY / HOSPITALIZATIONS:\n",
        "Reviewed and unchanged from the dictation on 12/03/2003.\n",
        "MEDICATIONS:\n",
        "Atenolol 50 mg daily, Premarin 0.625 mg daily, calcium with vitamin D two to three pills daily, multivitamin daily, aspirin as needed, and TriViFlor 25 mg two pills daily. She also has Elocon cream 0.1% and Synalar cream 0.01% that she uses as needed for rash\n",
        "\"\"\"\n",
        "all_data = [general_text,cancer_text,ade_text,body_re_text, radiology_text, long_text ]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "290afadb-e662-4d10-964a-68b27551c614",
          "showTitle": false,
          "title": ""
        },
        "id": "ahKcmZHdjNUM",
        "outputId": "046ff9fb-1815-4f1f-a40c-a7d3cf9819d7"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Writing license to scope JSL_SCOPE\n",
              "Creating new serving endpoint: tokenize_ENDPOINT\n",
              "Deployment starting, this may take 10 to 20 minutes...\n",
              "Created serving endpoint tokenize_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/tokenize_ENDPOINT\n",
              "Out[16]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nWriting license to scope JSL_SCOPE\nCreating new serving endpoint: tokenize_ENDPOINT\nDeployment starting, this may take 10 to 20 minutes...\nCreated serving endpoint tokenize_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/tokenize_ENDPOINT\nOut[16]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>text</th>\n",
              "      <th>token</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>John</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>Snow</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>is</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>a</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>medical</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>306</th>\n",
              "      <td>5</td>\n",
              "      <td>\\nPatient with hypertension, syncope, and spin...</td>\n",
              "      <td>uses</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>307</th>\n",
              "      <td>5</td>\n",
              "      <td>\\nPatient with hypertension, syncope, and spin...</td>\n",
              "      <td>as</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>308</th>\n",
              "      <td>5</td>\n",
              "      <td>\\nPatient with hypertension, syncope, and spin...</td>\n",
              "      <td>needed</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>309</th>\n",
              "      <td>5</td>\n",
              "      <td>\\nPatient with hypertension, syncope, and spin...</td>\n",
              "      <td>for</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>310</th>\n",
              "      <td>5</td>\n",
              "      <td>\\nPatient with hypertension, syncope, and spin...</td>\n",
              "      <td>rash</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>311 rows × 3 columns</p>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>text</th>\n      <th>token</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>John</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>Snow</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>is</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>a</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>medical</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>306</th>\n      <td>5</td>\n      <td>\\nPatient with hypertension, syncope, and spin...</td>\n      <td>uses</td>\n    </tr>\n    <tr>\n      <th>307</th>\n      <td>5</td>\n      <td>\\nPatient with hypertension, syncope, and spin...</td>\n      <td>as</td>\n    </tr>\n    <tr>\n      <th>308</th>\n      <td>5</td>\n      <td>\\nPatient with hypertension, syncope, and spin...</td>\n      <td>needed</td>\n    </tr>\n    <tr>\n      <th>309</th>\n      <td>5</td>\n      <td>\\nPatient with hypertension, syncope, and spin...</td>\n      <td>for</td>\n    </tr>\n    <tr>\n      <th>310</th>\n      <td>5</td>\n      <td>\\nPatient with hypertension, syncope, and spin...</td>\n      <td>rash</td>\n    </tr>\n  </tbody>\n</table>\n<p>311 rows × 3 columns</p>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# simple tokenizer endpoint\n",
        "nlp.deploy_endpoint('tokenize')\n",
        "nlp.query_endpoint('tokenize_ENDPOINT',all_data)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "4405286c-65c1-4ad5-8f54-2a017c9c9760",
          "showTitle": false,
          "title": ""
        },
        "id": "pSWhjYF9jNUM",
        "outputId": "8cebfaae-603e-4a54-c9bb-57b42738c6f0"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Endpoint ner_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \n",
              "Out[10]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nEndpoint ner_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \nOut[10]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>document</th>\n",
              "      <th>entities_from_disk</th>\n",
              "      <th>entities_from_disk_class</th>\n",
              "      <th>entities_from_disk_confidence</th>\n",
              "      <th>entities_from_disk_origin_chunk</th>\n",
              "      <th>entities_from_disk_origin_sentence</th>\n",
              "      <th>text</th>\n",
              "      <th>word_embedding_from_disk</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>John Snow</td>\n",
              "      <td>PERSON</td>\n",
              "      <td>0.98364997</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>England</td>\n",
              "      <td>GPE</td>\n",
              "      <td>0.9762</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>Peter</td>\n",
              "      <td>PERSON</td>\n",
              "      <td>0.9976</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>America</td>\n",
              "      <td>GPE</td>\n",
              "      <td>0.9603</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>document</th>\n      <th>entities_from_disk</th>\n      <th>entities_from_disk_class</th>\n      <th>entities_from_disk_confidence</th>\n      <th>entities_from_disk_origin_chunk</th>\n      <th>entities_from_disk_origin_sentence</th>\n      <th>text</th>\n      <th>word_embedding_from_disk</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>John Snow</td>\n      <td>PERSON</td>\n      <td>0.98364997</td>\n      <td>0</td>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>England</td>\n      <td>GPE</td>\n      <td>0.9762</td>\n      <td>1</td>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>Peter</td>\n      <td>PERSON</td>\n      <td>0.9976</td>\n      <td>2</td>\n      <td>1</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>America</td>\n      <td>GPE</td>\n      <td>0.9603</td>\n      <td>3</td>\n      <td>1</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Deploy & Query general ner model. Default output level is auto-inferred to chunk\n",
        "nlp.deploy_endpoint('ner')\n",
        "nlp.query_endpoint('ner_ENDPOINT', general_text)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "bd7de6ad-83c4-41d5-8412-121a9334109c",
          "showTitle": false,
          "title": ""
        },
        "id": "xlwQUiZUjNUN",
        "outputId": "1aa4e6a1-fd9d-4a8a-c0f3-43c6e69a75d1"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Out[11]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Out[11]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>document</th>\n",
              "      <th>entities_from_disk</th>\n",
              "      <th>entities_from_disk_class</th>\n",
              "      <th>entities_from_disk_confidence</th>\n",
              "      <th>entities_from_disk_origin_chunk</th>\n",
              "      <th>entities_from_disk_origin_sentence</th>\n",
              "      <th>output_level</th>\n",
              "      <th>text</th>\n",
              "      <th>word_embedding_from_disk</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>John Snow</td>\n",
              "      <td>PERSON</td>\n",
              "      <td>0.98364997</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>document</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>England</td>\n",
              "      <td>GPE</td>\n",
              "      <td>0.9762</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>document</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>Peter</td>\n",
              "      <td>PERSON</td>\n",
              "      <td>0.9976</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>document</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>America</td>\n",
              "      <td>GPE</td>\n",
              "      <td>0.9603</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>document</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>document</th>\n      <th>entities_from_disk</th>\n      <th>entities_from_disk_class</th>\n      <th>entities_from_disk_confidence</th>\n      <th>entities_from_disk_origin_chunk</th>\n      <th>entities_from_disk_origin_sentence</th>\n      <th>output_level</th>\n      <th>text</th>\n      <th>word_embedding_from_disk</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>John Snow</td>\n      <td>PERSON</td>\n      <td>0.98364997</td>\n      <td>0</td>\n      <td>0</td>\n      <td>document</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>England</td>\n      <td>GPE</td>\n      <td>0.9762</td>\n      <td>1</td>\n      <td>0</td>\n      <td>document</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>Peter</td>\n      <td>PERSON</td>\n      <td>0.9976</td>\n      <td>2</td>\n      <td>1</td>\n      <td>document</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>America</td>\n      <td>GPE</td>\n      <td>0.9603</td>\n      <td>3</td>\n      <td>1</td>\n      <td>document</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>[[-0.2747400105, 0.4868099988, -0.0717220008, ...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# can change output level like this\n",
        "nlp.query_endpoint('ner_ENDPOINT', general_text,output_level='document')\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "6fa0494e-19d5-4009-8c1c-418b36eaa676",
          "showTitle": false,
          "title": ""
        },
        "id": "3hyeh58wjNUN",
        "outputId": "654ab833-96fb-4dfa-9426-89019a589ef4"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Deleting registered model en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL\n",
              "Warning::Spark Session already created, some configs may not take.\n",
              "Warning::Spark Session already created, some configs may not take.\n",
              "bert_token_classifier_ner_jsl_pipeline download started this may take some time.\n",
              "Approx size to download 386.3 MB\n",
              "\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[OK!]\n",
              "2023/11/17 03:43:16 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\n",
              "Saving model to /tmp/mlflow/d821b627-7ea6-4cf9-b0f9-3747d0e6b82c\n",
              "Warning::Spark Session already created, some configs may not take.\n",
              "WARNING: No Visual NLP jar found!\n",
              "Successfully registered model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\n",
              "2023/11/17 03:43:54 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL, version 1\n",
              "Created version &#39;1&#39; of model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\n",
              "2023/11/17 03:44:40 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\n",
              "Registered model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39; already exists. Creating a new version of this model...\n",
              "2023/11/17 03:45:55 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL, version 2\n",
              "Created version &#39;2&#39; of model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\n",
              "Deleting exisiting Endpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\n",
              "Writing license to scope JSL_SCOPE\n",
              "Creating new serving endpoint: en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\n",
              "Deployment starting, this may take 10 to 20 minutes...\n",
              "Created serving endpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\n",
              "endpoint name is  en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\n",
              "Out[30]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Deleting registered model en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL\nWarning::Spark Session already created, some configs may not take.\nWarning::Spark Session already created, some configs may not take.\nbert_token_classifier_ner_jsl_pipeline download started this may take some time.\nApprox size to download 386.3 MB\n\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[ \\ ]\r[ | ]\r[ / ]\r[ — ]\r[OK!]\n2023/11/17 03:43:16 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\nSaving model to /tmp/mlflow/d821b627-7ea6-4cf9-b0f9-3747d0e6b82c\nWarning::Spark Session already created, some configs may not take.\nWARNING: No Visual NLP jar found!\nSuccessfully registered model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\n2023/11/17 03:43:54 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL, version 1\nCreated version &#39;1&#39; of model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\n2023/11/17 03:44:40 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\nRegistered model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39; already exists. Creating a new version of this model...\n2023/11/17 03:45:55 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL, version 2\nCreated version &#39;2&#39; of model &#39;en_classify_bert_token_ner_jsl_pipeline_REGISTERD_MODEL&#39;.\nDeleting exisiting Endpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\nWriting license to scope JSL_SCOPE\nCreating new serving endpoint: en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\nDeployment starting, this may take 10 to 20 minutes...\nCreated serving endpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\nendpoint name is  en_classify_bert_token_ner_jsl_pipeline_ENDPOINT\nOut[30]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>classified_token</th>\n",
              "      <th>document</th>\n",
              "      <th>entities</th>\n",
              "      <th>entities_class</th>\n",
              "      <th>entities_confidence</th>\n",
              "      <th>entities_origin_chunk</th>\n",
              "      <th>entities_origin_sentence</th>\n",
              "      <th>text</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, O, O, O, B-Demographics, I-Demographics, O...</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>medical doctor</td>\n",
              "      <td>Demographics</td>\n",
              "      <td>0.9947214</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, O, O, O, B-Demographics, I-Demographics, O...</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "      <td>Peter</td>\n",
              "      <td>Demographics</td>\n",
              "      <td>0.9825089</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>John Snow is a medical doctor from England. Pe...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>classified_token</th>\n      <th>document</th>\n      <th>entities</th>\n      <th>entities_class</th>\n      <th>entities_confidence</th>\n      <th>entities_origin_chunk</th>\n      <th>entities_origin_sentence</th>\n      <th>text</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>[O, O, O, O, B-Demographics, I-Demographics, O...</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>medical doctor</td>\n      <td>Demographics</td>\n      <td>0.9947214</td>\n      <td>0</td>\n      <td>0</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>[O, O, O, O, B-Demographics, I-Demographics, O...</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n      <td>Peter</td>\n      <td>Demographics</td>\n      <td>0.9825089</td>\n      <td>1</td>\n      <td>1</td>\n      <td>John Snow is a medical doctor from England. Pe...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# https://nlp.johnsnowlabs.com/2023/06/17/bert_token_classifier_ner_jsl_pipeline_en.html\n",
        "# '.' is replaced with '_' in the nlu reference for the endpoint name\n",
        "endpoint_name = nlp.deploy_endpoint('en.classify.bert_token_ner_jsl.pipeline')\n",
        "print(\"endpoint name is \", endpoint_name)\n",
        "nlp.query_endpoint(endpoint_name, general_text)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "e9d00f23-fb0a-4f93-a690-3cd1b0f9b647",
          "showTitle": false,
          "title": ""
        },
        "id": "Tp0tDMKdjNUN",
        "outputId": "f7d59010-3c23-4072-ba16-02cd6eee3fa1"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Endpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \n",
              "Out[36]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nEndpoint en_classify_bert_token_ner_jsl_pipeline_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \nOut[36]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>classified_token</th>\n",
              "      <th>document</th>\n",
              "      <th>entities</th>\n",
              "      <th>entities_class</th>\n",
              "      <th>entities_confidence</th>\n",
              "      <th>entities_origin_chunk</th>\n",
              "      <th>entities_origin_sentence</th>\n",
              "      <th>text</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>his</td>\n",
              "      <td>Demographics</td>\n",
              "      <td>0.9995588</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>perioral cyanosis</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.98401105</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>retractions</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.99925405</td>\n",
              "      <td>2</td>\n",
              "      <td>0</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>One day ago</td>\n",
              "      <td>Date_Time</td>\n",
              "      <td>0.99938554</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>mom</td>\n",
              "      <td>Demographics</td>\n",
              "      <td>0.99983484</td>\n",
              "      <td>4</td>\n",
              "      <td>1</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>tactile temperature</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.999352</td>\n",
              "      <td>5</td>\n",
              "      <td>1</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>Tylenol</td>\n",
              "      <td>Drug</td>\n",
              "      <td>0.9997625</td>\n",
              "      <td>6</td>\n",
              "      <td>1</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>Baby-girl</td>\n",
              "      <td>Age</td>\n",
              "      <td>0.98052883</td>\n",
              "      <td>7</td>\n",
              "      <td>2</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>decreased p.o. intake</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.99897766</td>\n",
              "      <td>8</td>\n",
              "      <td>2</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>His</td>\n",
              "      <td>Demographics</td>\n",
              "      <td>0.99991167</td>\n",
              "      <td>9</td>\n",
              "      <td>3</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>0</td>\n",
              "      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "      <td>breast-feeding</td>\n",
              "      <td>Body_Part</td>\n",
              "      <td>0.9993943</td>\n",
              "      <td>10</td>\n",
              "      <td>3</td>\n",
              "      <td>with his breathing while feeding (but negative...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>classified_token</th>\n      <th>document</th>\n      <th>entities</th>\n      <th>entities_class</th>\n      <th>entities_confidence</th>\n      <th>entities_origin_chunk</th>\n      <th>entities_origin_sentence</th>\n      <th>text</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>his</td>\n      <td>Demographics</td>\n      <td>0.9995588</td>\n      <td>0</td>\n      <td>0</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>perioral cyanosis</td>\n      <td>Symptom</td>\n      <td>0.98401105</td>\n      <td>1</td>\n      <td>0</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>retractions</td>\n      <td>Symptom</td>\n      <td>0.99925405</td>\n      <td>2</td>\n      <td>0</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>One day ago</td>\n      <td>Date_Time</td>\n      <td>0.99938554</td>\n      <td>3</td>\n      <td>1</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>mom</td>\n      <td>Demographics</td>\n      <td>0.99983484</td>\n      <td>4</td>\n      <td>1</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>tactile temperature</td>\n      <td>Symptom</td>\n      <td>0.999352</td>\n      <td>5</td>\n      <td>1</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>Tylenol</td>\n      <td>Drug</td>\n      <td>0.9997625</td>\n      <td>6</td>\n      <td>1</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>Baby-girl</td>\n      <td>Age</td>\n      <td>0.98052883</td>\n      <td>7</td>\n      <td>2</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>decreased p.o. intake</td>\n      <td>Symptom</td>\n      <td>0.99897766</td>\n      <td>8</td>\n      <td>2</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>His</td>\n      <td>Demographics</td>\n      <td>0.99991167</td>\n      <td>9</td>\n      <td>3</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>0</td>\n      <td>[O, B-Demographics, O, O, O, O, O, O, O, O, B-...</td>\n      <td>with his breathing while feeding (but negative...</td>\n      <td>breast-feeding</td>\n      <td>Body_Part</td>\n      <td>0.9993943</td>\n      <td>10</td>\n      <td>3</td>\n      <td>with his breathing while feeding (but negative...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Relation Example\n",
        "# https://nlp.johnsnowlabs.com/2023/06/17/bert_token_classifier_ner_jsl_pipeline_en.html\n",
        "endpoint_name = nlp.deploy_endpoint('en.classify.bert_token_ner_jsl.pipeline')\n",
        "nlp.query_endpoint(endpoint_name, cancer_text)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "7d48af06-622d-4ffb-bbdf-049218834d41",
          "showTitle": false,
          "title": ""
        },
        "id": "QfJ6mflCjNUN",
        "outputId": "475e6980-eea2-4e71-9514-fb093e6a6e79"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Endpoint en_classify_ade_seq_biobert_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \n",
              "Out[13]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nEndpoint en_classify_ade_seq_biobert_ENDPOINT already exists!  Set re_create_endpoint=True if you want to re-create it \nOut[13]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>classified_sequence</th>\n",
              "      <th>classified_sequence_confidence</th>\n",
              "      <th>sentence</th>\n",
              "      <th>text</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>True</td>\n",
              "      <td>0.998191</td>\n",
              "      <td>So glad I am off effexor, so sad it ruined my ...</td>\n",
              "      <td>So glad I am off effexor, so sad it ruined my ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>False</td>\n",
              "      <td>0.999601</td>\n",
              "      <td>tip Please be carefull taking antideppresiva ...</td>\n",
              "      <td>So glad I am off effexor, so sad it ruined my ...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>classified_sequence</th>\n      <th>classified_sequence_confidence</th>\n      <th>sentence</th>\n      <th>text</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>True</td>\n      <td>0.998191</td>\n      <td>So glad I am off effexor, so sad it ruined my ...</td>\n      <td>So glad I am off effexor, so sad it ruined my ...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>False</td>\n      <td>0.999601</td>\n      <td>tip Please be carefull taking antideppresiva ...</td>\n      <td>So glad I am off effexor, so sad it ruined my ...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Sequence Classifier Example https://nlp.johnsnowlabs.com/2022/02/08/bert_sequence_classifier_ade_en.html\n",
        "endpoint_name = nlp.deploy_endpoint('en.classify.ade.seq_biobert')\n",
        "nlp.query_endpoint(endpoint_name, ade_text)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "372f65b0-f258-4640-b3d2-7b3bed3a6571",
          "showTitle": false,
          "title": ""
        },
        "id": "emhJA7ScjNUN",
        "outputId": "ee632830-f48d-42de-a115-51ad62b45a0b"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Writing license to scope JSL_SCOPE\n",
              "Creating new serving endpoint: en_assert_radiology_ENDPOINT\n",
              "Deployment starting, this may take 10 to 20 minutes...\n",
              "Created serving endpoint en_assert_radiology_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_assert_radiology_ENDPOINT\n",
              "Out[14]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nWriting license to scope JSL_SCOPE\nCreating new serving endpoint: en_assert_radiology_ENDPOINT\nDeployment starting, this may take 10 to 20 minutes...\nCreated serving endpoint en_assert_radiology_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_assert_radiology_ENDPOINT\nOut[14]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>assertion</th>\n",
              "      <th>document</th>\n",
              "      <th>entities</th>\n",
              "      <th>entities_class</th>\n",
              "      <th>entities_confidence</th>\n",
              "      <th>entities_origin_chunk</th>\n",
              "      <th>entities_origin_sentence</th>\n",
              "      <th>text</th>\n",
              "      <th>word_embedding_from_disk</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>INTERPRETATION:</td>\n",
              "      <td>Section_Header</td>\n",
              "      <td>0.94765</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>moderate</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.8972</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>left-sided</td>\n",
              "      <td>Direction</td>\n",
              "      <td>0.9724</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>pneumothorax</td>\n",
              "      <td>Disease_Syndrome_Disorder</td>\n",
              "      <td>0.926</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>near</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.7196</td>\n",
              "      <td>4</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>complete</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.6933</td>\n",
              "      <td>5</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>collapse</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.6643</td>\n",
              "      <td>6</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>left</td>\n",
              "      <td>Direction</td>\n",
              "      <td>0.6613</td>\n",
              "      <td>7</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>upper lobe</td>\n",
              "      <td>Internal_organ_or_component</td>\n",
              "      <td>0.35195</td>\n",
              "      <td>8</td>\n",
              "      <td>1</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>lower lobe</td>\n",
              "      <td>Internal_organ_or_component</td>\n",
              "      <td>0.56105</td>\n",
              "      <td>9</td>\n",
              "      <td>2</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>stable</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.8667</td>\n",
              "      <td>10</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>diffuse</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.8833</td>\n",
              "      <td>11</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>bilateral</td>\n",
              "      <td>Direction</td>\n",
              "      <td>0.9789</td>\n",
              "      <td>12</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>interstitial thickening</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.3513</td>\n",
              "      <td>13</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>definite</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.9115</td>\n",
              "      <td>14</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>acute</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.8942</td>\n",
              "      <td>15</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>air space consolidation</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.25703335</td>\n",
              "      <td>16</td>\n",
              "      <td>3</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>heart</td>\n",
              "      <td>Internal_organ_or_component</td>\n",
              "      <td>0.9672</td>\n",
              "      <td>17</td>\n",
              "      <td>4</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>pulmonary vascularity</td>\n",
              "      <td>Internal_organ_or_component</td>\n",
              "      <td>0.72284997</td>\n",
              "      <td>18</td>\n",
              "      <td>4</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>Left-sided</td>\n",
              "      <td>Direction</td>\n",
              "      <td>0.9675</td>\n",
              "      <td>19</td>\n",
              "      <td>5</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>port</td>\n",
              "      <td>Medical_Device</td>\n",
              "      <td>0.5644</td>\n",
              "      <td>20</td>\n",
              "      <td>5</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>Groshong tip</td>\n",
              "      <td>Medical_Device</td>\n",
              "      <td>0.82495</td>\n",
              "      <td>21</td>\n",
              "      <td>5</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>0</td>\n",
              "      <td>Confirmed</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>SVC/RA junction</td>\n",
              "      <td>Internal_organ_or_component</td>\n",
              "      <td>0.5879</td>\n",
              "      <td>22</td>\n",
              "      <td>5</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>acute</td>\n",
              "      <td>Modifier</td>\n",
              "      <td>0.8571</td>\n",
              "      <td>23</td>\n",
              "      <td>6</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>fracture</td>\n",
              "      <td>Injury_or_Poisoning</td>\n",
              "      <td>0.8191</td>\n",
              "      <td>24</td>\n",
              "      <td>6</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>malalignment</td>\n",
              "      <td>Symptom</td>\n",
              "      <td>0.9013</td>\n",
              "      <td>25</td>\n",
              "      <td>6</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>0</td>\n",
              "      <td>Negative</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>dislocation</td>\n",
              "      <td>Injury_or_Poisoning</td>\n",
              "      <td>0.9575</td>\n",
              "      <td>26</td>\n",
              "      <td>6</td>\n",
              "      <td>INTERPRETATION: There has been interval develo...</td>\n",
              "      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>assertion</th>\n      <th>document</th>\n      <th>entities</th>\n      <th>entities_class</th>\n      <th>entities_confidence</th>\n      <th>entities_origin_chunk</th>\n      <th>entities_origin_sentence</th>\n      <th>text</th>\n      <th>word_embedding_from_disk</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>INTERPRETATION:</td>\n      <td>Section_Header</td>\n      <td>0.94765</td>\n      <td>0</td>\n      <td>0</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>moderate</td>\n      <td>Modifier</td>\n      <td>0.8972</td>\n      <td>1</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>left-sided</td>\n      <td>Direction</td>\n      <td>0.9724</td>\n      <td>2</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>pneumothorax</td>\n      <td>Disease_Syndrome_Disorder</td>\n      <td>0.926</td>\n      <td>3</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>near</td>\n      <td>Modifier</td>\n      <td>0.7196</td>\n      <td>4</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>complete</td>\n      <td>Modifier</td>\n      <td>0.6933</td>\n      <td>5</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>collapse</td>\n      <td>Symptom</td>\n      <td>0.6643</td>\n      <td>6</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>left</td>\n      <td>Direction</td>\n      <td>0.6613</td>\n      <td>7</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>upper lobe</td>\n      <td>Internal_organ_or_component</td>\n      <td>0.35195</td>\n      <td>8</td>\n      <td>1</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>lower lobe</td>\n      <td>Internal_organ_or_component</td>\n      <td>0.56105</td>\n      <td>9</td>\n      <td>2</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>stable</td>\n      <td>Modifier</td>\n      <td>0.8667</td>\n      <td>10</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>diffuse</td>\n      <td>Modifier</td>\n      <td>0.8833</td>\n      <td>11</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>bilateral</td>\n      <td>Direction</td>\n      <td>0.9789</td>\n      <td>12</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>interstitial thickening</td>\n      <td>Symptom</td>\n      <td>0.3513</td>\n      <td>13</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>definite</td>\n      <td>Modifier</td>\n      <td>0.9115</td>\n      <td>14</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>acute</td>\n      <td>Modifier</td>\n      <td>0.8942</td>\n      <td>15</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>air space consolidation</td>\n      <td>Symptom</td>\n      <td>0.25703335</td>\n      <td>16</td>\n      <td>3</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>heart</td>\n      <td>Internal_organ_or_component</td>\n      <td>0.9672</td>\n      <td>17</td>\n      <td>4</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>pulmonary vascularity</td>\n      <td>Internal_organ_or_component</td>\n      <td>0.72284997</td>\n      <td>18</td>\n      <td>4</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>Left-sided</td>\n      <td>Direction</td>\n      <td>0.9675</td>\n      <td>19</td>\n      <td>5</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>port</td>\n      <td>Medical_Device</td>\n      <td>0.5644</td>\n      <td>20</td>\n      <td>5</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>Groshong tip</td>\n      <td>Medical_Device</td>\n      <td>0.82495</td>\n      <td>21</td>\n      <td>5</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>0</td>\n      <td>Confirmed</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>SVC/RA junction</td>\n      <td>Internal_organ_or_component</td>\n      <td>0.5879</td>\n      <td>22</td>\n      <td>5</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>acute</td>\n      <td>Modifier</td>\n      <td>0.8571</td>\n      <td>23</td>\n      <td>6</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>fracture</td>\n      <td>Injury_or_Poisoning</td>\n      <td>0.8191</td>\n      <td>24</td>\n      <td>6</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>malalignment</td>\n      <td>Symptom</td>\n      <td>0.9013</td>\n      <td>25</td>\n      <td>6</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>0</td>\n      <td>Negative</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>dislocation</td>\n      <td>Injury_or_Poisoning</td>\n      <td>0.9575</td>\n      <td>26</td>\n      <td>6</td>\n      <td>INTERPRETATION: There has been interval develo...</td>\n      <td>[[0.0482680351, 0.8041833639, 0.2013939619, 0....</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Assertion Example https://nlp.johnsnowlabs.com/2021/03/18/assertion_dl_radiology_en.html\n",
        "endpoint_name = nlp.deploy_endpoint('en.assert.radiology')\n",
        "nlp.query_endpoint(endpoint_name, radiology_text)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "641a6d60-5fa1-4076-9d8b-5ea088dc0901",
          "showTitle": false,
          "title": ""
        },
        "id": "sA2Z9cRwjptp",
        "outputId": "272bc438-a155-4e5a-9b5d-f671f67a1fb3"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Source Code Pro\", \"Menlo\", monospace;;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Deleting exisiting Endpoint en_summarize_clinical_jsl_ENDPOINT\n",
              "Writing license to scope JSL_SCOPE\n",
              "Creating new serving endpoint: en_summarize_clinical_jsl_ENDPOINT\n",
              "Deployment starting, this may take 10 to 20 minutes...\n",
              "Created serving endpoint en_summarize_clinical_jsl_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_summarize_clinical_jsl_ENDPOINT\n",
              "Out[7]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nDeleting exisiting Endpoint en_summarize_clinical_jsl_ENDPOINT\nWriting license to scope JSL_SCOPE\nCreating new serving endpoint: en_summarize_clinical_jsl_ENDPOINT\nDeployment starting, this may take 10 to 20 minutes...\nCreated serving endpoint en_summarize_clinical_jsl_ENDPOINT at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/en_summarize_clinical_jsl_ENDPOINT\nOut[7]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          },
          "output_type": "display_data"
        },
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>sentence</th>\n",
              "      <th>summary</th>\n",
              "      <th>text</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>Patient with hypertension, syncope, and spinal...</td>\n",
              "      <td>The patient has hypertension, syncope, and spi...</td>\n",
              "      <td>Patient with hypertension, syncope, and spinal...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>The patient is a 78-year-old female who return...</td>\n",
              "      <td>A 78-year-old female returns for a recheck aft...</td>\n",
              "      <td>Patient with hypertension, syncope, and spinal...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>She has hypertension.</td>\n",
              "      <td>The patient has hypertension.</td>\n",
              "      <td>Patient with hypertension, syncope, and spinal...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>She denies difficulty with chest pain, palpati...</td>\n",
              "      <td>The patient denies any difficulty with chest p...</td>\n",
              "      <td>Patient with hypertension, syncope, and spinal...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>sentence</th>\n      <th>summary</th>\n      <th>text</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>Patient with hypertension, syncope, and spinal...</td>\n      <td>The patient has hypertension, syncope, and spi...</td>\n      <td>Patient with hypertension, syncope, and spinal...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>The patient is a 78-year-old female who return...</td>\n      <td>A 78-year-old female returns for a recheck aft...</td>\n      <td>Patient with hypertension, syncope, and spinal...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>She has hypertension.</td>\n      <td>The patient has hypertension.</td>\n      <td>Patient with hypertension, syncope, and spinal...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>She denies difficulty with chest pain, palpati...</td>\n      <td>The patient denies any difficulty with chest p...</td>\n      <td>Patient with hypertension, syncope, and spinal...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          },
          "output_type": "display_data"
        }
      ],
      "source": [
        "# Deploy & Query summarizer model https://nlp.johnsnowlabs.com/2023/03/25/summarizer_clinical_jsl.html\n",
        "endpoint_name = nlp.deploy_endpoint('en.summarize.clinical_jsl')\n",
        "nlp.query_endpoint(endpoint_name, long_text,workload_size='Large')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "92febe30-157d-4071-9b1f-ffcc2f524afc",
          "showTitle": false,
          "title": ""
        },
        "id": "-xjDmeErjNUO"
      },
      "source": [
        "# 3) Deploying&Query Custom Pipelines\n",
        "\n",
        "You must specify `endpoint_name` when deploying custom pipelines"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "cd65798b-6a61-4005-8ab7-2e894abd99ae",
          "showTitle": false,
          "title": ""
        },
        "id": "eWAlbw-DjNUO",
        "outputId": "0e4e20d4-c563-400b-e12b-ae1422d56891"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">Warning::Spark Session already created, some configs may not take.\n",
              "2023/11/17 01:57:51 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\n",
              "Saving model to /tmp/mlflow/4b24734b-4afc-467a-a292-adc8d651ea36\n",
              "Warning::Spark Session already created, some configs may not take.\n",
              "WARNING: No Visual NLP jar found!\n",
              "Successfully registered model &#39;my_simple_custom_pipe&#39;.\n",
              "2023/11/17 01:57:59 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: my_simple_custom_pipe, version 1\n",
              "Created version &#39;1&#39; of model &#39;my_simple_custom_pipe&#39;.\n",
              "2023/11/17 01:58:27 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\n",
              "Registered model &#39;my_simple_custom_pipe&#39; already exists. Creating a new version of this model...\n",
              "2023/11/17 01:59:36 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: my_simple_custom_pipe, version 2\n",
              "Created version &#39;2&#39; of model &#39;my_simple_custom_pipe&#39;.\n",
              "Writing license to scope JSL_SCOPE\n",
              "Creating new serving endpoint: my_simple_custom_pipe\n",
              "Deployment starting, this may take 10 to 20 minutes...\n",
              "Created serving endpoint my_simple_custom_pipe at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/my_simple_custom_pipe\n",
              "Out[7]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">Warning::Spark Session already created, some configs may not take.\n2023/11/17 01:57:51 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\nSaving model to /tmp/mlflow/4b24734b-4afc-467a-a292-adc8d651ea36\nWarning::Spark Session already created, some configs may not take.\nWARNING: No Visual NLP jar found!\nSuccessfully registered model &#39;my_simple_custom_pipe&#39;.\n2023/11/17 01:57:59 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: my_simple_custom_pipe, version 1\nCreated version &#39;1&#39; of model &#39;my_simple_custom_pipe&#39;.\n2023/11/17 01:58:27 WARNING mlflow.models.model: Model logged without a signature. Signatures will be required for upcoming model registry features as they validate model inputs and denote the expected schema of model outputs. Please visit https://www.mlflow.org/docs/2.40.0/models.html#set-signature-on-logged-model for instructions on setting a model signature on your logged model.\nRegistered model &#39;my_simple_custom_pipe&#39; already exists. Creating a new version of this model...\n2023/11/17 01:59:36 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: my_simple_custom_pipe, version 2\nCreated version &#39;2&#39; of model &#39;my_simple_custom_pipe&#39;.\nWriting license to scope JSL_SCOPE\nCreating new serving endpoint: my_simple_custom_pipe\nDeployment starting, this may take 10 to 20 minutes...\nCreated serving endpoint my_simple_custom_pipe at https://dbc-3d4c44aa-a512.cloud.databricks.com/#mlflow/endpoints/my_simple_custom_pipe\nOut[7]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>text</th>\n",
              "      <th>token</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>hello world</td>\n",
              "      <td>hello</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>hello world</td>\n",
              "      <td>world</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>text</th>\n      <th>token</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>hello world</td>\n      <td>hello</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>hello world</td>\n      <td>world</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Example of simple custom Pipeline\n",
        "documentAssembler = nlp.DocumentAssembler().setInputCol(\"text\").setOutputCol(\"document\")\n",
        "tokenizer = nlp.Tokenizer().setInputCols(\"document\").setOutputCol(\"token\")\n",
        "fitted_pipe = nlp.Pipeline(\n",
        "    stages=[documentAssembler, tokenizer]).fit(\n",
        "        spark.createDataFrame([[\"\"]]).toDF(\"text\"))\n",
        "\n",
        "\n",
        "# You must specify endpoint_name for custom pipes\n",
        "nlp.deploy_endpoint(fitted_pipe,endpoint_name='my_simple_custom_pipe')\n",
        "nlp.query_endpoint('my_simple_custom_pipe','hello world')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "914e3bf8-cf56-4bb8-bcad-96413f5bb266",
          "showTitle": false,
          "title": ""
        },
        "id": "UeLPAnSEjNUO",
        "outputId": "94f181b0-2e20-49a7-b2e2-0c241f9a2257"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\">glove_100d download started this may take some time.\n",
              "Approximate size to download 145.3 MB\n",
              "\r[ | ]\r[OK!]\n",
              "Warning::Spark Session already created, some configs may not take.\n",
              "Model already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\n",
              "Endpoint complex_custom_pipe already exists!  Set re_create_endpoint=True if you want to re-create it \n",
              "Out[21]: </div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\">glove_100d download started this may take some time.\nApproximate size to download 145.3 MB\n\r[ | ]\r[OK!]\nWarning::Spark Session already created, some configs may not take.\nModel already has been logged, skipping logging and using latest. Set re_create_model=True if you want to cre-create it\nEndpoint complex_custom_pipe already exists!  Set re_create_endpoint=True if you want to re-create it \nOut[21]: </div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>assertion</th>\n",
              "      <th>assertion_confidence</th>\n",
              "      <th>assertion_id</th>\n",
              "      <th>begin</th>\n",
              "      <th>chunk</th>\n",
              "      <th>chunk_id</th>\n",
              "      <th>chunk_num</th>\n",
              "      <th>document</th>\n",
              "      <th>end</th>\n",
              "      <th>entity</th>\n",
              "      <th>label</th>\n",
              "      <th>sent_begin</th>\n",
              "      <th>sent_end</th>\n",
              "      <th>sentence_id</th>\n",
              "      <th>task_id</th>\n",
              "      <th>text</th>\n",
              "      <th>tkn_end</th>\n",
              "      <th>tkn_start</th>\n",
              "      <th>word_embedding_from_disk</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.5846</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>Lorem</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>Lorem</td>\n",
              "      <td>1</td>\n",
              "      <td>A</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>Lorem</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>[[-0.028802, 0.1998700052, -0.3181200027, 0.21...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>index</th>\n      <th>assertion</th>\n      <th>assertion_confidence</th>\n      <th>assertion_id</th>\n      <th>begin</th>\n      <th>chunk</th>\n      <th>chunk_id</th>\n      <th>chunk_num</th>\n      <th>document</th>\n      <th>end</th>\n      <th>entity</th>\n      <th>label</th>\n      <th>sent_begin</th>\n      <th>sent_end</th>\n      <th>sentence_id</th>\n      <th>task_id</th>\n      <th>text</th>\n      <th>tkn_end</th>\n      <th>tkn_start</th>\n      <th>word_embedding_from_disk</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0.5846</td>\n      <td>1</td>\n      <td>0</td>\n      <td>Lorem</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Lorem</td>\n      <td>1</td>\n      <td>A</td>\n      <td>0</td>\n      <td>0</td>\n      <td>3</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Lorem</td>\n      <td>1</td>\n      <td>0</td>\n      <td>[[-0.028802, 0.1998700052, -0.3181200027, 0.21...</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "textData": null,
              "type": "htmlSandbox"
            }
          }
        }
      ],
      "source": [
        "# Example of complex custom pipe\n",
        "# This pipe is expecting multiple external input features\n",
        "# You must provide them when when sending query\n",
        "import pandas as pd\n",
        "from johnsnowlabs import nlp,medical\n",
        "from pyspark.sql import SparkSession\n",
        "# Dummy data\n",
        "dummy_data = {\n",
        "    \"assertion_id\": ['1', '2', '3'],\n",
        "    \"label\": ['0', '1', '0'],\n",
        "    \"begin\": ['0', '0', '0'],\n",
        "    \"chunk_id\": ['1', '2', '3'],\n",
        "    \"entity\": [\"A\", \"B\", \"C\"],\n",
        "    \"chunk_num\": ['1', '2', '3'],\n",
        "    \"chunk\": [\"Lorem\", \"ipsum\", \"dolor\"],\n",
        "    \"end\": ['1', '1', '1'],\n",
        "    \"sentence_id\": ['1', '1', '2'],\n",
        "    \"text\": [\"Lorem ipsum\", \"dolor sit\", \"amet\"],\n",
        "    \"sent_begin\": ['0', '0', '0'],\n",
        "    \"sent_end\": ['3', '3', '3'],\n",
        "    \"task_id\": ['1', '2', '1'],\n",
        "    \"tkn_start\": ['0', '0', '0'],\n",
        "    \"tkn_end\": ['1', '1', '1']\n",
        "}\n",
        "\n",
        "\n",
        "# Create Spark DataFrame\n",
        "df = spark.createDataFrame(pd.DataFrame(dummy_data))\n",
        "\n",
        "\n",
        "document = nlp.DocumentAssembler()\\\n",
        "    .setInputCol(\"text\")\\\n",
        "    .setOutputCol(\"document\")\n",
        "\n",
        "chunk = nlp.Doc2Chunk()\\\n",
        "    .setInputCols(\"document\")\\\n",
        "    .setOutputCol(\"assertion_chunk\")\\\n",
        "    .setChunkCol(\"chunk\")\\\n",
        "    .setStartCol(\"tkn_start\")\\\n",
        "    .setStartColByTokenIndex(True)\\\n",
        "    .setFailOnMissing(False)\\\n",
        "    .setLowerCase(False)\n",
        "\n",
        "token = nlp.Tokenizer()\\\n",
        "    .setInputCols(['document'])\\\n",
        "    .setOutputCol('token')\\\n",
        "    .setContextChars([' ', '_', '/', '.', '(', ')', ':', ',', '-', ''',''', '\"', '\"', '\"', '\\'', ';', '#', '{', '}', '[', ']', '*', '!', '?', '+'])\n",
        "embeddings = (\n",
        "        nlp.WordEmbeddingsModel.pretrained()\n",
        "            .setInputCols([\"document\", \"token\"])\n",
        "            .setOutputCol(\"embeddings\")\n",
        "    )\n",
        "\n",
        "assertionStatus = medical.AssertionDLApproach()\\\n",
        "    .setLabelCol(\"label\")\\\n",
        "    .setInputCols(\"document\", \"assertion_chunk\", \"embeddings\")\\\n",
        "    .setOutputCol(\"prediction\")\\\n",
        "    .setBatchSize(32)\\\n",
        "    .setDropout(0.2)\\\n",
        "    .setLearningRate(0.001)\\\n",
        "    .setEpochs(1)\\\n",
        "    .setValidationSplit(0.2)\\\n",
        "    .setStartCol(\"tkn_start\")\\\n",
        "    .setEndCol(\"tkn_end\")\\\n",
        "    .setScopeWindow([12,9])\\\n",
        "    .setIncludeConfidence(True)\\\n",
        "    .setEnableOutputLogs(True)\\\n",
        "    .setOutputLogsPath('../assertion/logs/mlflow/')\n",
        "\n",
        "\n",
        "fitted_pipe = nlp.Pipeline(\n",
        "    stages = [\n",
        "    document,\n",
        "    chunk,\n",
        "    token,\n",
        "    embeddings,\n",
        "    assertionStatus]).fit(df)\n",
        "\n",
        "json_query = \"\"\"\n",
        "{\n",
        "  \"dataframe_split\": {\n",
        "  \"columns\": [\"assertion_id\", \"label\", \"begin\", \"chunk_id\", \"entity\", \"chunk_num\", \"chunk\", \"end\", \"sentence_id\", \"text\", \"sent_begin\", \"sent_end\", \"task_id\", \"tkn_start\", \"tkn_end\"],\n",
        "  \"data\": [[\"1\", \"0\", \"0\", \"1\", \"A\", \"1\", \"Lorem\", \"1\", \"1\", \"Lorem\", \"0\", \"3\", \"1\", \"0\", \"1\"]]\n",
        "}\n",
        "}\n",
        "\"\"\"\n",
        "nlp.deploy_endpoint(fitted_pipe,endpoint_name='complex_custom_pipe')\n",
        "nlp.query_endpoint('complex_custom_pipe',json_query,is_json_query=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {},
          "inputWidgets": {},
          "nuid": "016ec44e-70cd-4bf1-b502-820fb303116d",
          "showTitle": false,
          "title": ""
        },
        "id": "brJU0yu0jNUO"
      },
      "source": [
        "# 4) Delete all endpoints\n",
        "\n",
        "# You can uncomment and run this to clean up all endpoints"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "application/vnd.databricks.v1+cell": {
          "cellMetadata": {
            "byteLimit": 2048000,
            "rowLimit": 10000
          },
          "inputWidgets": {},
          "nuid": "142ee3eb-7d63-4558-9399-23d115c6f6bb",
          "showTitle": false,
          "title": ""
        },
        "id": "37XlerdQjNUO",
        "outputId": "e2a472fc-ae93-4fb5-d066-43667830fede"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style scoped>\n",
              "  .ansiout {\n",
              "    display: block;\n",
              "    unicode-bidi: embed;\n",
              "    white-space: pre-wrap;\n",
              "    word-wrap: break-word;\n",
              "    word-break: break-all;\n",
              "    font-family: \"Menlo\", \"Monaco\", \"Consolas\", \"Ubuntu Mono\", \"Source Code Pro\", monospace;\n",
              "    font-size: 13px;\n",
              "    color: #555;\n",
              "    margin-left: 4px;\n",
              "    line-height: 19px;\n",
              "  }\n",
              "</style>\n",
              "<div class=\"ansiout\"></div>"
            ]
          },
          "metadata": {
            "application/vnd.databricks.v1+output": {
              "addedWidgets": {},
              "arguments": {},
              "data": "<div class=\"ansiout\"></div>",
              "datasetInfos": [],
              "metadata": {},
              "removedWidgets": [],
              "type": "html"
            }
          }
        }
      ],
      "source": [
        "from johnsnowlabs.auto_install.databricks.endpoints import delete_all_endpoints\n",
        "# delete_all_endpoints()"
      ]
    }
  ],
  "metadata": {
    "application/vnd.databricks.v1+notebook": {
      "dashboards": [],
      "language": "python",
      "notebookMetadata": {
        "pythonIndentUnit": 4
      },
      "notebookName": "databricks_endpoints_tutorial_PUBLIC",
      "widgets": {}
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}