From 80b33b9e0c5fba1fcaf7a62c529c3f2614160368 Mon Sep 17 00:00:00 2001 From: Luis Quintanilla <46974588+luisquintanilla@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:50:54 +0000 Subject: [PATCH] Update notebooks and broken data --- .devcontainer/ai/Dockerfile | 10 +- .../Notebooks/03-Introduction-ChatGPT.ipynb | 82 ++++++----- .../04-Prompts-Prompt-Engineering.ipynb | 63 ++++----- ...trieval-Augmented-Generation-Context.ipynb | 128 ++++++++---------- .../07-Introduction-AI-Services.ipynb | 6 +- .../Notebooks/08-Train-AI-Services.ipynb | 4 +- .../Notebooks/10-Introduction-AutoML.ipynb | 107 ++++++++++----- .../sample-code/scripts/download-data.ps1 | 2 +- .../sample-code/scripts/download-data.sh | 2 +- 9 files changed, 210 insertions(+), 194 deletions(-) mode change 100644 => 100755 Artificial Intelligence and Machine Learning/sample-code/scripts/download-data.sh diff --git a/.devcontainer/ai/Dockerfile b/.devcontainer/ai/Dockerfile index 793fc1a..235d7eb 100644 --- a/.devcontainer/ai/Dockerfile +++ b/.devcontainer/ai/Dockerfile @@ -1,7 +1,7 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 -RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb -RUN dpkg -i packages-microsoft-prod.deb -RUN rm packages-microsoft-prod.deb -RUN apt update && apt upgrade -y && apt install unzip curl dotnet-sdk-6.0 -y +FROM mcr.microsoft.com/dotnet/sdk:8.0 +# RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +# RUN dpkg -i packages-microsoft-prod.deb +# RUN rm packages-microsoft-prod.deb +# RUN apt update && apt upgrade -y && apt install unzip curl dotnet-sdk-8.0 -y RUN dotnet tool install -g mlnet-linux-x64 ENV PATH="$PATH:/root/.dotnet/tools" \ No newline at end of file diff --git a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/03-Introduction-ChatGPT.ipynb b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/03-Introduction-ChatGPT.ipynb index 4188ce9..5349fcf 100644 --- a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/03-Introduction-ChatGPT.ipynb +++ b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/03-Introduction-ChatGPT.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -29,7 +29,7 @@ { "data": { "text/html": [ - "
Installed Packages
" + "
Installed Packages
" ] }, "metadata": {}, @@ -37,13 +37,13 @@ } ], "source": [ - "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.6\"\n", - "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.23313.2\"" + "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.15\"\n", + "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.24164.1\"" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 14, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -160,6 +160,7 @@ "source": [ "var options = new ChatCompletionsOptions\n", "{\n", + " DeploymentName=deploymentId,\n", " MaxTokens=400,\n", " Temperature=1f,\n", " FrequencyPenalty=0.0f,\n", @@ -177,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -188,7 +189,7 @@ }, "outputs": [], "source": [ - "options.Messages.Add(new ChatMessage(ChatRole.System, systemPrompt));" + "options.Messages.Add(new ChatRequestSystemMessage(systemPrompt));" ] }, { @@ -200,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -216,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 17, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -236,30 +237,41 @@ "2. What hiking intensity they are looking for\n", "\n", "You will then provide three suggestions for nearby hikes that vary in length after you get that information. You will also share an interesting fact about the local nature on the hikes when making a recommendation.\n", - "User: Hi\n", - "Assistant: Hello there! My name is [Your Name], and I'm here to help you find some fun hikes in your area. Before we get started, can you please let me know where you are located and what hiking intensity you are looking for?\n", - "User: I want to hike in the Hudson Valley\n", - "Assistant: Great choice! The Hudson Valley is known for its beautiful scenery and great hiking trails. Can you please let me know what kind of hiking intensity you are looking for? Are you looking for something easy, moderate or strenuous?\n", - "User: Easy\n", - "Assistant: Sure thing! Here are three nearby hikes in the Hudson Valley that I think you might enjoy:\n", - "\n", - "1. Poet's Walk Park - This is an easy 2-mile hike in Red Hook, NY that has stunning views of the Hudson River. The park is named after Washington Irving, who was inspired by the beauty of the landscape. Fun fact: The park features a beautiful gazebo that was built to honor the 200th anniversary of Irving's birth.\n", + "User: I'm looking to hike in the Hudson Valley area. Nothing too strenuous.\n", + "Assistant: Hello there! I'm glad to help you with your hiking plans in the beautiful Hudson Valley area. The Hudson Valley offers a fantastic range of trails for all levels of hikers. Could you please let me know where exactly in the Hudson Valley you are located, and what kind of hiking intensity you are looking for? That way, I can recommend some great trails that suit your preferences.\n", "\n", - "2. Walkway Over the Hudson State Historic Park - This is a flat, easy 1.25-mile hike that offers stunning views of the Hudson River and the surrounding landscape. It's also a great spot for birdwatching. Fun fact: The Walkway is the longest pedestrian bridge in the world!\n", + "Once I have that information, I'll be able to provide you with three different hiking options, varying in length and intensity. And of course, I'll include some interesting facts about the local nature along the trails!\n", + "User: Beacon, NY and I want something low intensity\n", + "Assistant: Great! Based on your location in Beacon, NY, and your preference for low-intensity hiking, here are three wonderful options for you:\n", "\n", - "3. Esopus Creek Conservancy - This is an easy 1.5-mile hike in Saugerties, NY that takes you through forests, fields, and streams. The preserve has several trails to explore, and the views of the Esopus Creek are stunning. Fun fact: The Esopus Creek is a popular spot for trout fishing, and you might even catch a glimpse of a bald eagle flying overhead!\n", + "1. Dennings Point Loop Trail: This trail is approximately 2.5 miles long and offers a gentle hike along the Hudson River. You'll enjoy scenic views of the river, marshes, and wooded areas. Keep an eye out for bald eagles that are often spotted in this area!\n", "\n", - "I hope these recommendations help, and let me know if you have any questions or if there's anything else I can do for you.\n", - "User: Format this as a table\n", - "Assistant: Sure, here are the same three hiking recommendations in a table format:\n", + "2. Madam Brett Park Loop: Located near the heart of Beacon, this loop trail is about 1.5 miles long and takes you through a tranquil park with beautiful waterfalls, historical ruins, and lovely wooded sections. Fun fact: Madam Brett Park is named after an 18th-century ironmaster's wife who played a significant role in the local iron industry.\n", "\n", - "| Hike | Location | Length | Fun Fact |\n", - "|------|----------|--------|----------|\n", - "| Poet's Walk Park | Red Hook, NY | 2 miles | The park features a gazebo built to honor Washington Irving's 200th birth anniversary |\n", - "| Walkway Over the Hudson State Historic Park | Poughkeepsie, NY | 1.25 miles | The Walkway is the longest pedestrian bridge in the world |\n", - "| Esopus Creek Conservancy | Saugerties, NY | 1.5 miles | The Esopus Creek is a popular spot for trout fishing and bald eagle sightings | \n", + "3. Fishkill Ridge Trail: This trail, approximately 3.5 miles long, offers a bit more of a challenge but still manageable for a low-intensity hike. You'll be rewarded with breathtaking views of the Hudson Valley, including the charming village of Cold Spring. Keep an eye out for interesting rock formations and unique plant species along the way.\n", "\n", - "I hope this format makes it easier to compare the hikes and choose one that fits your needs. Let me know if you have any questions!\n" + "I hope you find these suggestions helpful! Enjoy your hike in Beacon, and don't forget to take in the stunning natural beauty that the Hudson Valley has to offer.\n" + ] + }, + { + "ename": "Error", + "evalue": "Input request cancelled", + "output_type": "error", + "traceback": [ + "Input request cancelled" + ] + }, + { + "ename": "Error", + "evalue": "System.Exception: Input request cancelled\n at Microsoft.DotNet.Interactive.Kernel.GetInputAsync(String prompt, Boolean isPassword, String typeHint, String valueName) in D:\\a\\_work\\1\\s\\src\\Microsoft.DotNet.Interactive\\Kernel.Static.cs:line 72\n at Microsoft.DotNet.Interactive.Kernel.GetInputAsync(String prompt, String typeHint, String valueName) in D:\\a\\_work\\1\\s\\src\\Microsoft.DotNet.Interactive\\Kernel.Static.cs:line 46\n at Submission#16.<>d__0.MoveNext()\n--- End of stack trace from previous location ---\n at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)", + "output_type": "error", + "traceback": [ + "System.Exception: Input request cancelled\n", + " at Microsoft.DotNet.Interactive.Kernel.GetInputAsync(String prompt, Boolean isPassword, String typeHint, String valueName) in D:\\a\\_work\\1\\s\\src\\Microsoft.DotNet.Interactive\\Kernel.Static.cs:line 72\n", + " at Microsoft.DotNet.Interactive.Kernel.GetInputAsync(String prompt, String typeHint, String valueName) in D:\\a\\_work\\1\\s\\src\\Microsoft.DotNet.Interactive\\Kernel.Static.cs:line 46\n", + " at Submission#16.<>d__0.MoveNext()\n", + "--- End of stack trace from previous location ---\n", + " at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)" ] } ], @@ -274,11 +286,11 @@ " break; \n", " }\n", " Console.WriteLine($\"User: {userPrompt}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.User, userPrompt));\n", - " var assistantResponse = await client.GetChatCompletionsAsync(deploymentId, options);\n", + " options.Messages.Add(new ChatRequestUserMessage(userPrompt));\n", + " var assistantResponse = await client.GetChatCompletionsAsync(options);\n", " var response = assistantResponse.Value.Choices[0].Message.Content;\n", " Console.WriteLine($\"Assistant: {response}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.Assistant, response));\n", + " options.Messages.Add(new ChatRequestAssistantMessage(response));\n", "};\n", "options.Messages.Clear();" ] diff --git a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/04-Prompts-Prompt-Engineering.ipynb b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/04-Prompts-Prompt-Engineering.ipynb index 581fd50..d80cd65 100644 --- a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/04-Prompts-Prompt-Engineering.ipynb +++ b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/04-Prompts-Prompt-Engineering.ipynb @@ -29,7 +29,7 @@ { "data": { "text/html": [ - "
Installed Packages
  • Azure.AI.OpenAI, 1.0.0-beta.6
  • Microsoft.DotNet.Interactive, 1.0.0-beta.23313.2
" + "
Installed Packages
  • Azure.AI.OpenAI, 1.0.0-beta.15
  • Microsoft.DotNet.Interactive, 1.0.0-beta.24164.1
" ] }, "metadata": {}, @@ -37,8 +37,8 @@ } ], "source": [ - "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.6\"\n", - "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.23313.2\"" + "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.15\"\n", + "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.24164.1\"" ] }, { @@ -145,6 +145,7 @@ "source": [ "var options = new ChatCompletionsOptions\n", "{\n", + " DeploymentName=deploymentId,\n", " MaxTokens=400,\n", " Temperature=1f,\n", " FrequencyPenalty=0.0f,\n", @@ -162,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -173,7 +174,7 @@ }, "outputs": [], "source": [ - "var systemMessage = new ChatMessage(ChatRole.System, genericSystemPrompt);\n", + "var systemMessage = new ChatRequestSystemMessage(genericSystemPrompt);\n", "options.Messages.Add(systemMessage);" ] }, @@ -186,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -202,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -217,20 +218,8 @@ "output_type": "stream", "text": [ "System: You are an AI assistant that helps people find information about your business\n", - "User: I'd like to get some pizza\n", - "Assistant: Certainly! Would you like some recommendations for pizza places in your area or would you like information about our business specifically?\n", - "User: pizza in the area\n", - "Assistant: Sure, could you please provide me with your location or zip code so I can look up pizza places nearby?\n", - "User: Chicago\n", - "Assistant: Great! Here are a few pizza places in Chicago:\n", - "\n", - "1. Lou Malnati's Pizzeria\n", - "2. Giordano's\n", - "3. Pequod's Pizza\n", - "4. Gino's East\n", - "5. Pizzeria Uno\n", - "\n", - "I hope this helps! Let me know if you need any further assistance.\n" + "User: I want pizza\n", + "Assistant: Great! I can help you find a pizza place nearby. Could you please provide me with your location or a specific area?\n" ] } ], @@ -245,11 +234,11 @@ " break; \n", " }\n", " Console.WriteLine($\"User: {userPrompt}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.User, userPrompt));\n", - " var assistantResponse = await client.GetChatCompletionsAsync(deploymentId, options);\n", + " options.Messages.Add(new ChatRequestUserMessage(userPrompt));\n", + " var assistantResponse = await client.GetChatCompletionsAsync(options);\n", " var response = assistantResponse.Value.Choices[0].Message.Content;\n", " Console.WriteLine($\"Assistant: {response}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.Assistant, response));\n", + " options.Messages.Add(new ChatRequestAssistantMessage(response));\n", "};\n", "options.Messages.Clear();" ] @@ -263,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -313,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -324,12 +313,12 @@ }, "outputs": [], "source": [ - "options.Messages.Add(new ChatMessage(ChatRole.System, systemPrompt));" + "options.Messages.Add(new ChatRequestSystemMessage(systemPrompt));" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -345,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -391,12 +380,10 @@ "\n", "User: I'm interested in reselling some of your products in my shop. \n", "Assistant: Sure, our billing department is able to help. Here is their number, 1-800-111-1113. \n", - "User: Hi\n", - "Assistant: Hi there! How may I assist you today?\n", - "User: I want to return some equipment I bought last week\n", - "Assistant: I'm sorry to hear that you need to return some equipment. I can assist you with that. Please contact our returns department at 1-800-111-1113. They will be able to assist you with the return or exchange process.\n", - "User: I want to order a milkshake\n", - "Assistant: I'm sorry, but we are an outdoor equipment business and we don't sell milkshakes or food products. Is there anything else I can help you with related to our business?\n" + "User: I want to return some equipment\n", + "Assistant: Sorry to hear that you want to return some equipment. Here is the contact information for the returns department: 1-800-111-1113.\n", + "User: I want a milkshake\n", + "Assistant: Sorry, but we don't offer milkshakes. We are an outdoor equipment company. Is there anything else I can assist you with?\n" ] } ], @@ -411,11 +398,11 @@ " break; \n", " }\n", " Console.WriteLine($\"User: {userPrompt}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.User, userPrompt));\n", - " var assistantResponse = await client.GetChatCompletionsAsync(deploymentId, options);\n", + " options.Messages.Add(new ChatRequestUserMessage(userPrompt));\n", + " var assistantResponse = await client.GetChatCompletionsAsync(options);\n", " var response = assistantResponse.Value.Choices[0].Message.Content;\n", " Console.WriteLine($\"Assistant: {response}\");\n", - " options.Messages.Add(new ChatMessage(ChatRole.Assistant, response));\n", + " options.Messages.Add(new ChatRequestAssistantMessage(response));\n", "};\n", "options.Messages.Clear();" ] diff --git a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/05-Retrieval-Augmented-Generation-Context.ipynb b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/05-Retrieval-Augmented-Generation-Context.ipynb index 21b210d..341993d 100644 --- a/Artificial Intelligence and Machine Learning/sample-code/Notebooks/05-Retrieval-Augmented-Generation-Context.ipynb +++ b/Artificial Intelligence and Machine Learning/sample-code/Notebooks/05-Retrieval-Augmented-Generation-Context.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -32,7 +32,7 @@ { "data": { "text/html": [ - "
Installed Packages
  • Azure.AI.OpenAI, 1.0.0-beta.6
  • Microsoft.DotNet.Interactive, 1.0.0-beta.23313.2
" + "
Installed Packages
  • Azure.AI.OpenAI, 1.0.0-beta.15
  • Microsoft.DotNet.Interactive, 1.0.0-beta.24164.1
  • System.Numerics.Tensors, 8.0.0
" ] }, "metadata": {}, @@ -40,13 +40,14 @@ } ], "source": [ - "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.6\"\n", - "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.23313.2\"" + "#r \"nuget: Azure.AI.OpenAI, 1.0.0-beta.15\"\n", + "#r \"nuget: Microsoft.DotNet.Interactive, 1.0.0-beta.24164.1\"\n", + "#r \"nuget: System.Numerics.Tensors, 8.0.0\"" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 10, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -65,7 +66,8 @@ "using System.Linq;\n", "using System.Text.Json;\n", "using Azure.AI.OpenAI;\n", - "using Microsoft.DotNet.Interactive;" + "using Microsoft.DotNet.Interactive;\n", + "using System.Numerics.Tensors;" ] }, { @@ -77,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 11, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -106,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -132,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -165,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 14, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -204,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -218,19 +220,19 @@ }, "outputs": [], "source": [ - "string FormatMessage(ChatMessage m)\n", + "string FormatMessage(ChatRequestMessage m)\n", "{\n", " if(m.Role == ChatRole.System)\n", - " return $\"System: {m.Content}\";\n", + " return $\"System: {((ChatRequestSystemMessage)m).Content }\";\n", " else if(m.Role == ChatRole.User)\n", - " return $\"User: {m.Content}\";\n", + " return $\"User: {((ChatRequestUserMessage)m).Content}\";\n", " else if(m.Role == ChatRole.Assistant)\n", - " return $\"Assistant: {m.Content}\";\n", + " return $\"Assistant: {((ChatRequestAssistantMessage)m).Content}\";\n", " else\n", - " return m.Content;\n", + " return m.ToString();\n", "}\n", "\n", - "var RenderUserPrompt = (List history, string[] documents, string query) => \n", + "var RenderUserPrompt = (List history, string[] documents, string query) => \n", " {\n", " var chatMessages = \n", " history\n", @@ -257,37 +259,12 @@ " return template;\n", " };\n", "\n", - "var CosineSimilarity = (float[] vectorA, float[] vectorB) => \n", - "{\n", - " if (vectorA == null || vectorB == null)\n", - " throw new ArgumentNullException(\"Input vectors cannot be null.\");\n", - "\n", - " if (vectorA.Length != vectorB.Length)\n", - " throw new ArgumentException(\"Input vectors must have the same length.\");\n", - "\n", - " double dotProduct = 0;\n", - " double normA = 0;\n", - " double normB = 0;\n", - "\n", - " for (int i = 0; i < vectorA.Length; i++)\n", - " {\n", - " dotProduct += vectorA[i] * vectorB[i];\n", - " normA += vectorA[i] * vectorA[i];\n", - " normB += vectorB[i] * vectorB[i];\n", - " }\n", - "\n", - " if (normA == 0 || normB == 0)\n", - " throw new ArgumentException(\"Input vectors cannot be zero vectors.\");\n", - "\n", - " return dotProduct / (Math.Sqrt(normA) * Math.Sqrt(normB));\n", - "};\n", - "\n", "var GetTopKDocuments = (Document[] sources, float[] userQueryEmbedding, int k) => \n", "{\n", " return sources\n", " .Select(document => \n", " {\n", - " var similarity = CosineSimilarity(document.Embedding, userQueryEmbedding);\n", + " var similarity = TensorPrimitives.CosineSimilarity(document.Embedding, userQueryEmbedding);\n", " return (similarity, document);\n", " })\n", " .OrderByDescending(x => x.Item1)\n", @@ -306,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -333,7 +310,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 17, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -349,7 +326,7 @@ { "data": { "text/html": [ - "
Submission#6+Document
Embedding
[ 0.0150072165, 0.009965043, 0.010806452, -0.031345617, -0.00073584024, -0.010448539, -0.0044425125, -0.015120241, -0.016526775, 0.001671829, 0.02639763, 0.014253716, -0.034686133, -0.01564769, -0.046415623, 0.0055319485, 0.018397968, 0.007905475, 0.007930592, -0.023685029 ... (1516 more) ]
Metadata
Submission#6+Metadata
Title24-hour clock
TextThe 24-hour clock is a way of telling the time in which the day runs from midnight to midnight and is divided into 24 hours, numbered from 0 to 23. It does not use a.m. or p.m. This system is also referred to (only in the US and the English speaking parts of Canada) as military time or (only in the United Kingdom and now very rarely) as continental time. In some parts of the world, it is called railway time. Also, the international standard notation of time (ISO 8601) is based on this format.
WikiId
9985
ParagraphId
0