diff --git a/notebooks/integrations/hugging-face/_nbtest.teardown.loading-model-from-hugging-face.ipynb b/notebooks/integrations/hugging-face/_nbtest.teardown.loading-model-from-hugging-face.ipynb new file mode 100644 index 00000000..cbdb13e7 --- /dev/null +++ b/notebooks/integrations/hugging-face/_nbtest.teardown.loading-model-from-hugging-face.ipynb @@ -0,0 +1,56 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "385c47c3-27e8-4b51-b8b7-26c97b9a3ad3", + "metadata": {}, + "outputs": [], + "source": [ + "from elasticsearch import Elasticsearch\n", + "from getpass import getpass\n", + "\n", + "ELASTIC_CLOUD_ID = getpass(\"Elastic Cloud ID: \")\n", + "ELASTIC_API_KEY = getpass(\"Elastic Api Key: \")\n", + "\n", + "client = Elasticsearch(cloud_id=ELASTIC_CLOUD_ID, api_key=ELASTIC_API_KEY,)\n", + "\n", + "# delete the notebook's index\n", + "client.indices.delete(index=\"blogs\", ignore_unavailable=True)\n", + "\n", + "# delete the pipeline\n", + "try:\n", + " client.ingest.delete_pipeline(id=\"vectorize_blogs\")\n", + "except:\n", + " pass\n", + "\n", + "# delete the model\n", + "try:\n", + " client.ml.delete_trained_model(model_id=\"sentence-transformers__all-minilm-l6-v2\", force=True)\n", + "except:\n", + " pass" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb b/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb index ddd16b8b..f9bbaf4c 100644 --- a/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb +++ b/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb @@ -3,7 +3,10 @@ { "cell_type": "markdown", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "# NLP text search using hugging face transformer model\n", @@ -44,14 +47,20 @@ }, "outputs": [], "source": [ - "# install packages\n", - "!python3 -m pip install -qU sentence-transformers eland elasticsearch transformers\n", - "\n", + "!python3 -m pip -qU install sentence-transformers eland elasticsearch transformers" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "# import modules\n", - "import pandas as pd, json\n", "from elasticsearch import Elasticsearch\n", "from getpass import getpass\n", - "from urllib.request import urlopen" + "from urllib.request import urlopen\n", + "import json" ] }, { @@ -93,8 +102,15 @@ "ELASTIC_CLOUD_ID = getpass(\"Elastic Cloud ID: \")\n", "\n", "# https://www.elastic.co/search-labs/tutorials/install-elasticsearch/elastic-cloud#creating-an-api-key\n", - "ELASTIC_API_KEY = getpass(\"Elastic Api Key: \")\n", - "\n", + "ELASTIC_API_KEY = getpass(\"Elastic Api Key: \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "!eland_import_hub_model --cloud-id $ELASTIC_CLOUD_ID --hub-model-id sentence-transformers/all-MiniLM-L6-v2 --task-type text_embedding --es-api-key $ELASTIC_API_KEY --start" ] }, @@ -304,7 +320,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -315,125 +331,40 @@ }, "outputs": [ { - "data": { - "text/html": [ - "
\n", - " | _id | \n", - "_score | \n", - "fields.title | \n", - "
---|---|---|---|
0 | \n", - "TxUU-YkBAHcz2kFqAun2 | \n", - "0.591786 | \n", - "[Brewing in Beats: Track network connections] | \n", - "
1 | \n", - "SxUU-YkBAHcz2kFqAun2 | \n", - "0.401099 | \n", - "[Machine Learning for Nginx Logs - Identifying... | \n", - "
2 | \n", - "UxUU-YkBAHcz2kFqAun2 | \n", - "0.390279 | \n", - "[Data Visualization For Machine Learning] | \n", - "
3 | \n", - "TBUU-YkBAHcz2kFqAun2 | \n", - "0.368995 | \n", - "[Logstash Lines: Introduce integration plugins] | \n", - "
4 | \n", - "UhUU-YkBAHcz2kFqAun2 | \n", - "0.368995 | \n", - "[Logstash Lines: Introduce integration plugins] | \n", - "
5 | \n", - "URUU-YkBAHcz2kFqAun2 | \n", - "0.356903 | \n", - "[Keeping up with Kibana: This week in Kibana f... | \n", - "
6 | \n", - "UBUU-YkBAHcz2kFqAun2 | \n", - "0.341939 | \n", - "[Kibana 4 Video Tutorials, Part 3] | \n", - "
7 | \n", - "VBUU-YkBAHcz2kFqAun2 | \n", - "0.337294 | \n", - "[Introducing approximate nearest neighbor sear... | \n", - "
8 | \n", - "ThUU-YkBAHcz2kFqAun2 | \n", - "0.336460 | \n", - "[Where in the World is Elastic? - QCon Beijing... | \n", - "
9 | \n", - "TRUU-YkBAHcz2kFqAun2 | \n", - "0.320756 | \n", - "[EQL for the masses] | \n", - "