Skip to content

Merge main into staging #318

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 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file modified site/notebooks.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@
"import os\n",
"\n",
"import dotenv\n",
"import nltk\n",
"\n",
"dotenv.load_dotenv()\n",
"nltk.download('stopwords')\n",
"\n",
"if os.getenv(\"OPENAI_API_KEY\") is None:\n",
" raise Exception(\"OPENAI_API_KEY not found\")"
Expand Down
165 changes: 7 additions & 158 deletions site/notebooks/code_samples/nlp_and_llm/llm_summarization_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
"\n",
"train_df, test_df = cnn_dailymail.load_data(source=\"offline\", dataset_size=\"100\")\n",
"\n",
"# Display the first few rows of the dataframe to check the loaded data.\n",
"cnn_dailymail.display_nice(train_df.head())"
"# Display the first few rows of the dataframe to check the loaded data. Ignore the \"bert_embedding_model_prediction\" column\n",
"cnn_dailymail.display_nice(train_df.drop(\"bert_embedding_model_prediction\", axis=1).head())"
]
},
{
Expand Down Expand Up @@ -223,8 +223,12 @@
"import os\n",
"\n",
"import dotenv\n",
"import nltk\n",
"\n",
"dotenv.load_dotenv()\n",
"nltk.download('stopwords')\n",
"\n",
"# os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"\n",
"\n",
"if os.getenv(\"OPENAI_API_KEY\") is None:\n",
" raise Exception(\"OPENAI_API_KEY not found\")"
Expand Down Expand Up @@ -624,162 +628,7 @@
"source": [
"### Model Validation\n",
"\n",
"This section is dedicated to the assessment of the AI model's understanding and processing of language data. It involves validating the model through various embedding and performance tests, ensuring the model's output is as expected and reliable."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Run embeddings tests\n",
"\n",
"This subsection involves conducting tests to examine the semantic space where words or phrases from the vocabulary are mapped. We check for:\n",
"\n",
"- *Cosine Similarity Distribution*: Analyze the degree of similarity between vectors.\n",
"- *Cluster Distribution*: Observe how embeddings group together, potentially indicating similarities in meaning.\n",
"- *Descriptive Analytics*: Provide statistical descriptions of the embedding space.\n",
"- *Stability Analysis Keyword*: Test embeddings stability against keyword variations.\n",
"- *Stability Analysis Random Noise*: Assess how random noise affects the stability of embeddings.\n",
"- *Stability Analysis Synonyms*: Evaluate the consistency of embeddings for synonymous words."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from transformers import pipeline\n",
"\n",
"embedding_model = pipeline(\n",
" \"feature-extraction\",\n",
" model=\"bert-base-uncased\",\n",
" tokenizer=\"bert-base-uncased\",\n",
" truncation=True,\n",
")\n",
"\n",
"vm_embedding_model = vm.init_model(\n",
" model=embedding_model,\n",
" input_id=\"bert_embedding_model\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vm_test_ds.assign_predictions(\n",
" model=vm_embedding_model,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.CosineSimilarityDistribution\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
")\n",
"test.log()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.ClusterDistribution\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
")\n",
"test.log()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.DescriptiveAnalytics\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
")\n",
"test.log()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.StabilityAnalysisKeyword\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
" params={\n",
" \"text_column\": \"article\",\n",
" \"keyword_dict\": {\"finance\": \"financial\"},\n",
" },\n",
")\n",
"test.log()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.StabilityAnalysisRandomNoise\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
" params={\n",
" \"text_column\": \"article\",\n",
" },\n",
")\n",
"test.log()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test = vm.tests.run_test(\n",
" \"validmind.model_validation.embeddings.StabilityAnalysisSynonyms\",\n",
" inputs={\n",
" \"dataset\": vm_test_ds,\n",
" \"model\": vm_embedding_model,\n",
" },\n",
" params={\n",
" \"text_column\": \"article\",\n",
" \"probability:\": 0.1,\n",
" },\n",
")\n",
"test.log()"
"This section is dedicated to the assessment of the AI model's understanding and processing of language data. It involves running various model performance tests, ensuring the model's output is as expected and reliable."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@
"# load openai api key\n",
"import os\n",
"\n",
"from dotenv import load_dotenv\n",
"import dotenv\n",
"import nltk\n",
"\n",
"load_dotenv()\n",
"dotenv.load_dotenv()\n",
"nltk.download('stopwords')\n",
"\n",
"# os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"\n",
"\n",
Expand Down
Loading