Nvidia Unveils Futuristic Gaming Experience at Computex 2023
News

Nvidia Unveils Futuristic Gaming Experience at Computex 2023, Blending Gaming and AI

by Isabel
May 29, 2023
0

At Computex 2023, Nvidia displays a futuristic gaming experience that...

Read more
Adobe Introduces Powerful Generative AI Tools in Photoshop

Adobe Introduces Powerful Generative AI Tools in Photoshop Beta

May 29, 2023
Adobe Photoshop's Generative Fill Feature

Exploring the Power of Adobe Photoshop’s Generative Fill Feature

May 27, 2023
NVIDIA and Microsoft Partner to Accelerate AI

NVIDIA and Microsoft Partner to Accelerate AI

May 25, 2023
google photos security and privacy

Exploring the Top 5 Privacy and Security Risks of using Google Photos

May 24, 2023
Marvin AI A Powerful Tool for Building AI-Powered Software

Marvin AI: A Powerful Tool for Building AI-Powered Software

May 18, 2023
ChatGPT Clone

ChatGPT Clone Development: A Complete Guide

April 28, 2023
AudioGPT

AudioGPT: The Future of Automated Audio Production

May 4, 2023
7 Harmful Effects of Artificial Intelligence

7 Harmful Effects of Artificial Intelligence (AI) – WARNING

February 14, 2023
AutoGPT and ChatGPT

AutoGPT and ChatGPT: Discovering the World of AI Language Models

May 4, 2023
Create Chatbot using ChatGPT

How to Build an AI Chatbot Using the ChatGPT API

April 17, 2023
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Artificial Intelligence

Semantic Kernel for Natural Language Processing

by Hollie
May 29, 2023
in Artificial Intelligence
Reading Time: 10 mins read
Semantic kernel
Share on FacebookShare on TwitterShare on WhatsAppShare on Telegram

Natural language processing (NLP) benefits greatly from semantic kernels. By expressing words as high-dimensional vectors rather than simply strings of letters, they enable computers to interpret the meaning of words in a more complex way. This enables computers to detect word associations, such as synonyms and antonyms, without the requirement for explicit rules or human supervision.

Table of Contents

  1. What is Semantic Kernel?
  2. Orchestrating AI with Semantic Kernel
  3. How to use Semantic Kernel
  4. Requirements to run the guides.
  5. Download and run the Guides.

What is Semantic Kernel?

Semantic Kernel (SK) is a lightweight SDK that allows AI Large Language Models (LLMs) to be integrated with traditional programming languages. The SK extensible programming model combines natural language semantic functions, conventional code native functions, and embeddings-based memory to unlock new possibilities and provide value to AI-powered systems.

You might also like

ChatGPT app

The Easiest Way to Download ChatGPT App Free

May 31, 2023
LLM Connected with APIs

Gorilla: LLM Connected with APIs

May 31, 2023

SDK that allows you to quickly combine AI prompts with traditional programming languages such as C# and Python.

Orchestrating AI with Semantic Kernel

The real power of Semantic Kernel derives from its ability to mix various components. You may design sophisticated pipelines that employ AI to automate complicated operations by combining several AI models, native functions, and memory within Semantic Kernel.

For example, you might utilize Semantic Kernel to build a pipeline that assists a user in sending an email to their marketing staff. With memory, you might obtain project information and then utilize planner to autogenerate the next stages (for example, grounding the user’s request with Microsoft Graph data, generating a response with GPT-4, and sending the email). Finally, in your custom app, you may display a success message to the user.

Semantic Kernel


The steps described outline the process of interacting with the Semantic Kernel in an AI application. Here’s a breakdown of each step:

StepComponentDescription
1AskThe user or developer sends a goal or request to the Semantic Kernel.
2KernelOrchestrates the user’s request and runs a pipeline or chain of functions defined by the developer. Provides a common context for data sharing between functions.
2.1MemoriesAllows developers to recall and store context in vector databases, simulating memory within the AI application.
2.2PlannerEnables the automatic creation of chains or pipelines to address new or novel user needs. Can utilize existing plugins to create additional steps.
2.3ConnectorsProvides out-of-the-box connectors to retrieve additional data or perform autonomous actions. Developers can use pre-built connectors or create custom connectors for their own services.
2.4Custom functionsDevelopers can create custom functions that run inside the Semantic Kernel. These can be semantic functions (LLM prompts) or native code (C# or Python) to add new AI capabilities and integrate existing apps and services.
3ResponseThe generated response is sent back to the user to indicate that the requested task or goal has been completed.

How to use Semantic Kernel

You can run the Semantic Kernel getting started guidelines in C# or Python in only a few steps. After finishing the tutorials, you’ll be able to…

  • Configure your local machine to run Semantic Kernel
  • Run prompts from the kernel.
  • Make prompts dynamic with variables.
  • Create prompt chains.
  • Automatically create new chains with the planner
  • Store and retrieve memory with embeddings.

Requirements to run the guides.

Before running the guides in C#, make sure you have the following installed on your local machine. If you are using the Python guides, you just need git and python.

  • git or the GitHub application
  • VSCode vs. Visual Studio
  • An OpenAI key obtained using the Azure OpenAI Service or OpenAI
  • .Net 7 SDK – C# notebook documentation
  • The Polyglot Notebook in VS Code – for notebook instructions

C#

1. Create a new console app.

2. Add the semantic kernel nuget 

#r "nuget: Microsoft.SemanticKernel, *-*"

3. Copy the code from here into the app Program.cs file.

4. Replace the configuration placeholders for API key and other params with your key and settings.

5. Run with F5 or dotnet run

Python

1. Install the pip package

pip install semantic-kernel

2. Create a new script e.g. hello-world.py.

3. Store your API key and settings in an .env file as described here.

4. Copy the code from here into the hello-world.py script.

5. Run the python script.

Download and run the Guides.

  1. Use your web browser to visit aka.ms/sk/repo on GitHub.
  2. Clone or fork the repo to your local machine.
  3. While the repository is open in VS Code, navigate to the semantic-kernel/samples/notebooks folder.
  4. Choose either the .Net or Python folder based on your preferred programming language.
  5. Open the 00-getting-started.ipynb notebook.
  6. Activate each code snippet with the “play” button on the left hand side. If you need help running the 00-getting-started.ipynb notebook, you can watch the video below.
  7. Repeat for the remaining notebooks.

Getting started with C# notebook

1: Configure your AI service credentials

Use this notebook first, to choose whether to run these notebooks with OpenAI or Azure OpenAI, and to save your credentials in the configuration file.

// Load some helper functions, e.g. to load values from settings.json
#!import config/Settings.cs

2: Import Semantic Kernel SDK from NuGet

// Import Semantic Kernel
#r "nuget: Microsoft.SemanticKernel, 0.14.547.1-preview"

3: Instantiate the Kernel

using Microsoft.SemanticKernel;

// Set Simple kernel instance
IKernel kernel = KernelBuilder.Create();
// Configure AI service credentials used by the kernel
var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();

if (useAzureOpenAI)
    kernel.Config.AddAzureTextCompletionService(model, azureEndpoint, apiKey);
else
    kernel.Config.AddOpenAITextCompletionService(model, apiKey, orgId);

4: Load and Run a Skill

// Load the Skills Directory
var skillsDirectory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..", "..", "skills");

// Load the FunSkill from the Skills Directory
var funSkillFunctions = kernel.ImportSemanticSkillFromDirectory(skillsDirectory, "FunSkill");

// Run the Function called Joke
var result = await funSkillFunctions["Joke"].InvokeAsync("time travel to dinosaur age");

// Return the result to the Notebook
Console.WriteLine(result);

Getting started with Python notebook

1. Import Semantic Kernel SDK from pypi.org

!python -m pip install semantic-kernel==0.2.7.dev0
import semantic_kernel as sk

kernel = sk.Kernel()

Using OpenAI

2. Add your Open AI Key key to a .env file in the same folder (org Id only if you have multiple orgs):

OPENAI_API_KEY="sk-..."
OPENAI_ORG_ID=""

and add OpenAI Text Completion to the kernel:

from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion

api_key, org_id = sk.openai_settings_from_dot_env()

kernel.add_text_completion_service("dv", OpenAITextCompletion("text-davinci-003", api_key, org_id))

Using Azure OpenAI

3. Add your Azure Open AI Service key settings to a .env file in the same folder:

AZURE_OPENAI_API_KEY="..."
AZURE_OPENAI_ENDPOINT="https://..."
AZURE_OPENAI_DEPLOYMENT_NAME="..."

and add Azure OpenAI Text Completion to the kernel:

from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion

deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()

kernel.add_text_completion_service("dv", AzureTextCompletion(deployment, endpoint, api_key))

Run a Semantic Function

4. Load a Skill and run a semantic function:

skill = kernel.import_semantic_skill_from_directory("../../skills", "FunSkill")
joke_function = skill["Joke"]

print(joke_function("time travel to dinosaur age"))

Also Read: Mr. Ranedeer: The AI Tutor That Can Help You Learn Anything

This article is to help you learn the semantic kernel. We trust that it has been helpful to you. Please feel free to share your thoughts and feedback in the comment section below.

Continue Reading
Share2Tweet1SendShare
Hollie

Hollie

Help us grow and support our blog! Your contribution can make a real difference in providing valuable content to our readers. Join us in our journey by supporting our blog today!
Buy me a Coffee

Related Posts

Soundstorm-Pytorch

Soundstorm-Pytorch: A Powerful Tool for Audio Generation

May 30, 2023
Midjourney vs Adobe Firefly

Midjourney vs Adobe Firefly: A Comparison of Two AI Image Generation Tools

May 30, 2023
ChatGPT

How to Use ChatGPT Code Interpreter

May 31, 2023
Leonardo AI Login

How to login and use Leonardo AI to generate high-quality image

May 30, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

Cloudbooklet

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS

Cloudbooklet © 2023 All rights reserved.

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.