By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
Cloudbooklet Logo
  • Artificial Intelligence
  • Applications
  • Linux
Notification

Free AI Image Generator

AI Tools
Cloudbooklet AICloudbooklet AI
Search
AI Tools
  • Artificial Intelligence
  • Applications
  • Google Cloud
  • Compute Engine
  • Linux

Top Stories

Explore the latest updated news!
Stable Video Diffusion

How to run Stable Video Diffusion img2vid- Guide

Turnitin Ai

How to Use Turnitin AI Writing Detection Checker Tool

Spotify Wrapped

Spotify Wrapped 2023: Everything You Need to Know

Follow US
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.

Home » Artificial Intelligence » Semantic Kernel for Natural Language Processing

Artificial Intelligence

Semantic Kernel for Natural Language Processing

Last updated: 2023/05/29 at 11:48 AM
By Hollie Moore
Semantic Kernel
SHARE
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

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.

Table of Contents
Table of ContentsWhat is Semantic Kernel?Orchestrating AI with Semantic KernelHow to use Semantic KernelRequirements to run the guides.Download and run the Guides.

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
Semantic Kernel for Natural Language Processing 1


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.

Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Reddit Telegram Copy Link Print
Share
Avatar Of Hollie Moore
By Hollie Moore
Follow:
Greetings, I am a technical writer who specializes in conveying complex topics in simple and engaging ways. I have a degree in computer science and journalism, and I have experience writing about software, data, and design. My content includes blog posts, tutorials, and documentation pages, which I always strive to make clear, concise, and useful for the reader. I am constantly learning new things and sharing my insights with others.
Leave a review Leave a review

Leave a review Cancel reply

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

Please select a rating!

Popular

Amazon Q Ai
How Amazon Q AI Assistant Can Boost Your AWS Productivity
Artificial Intelligence
Ai Nude Generator
14 Best Free AI Nude Generators to Create Fake AI Nude Online
Artificial Intelligence
Cloth Off Bot
8 Best Cloth Off Bot That Remove Cloth from Images
Artificial Intelligence
Ai Vs Machine Learning
AI vs Machine Learning: What’s the Difference and Which One is Right for You?”
Artificial Intelligence
- Advertisement -

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Related Stories

Uncover the stories that related to the post!
Stable Video Diffusion
Artificial Intelligence

How to run Stable Video Diffusion img2vid- Guide

Turnitin Ai
Artificial Intelligence

How to Use Turnitin AI Writing Detection Checker Tool

Spotify Wrapped
Artificial Intelligence

Spotify Wrapped 2023: Everything You Need to Know

Amazon Titan
Artificial Intelligence

How Amazon Titan Image Generator Can Revolutionize Generative AI

Cloudbooklet Logo
  • Categories:
  • Artificial Intelligence
  • Applications
  • Google Cloud

Quick Links

  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.
Welcome Back!

Sign in to your account

Lost your password?