Skip to content

Commit

Permalink
feat: update embeddings tuning notebook (GoogleCloudPlatform#1096)
Browse files Browse the repository at this point in the history
# Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make
sure it goes smoothly:

- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/CONTRIBUTING.md).
- [x] You are listed as the author in your notebook or README file.
- [x] Your account is listed in
[`CODEOWNERS`](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/.github/CODEOWNERS)
for the file(s).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- [x] Ensure the tests and linter pass (Run `nox -s format` from the
repository root to format).
- [x] Appropriate docs were updated (if necessary)

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
inardini and gcf-owl-bot[bot] authored Sep 17, 2024
1 parent 24262f1 commit 0a59ddf
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions embeddings/intro_embeddings_tuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
},
"outputs": [],
"source": [
"! pip3 install --upgrade --user google-cloud-aiplatform==1.48.0 google-cloud-documentai==2.26.0 google-cloud-documentai-toolbox==0.13.3a0\n",
"! pip3 install --upgrade --user langchain==0.1.16 langchain-core==0.1.44 langchain-text-splitters==0.0.1 langchain-google-community==1.0.2 gcsfs==2024.3.1 etils==1.7.0"
"! pip3 install --upgrade --user google-cloud-aiplatform google-cloud-documentai google-cloud-documentai-toolbox --quiet\n",
"! pip3 install --upgrade --user langchain langchain-core langchain-text-splitters langchain-google-community gcsfs etils --quiet"
]
},
{
Expand Down Expand Up @@ -402,10 +402,9 @@
"from google.api_core.client_options import ClientOptions\n",
"from google.cloud import aiplatform, documentai\n",
"from google.protobuf.json_format import MessageToDict\n",
"from langchain_community.document_loaders.blob_loaders import Blob\n",
"from langchain_community.document_loaders.parsers import DocAIParser\n",
"import langchain_core\n",
"from langchain_core.documents.base import Document\n",
"from langchain_google_community.docai import Blob, DocAIParser\n",
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
"import numpy as np\n",
"import pandas as pd\n",
Expand Down Expand Up @@ -517,11 +516,11 @@
" }\n",
"\n",
" prompt_template = \"\"\"\n",
" You are an examinator. Your task is to create one QUESTION for an exam using <DOCUMENT> only.\n",
" You are an examinator. Your task is to create one QUESTION for an exam using only.\n",
"\n",
" <DOCUMENT>\n",
" \n",
" {chunk}\n",
" <DOCUMENT/>\n",
" \n",
"\n",
" QUESTION:\n",
" \"\"\"\n",
Expand Down Expand Up @@ -568,7 +567,7 @@
" \"\"\"Get uploaded model from the pipeline job\"\"\"\n",
" evaluation_task = get_task_by_name(job, task_name)\n",
" upload_metadata = MessageToDict(evaluation_task.execution._pb)[\"metadata\"]\n",
" return vertexai.Model(upload_metadata[\"output:model_resource_name\"])\n",
" return aiplatform.Model(upload_metadata[\"output:model_resource_name\"])\n",
"\n",
"\n",
"def get_training_output_dir(\n",
Expand Down Expand Up @@ -724,7 +723,7 @@
},
"outputs": [],
"source": [
"blob = Blob(\n",
"blob = Blob.from_path(\n",
" path=f\"{RAW_DATA_URI}/goog-10-k-2023.pdf\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -1382,28 +1381,33 @@
},
"outputs": [],
"source": [
"import os\n",
"import shutil\n",
"\n",
"delete_endpoint = False\n",
"delete_model = False\n",
"delete_job = False\n",
"delete_bucket = False\n",
"delete_tutorial = False\n",
"\n",
"# Delete endpoint resource\n",
"if delete_endpoint or os.getenv(\"IS_TESTING\"):\n",
" endpoint.delete()\n",
"if delete_endpoint:\n",
" endpoint.delete(force=True)\n",
"\n",
"# Delete model resource\n",
"if delete_model or os.getenv(\"IS_TESTING\"):\n",
"if delete_model:\n",
" model.delete()\n",
"\n",
"# Delete pipeline job\n",
"if delete_job or os.getenv(\"IS_TESTING\"):\n",
"if delete_job:\n",
" job.delete()\n",
"\n",
"# Delete Cloud Storage objects that were created\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil -m rm -r $BUCKET_URI"
"if delete_bucket:\n",
" ! gsutil -m rm -r $BUCKET_URI\n",
"\n",
"# Delete tutorial folder\n",
"if delete_tutorial:\n",
" shutil.rmtree(str(tutorial_path))"
]
}
],
Expand Down

0 comments on commit 0a59ddf

Please sign in to comment.