Skip to content

This PR addresses several long-standing issues across the Spark NLP example notebooks #14620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,191 changes: 210 additions & 1,981 deletions examples/python/transformers/onnx/HuggingFace_ONNX_in_Spark_NLP_ALBERT.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,736 changes: 555 additions & 2,181 deletions examples/python/transformers/onnx/HuggingFace_ONNX_in_Spark_NLP_BERT.ipynb

Large diffs are not rendered by default.

3,172 changes: 422 additions & 2,750 deletions examples/python/transformers/onnx/HuggingFace_ONNX_in_Spark_NLP_BGE.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "yy9Ig4tY3L0z",
"outputId": "2104230a-63f9-4778-f218-484fa5eebe8f",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"id": "yy9Ig4tY3L0z",
"outputId": "2104230a-63f9-4778-f218-484fa5eebe8f"
},
"outputs": [
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m433.6/433.6 kB\u001b[0m \u001b[31m11.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.6/17.6 MB\u001b[0m \u001b[31m63.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m72.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m363.4/363.4 MB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.8/13.8 MB\u001b[0m \u001b[31m62.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m24.6/24.6 MB\u001b[0m \u001b[31m52.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m883.7/883.7 kB\u001b[0m \u001b[31m29.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.5/211.5 MB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 MB\u001b[0m \u001b[31m14.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 MB\u001b[0m \u001b[31m7.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.5/207.5 MB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.1/21.1 MB\u001b[0m \u001b[31m54.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
],
"outputs": [],
"source": [
"!pip install -q --upgrade transformers optimum onnx onnxruntime"
]
Expand Down Expand Up @@ -105,16 +79,16 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "1F7dqTBe3L01",
"outputId": "04ec1dfb-0327-42c2-e058-e7ca52c847a2",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"id": "1F7dqTBe3L01",
"outputId": "04ec1dfb-0327-42c2-e058-e7ca52c847a2"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"2025-05-13 14:31:06.182461: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
Expand Down Expand Up @@ -200,57 +174,57 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "nCc4TrW3IVCs"
},
"outputs": [],
"source": [
"import json\n",
"output_json = json.load(open(f\"{EXPORT_PATH}/vocab.json\"))\n",
"\n",
"with open(f\"{EXPORT_PATH}/assets/vocab.txt\", \"w\") as f:\n",
" for key in output_json.keys():\n",
" print(key, file=f)"
],
"metadata": {
"id": "nCc4TrW3IVCs"
},
"execution_count": 9,
"outputs": []
]
},
{
"cell_type": "code",
"source": [
"!mv {EXPORT_PATH}/merges.txt {EXPORT_PATH}/assets"
],
"execution_count": 10,
"metadata": {
"id": "Jgrbr5_iISGa",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Jgrbr5_iISGa",
"outputId": "042b47be-d0c0-4ae6-892a-d48a280f9d59"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"mv: cannot stat 'export_onnx/sshleifer/distilbart-xsum-12-6/merges.txt': No such file or directory\n"
]
}
],
"source": [
"!mv {EXPORT_PATH}/merges.txt {EXPORT_PATH}/assets"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"id": "qFXX_acJ3L03",
"outputId": "09206d0e-c68c-472c-9f0c-9a433f59ea0a",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"id": "qFXX_acJ3L03",
"outputId": "09206d0e-c68c-472c-9f0c-9a433f59ea0a"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"total 3152352\n",
"drwxr-xr-x 2 root root 4096 May 13 14:34 assets\n",
Expand Down Expand Up @@ -294,17 +268,17 @@
"cell_type": "code",
"execution_count": 28,
"metadata": {
"id": "udnbTHNj8WR6",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 582
},
"id": "udnbTHNj8WR6",
"outputId": "413b9a26-5121-4835-8929-bd051ba7293f"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Installing PySpark 3.2.3 and Spark NLP 6.0.0\n",
"setup Colab for PySpark 3.2.3 and Spark NLP 6.0.0\n",
Expand Down Expand Up @@ -336,19 +310,19 @@
]
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"id": "a0a7f59038d342b4a4cd8ee099c8f6a3",
"pip_warning": {
"packages": [
"py4j",
"pyspark"
]
},
"id": "a0a7f59038d342b4a4cd8ee099c8f6a3"
}
}
},
"metadata": {}
"metadata": {},
"output_type": "display_data"
}
],
"source": [
Expand All @@ -375,8 +349,7 @@
"source": [
"import sparknlp\n",
"# let's start Spark with Spark NLP\n",
"spark = sparknlp.start()\n",
""
"spark = sparknlp.start()\n"
]
},
{
Expand Down Expand Up @@ -475,8 +448,8 @@
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"ls: cannot access 'sshleifer/distilbart-xsum-12-6_spark_nlp': No such file or directory\n"
]
Expand Down Expand Up @@ -533,9 +506,6 @@
},
"outputs": [
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand Down Expand Up @@ -613,4 +583,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading