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
What is langchain

Experience the Power of Langchain: The Next Generation of Language Learning

May 5, 2023
Stable Diffusion web UI

Stable Diffusion web UI: A Comprehensive Guide

May 30, 2023
How to use ChatGPT

ChatGPT: A Step-by-Step Guide to Using This Powerful AI Tool

May 15, 2023
Fairseq A Powerful Tool for Sequence Modeling

Fairseq: A Powerful Tool for Sequence Modeling

May 25, 2023
AI Ethics: How to Ensure Responsible Development and Use of Artificial Intelligence

AI Ethics: How to Ensure Responsible Development and Use of Artificial Intelligence

April 12, 2023
ChatGPT plugins

A Step-by-Step Guide to Enabling and Using ChatGPT Plugins

May 19, 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

Microsoft Guidance: The Next-Gen Prompt Programming Language

by Veronica
May 20, 2023
in Artificial Intelligence
Reading Time: 9 mins read
Microsoft Guidance The Next-Gen Prompt Programming Language
Share on FacebookShare on TwitterShare on WhatsAppShare on Telegram

Microsoft Guidance is a prompt programming language for the future generation that allows developers to control modern language models more effectively and efficiently than traditional prompting or chaining. Guidance programs enable developers to interleave generation, prompting, and logical control into a single continuous flow that corresponds to how the language model processes the text. As a result, the outcomes are more precise and consistent, as well as a more intuitive and productive development experience.

Table of Contents

  1. Microsoft Guidance
  2. Installation
  3. Chat Dialog Development with Guidance
  4. Agents
  5. Generation
  6. Features of Guidance

Microsoft Guidance

Guidance is an effective method for improving the control and efficiency of current language models (LLMs) such as GPT-3 and GPT-4. It enables you to integrate generation, prompting, and logical control into a continuous flow that corresponds to how the language model processes text.

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

The use of basic output structures such as Chain of Thought (CoT) and its variants such as ART (Adaptive Response Technology) and Auto-CoT is a common type of guiding. These structures have been shown to enhance the performance of LLMs. Guidance can enable more richer structures with the advent of more powerful LLMs like GPT-4, making it easier and more cost-effective to deal with them.

Installation

pip install guidance

How to use the “Microsoft guidance” package in a Jupyter/VSCode Notebook for live streaming of complex templates and generations. Here is the code:

  1. Importing the “guidance” package:
import guidance
  1. Setting the default language model:
guidance.llm = guidance.llms.OpenAI("text-davinci-003")

This line specifies the language model that will be utilized to execute the guidance programs. It’s set to OpenAI’s “text-davinci-003” model in this example. You can modify the model to meet your needs.

  1. Defining a guidance program:
program = guidance("""Tweak this proverb to apply to model instructions instead.

{{proverb}}
- {{book}} {{chapter}}:{{verse}}

UPDATED
Where there is no guidance{{gen 'rewrite' stop="\\n-"}}
- GPT {{gen 'chapter'}}:{{gen 'verse'}}""")

This code block uses a multi-line string to define a guidance program. Variable interpolation is used with double curly braces (e.g., proverb), as well as logical control flow with if statements and generations using gen commands. The program’s goal is to model instructions after a proverb.

  1. Executing the program:
executed_program = program(
    proverb="Where there is no guidance, a people falls,\nbut in an abundance of counselors there is safety.",
    book="Proverbs",
    chapter=11,
    verse=14
)

This code block executes the defined guidance program by calling the program object as a function and passing in the desired values for the variables. The executed program is stored in the executed_program variable.

  1. Accessing generated variables:
executed_program["rewrite"]

After executing the program, you can access the generated variables by accessing the keys of the executed_program dictionary. In this case, the generated variable with the key “rewrite” will contain the resulting text.

By using the “Guidance” package, you can iteratively develop and refine your prompts in a notebook environment, combining template-like syntax with language model generation and logical control flow.

Chat Dialog Development with Guidance

How to use the “Microsoft Guidance” package in a Jupyter/VSCode Notebook for interactive chat dialog development with chat models like GPT-4 or Vicuna. Here is the code:

  1. Connecting to a chat model:
gpt4 = guidance.llms.OpenAI("gpt-4")

This line establishes a connection to a chat model, in this case, GPT-4. You can use other chat models like Vicuna by instantiating the corresponding guidance.llms.transformers.Vicuna object.

  1. Defining a guidance program for chat dialog:
experts = guidance('''
{{#system~}}
You are a helpful and terse assistant.
{{~/system}}

{{#user~}}
I want a response to the following question:
{{query}}
Name 3 world-class experts (past or present) who would be great at answering this?
Don't answer the question yet.
{{~/user}}

{{#assistant~}}
{{gen 'expert_names' temperature=0 max_tokens=300}}
{{~/assistant}}

{{#user~}}
Great, now please answer the question as if these experts had collaborated in writing a joint anonymous answer.
{{~/user}}

{{#assistant~}}
{{gen 'answer' temperature=0 max_tokens=500}}
{{~/assistant}}
''', llm=gpt4)

This code block defines a guidance program for the chat dialog. The program includes different role tags like {{#system}}, {{#user}}, and {{#assistant}} to represent the different participants in the conversation. Within each role tag, you can specify the desired instructions and use {{gen}} commands to generate responses from the chat model.

  1. Executing the chat dialog:
experts(query='How can I be more productive?')

To initiate the chat dialog, you call the experts object as a function and pass in the user query using the query parameter. This will execute the Microsoft Guidance program and generate a response from the chat model based on the defined instructions.

By using the “guidance” package, you can interactively develop chat dialogs that combine rich templating, logical control, and chat model responses. This allows for dynamic and interactive conversations with the language model.

Also, Read Mojo programming language exclusive for AI.

Agents

You may use the await command within a loop to pause and resume execution of a partially performed Microsoft Guidance program to simulate a dialogue between two agents using the “guidance” package. Here’s an example:

import guidance
import re
guidance.llm = guidance.llms.OpenAI("gpt-4")
role_simulator = guidance('''
{{#system~}}
You are a helpful assistant
{{~/system}}
                                           
{{#user~}}
You will answer the user as {{role}} in the following conversation. At every step, I will provide you with the user input, as well as a comment reminding you of your instructions. Never talk about the fact that you are an AI, even if the user asks you. Always answer as {{role}}.
{{#if first_question}}You can also start the conversation.{{/if}}
{{~/user}}
                                           
{{~! The assistant either starts the conversation or not, depending on if this is the first or second agent }}
{{#assistant~}}
Ok, I will follow these instructions.
{{#if first_question}}Let me start the conversation now:
{{role}}: {{first_question}}{{/if}}
{{~/assistant}}

{{~! Then the conversation unrolls }}
{{~#geneach 'conversation' stop=False}}
{{#user~}}
User: {{set 'this.input' (await 'input')}}
Comment: Remember, answer as a {{role}}. Start your utterance with {{role}}:
{{~/user}}

{{#assistant~}}
{{gen 'this.response' temperature=0 max_tokens=300}}
{{~/assistant}}
{{~/geneach}}''')

republican = role_simulator(role='Republican', await_missing=True)
democrat = role_simulator(role='Democrat', await_missing=True)

first_question = '''What do you think is the best way to stop inflation?'''
republican = republican(input=first_question, first_question=None)
democrat = democrat(input=republican["conversation"][-2]["response"].strip('Republican: '), first_question=first_question)
for i in range(2):
    republican = republican(input=democrat["conversation"][-2]["response"].replace('Democrat: ', ''))
    democrat = democrat(input=republican["conversation"][-2]["response"].replace('Republican: ', ''))
print('Democrat: ' + first_question)
for x in democrat['conversation'][:-1]:
    print('Republican:', x['input'])
    print()
    print(x['response'])

Generation

Basic generation

The gen tag is used to generate text. You can use whatever arguments are supported by the underlying model. Executing a prompt calls the generation prompt:

import guidance
# Set the default llm. Could also pass a different one as argument to guidance(), with guidance(llm=...)
guidance.llm = guidance.llms.OpenAI("text-davinci-003")
prompt = guidance('''The best thing about the beach is {{~gen 'best' temperature=0.7 max_tokens=7}}''')
prompt = prompt()
prompt

guidance caches all OpenAI generations with the same arguments. If you want to flush the cache, you can call guidance.llms.OpenAI.cache.clear().

Hidden generation

You can generate text without displaying it or using it in the subsequent generations using the hidden tag, either in a block or in a gen tag:

prompt = guidance('''{{#block hidden=True}}Generate a response to the following email:
{{email}}.
Response:{{gen "response"}}{{/block}}
I will show you an email and a response, and you will tell me if it's offensive.
Email: {{email}}.
Response: {{response}}
Is the response above offensive in any way? Please answer with a single word, either "Yes" or "No".
Answer:{{#select "answer" logprobs='logprobs'}} Yes{{or}} No{{/select}}''')
prompt = prompt(email='I hate tacos')
prompt

Features of Guidance

  1. Simple Syntax: Microsoft Guidance has a basic and accessible syntax based on Handlebars templating. This syntax makes it simple to specify and alter the produced text’s output structure.
  2. Rich Output Structure: Microsoft Guidance enables the design of complicated output structures involving numerous generations, selects, conditionals, tool usage, and more. This adaptability allows for fine-grained control over the output text’s content and layout.
  3. Streaming in Jupyter/VSCode Notebooks: Microsoft Guidance provides a playground-like experience for interactive and iterative model creation in Jupyter/VSCode Notebooks. This feature makes it easier to experiment with and explore the model’s possibilities.
  4. Caching for Smart Seed-Based Generation: Microsoft Guidance includes clever caching methods that enhance the generation process. It minimizes duplicate computations and speeds up subsequent requests for comparable outputs by caching previously created text based on seed inputs.
  5. Role-Based Chat Model Support: Microsoft Guidance is designed to interact seamlessly with role-based chat models such as ChatGPT. This connection allows for context-aware discussions and improves the model’s capacity to recognize and respond to various roles or personas.
  6. Simple Integration with Hugging Face Models: Microsoft Guidance may be simply connected with Hugging Face model hub models. It includes a number of acceleration techniques to increase speed over ordinary prompting, token healing to optimize prompt borders, and regex pattern guides to impose certain formats or limits on the output text.

Overall, Microsoft Guidance offers a complete framework for regulating and optimizing the output of current language models, making it simpler to effectively and economically use their capabilities.

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

Share3Tweet2SendShare
Veronica

Veronica

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.

  • Trending
  • Comments
  • Latest
DragGAN The AI-Powered Image Editing Tool

DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

May 30, 2023
DragGAN AI editing Tool Install and Use DragGAN Photo Editor

DragGAN AI editing Tool Install and Use DragGAN Photo Editor

May 27, 2023
Bard API key

Everything You Need to Know About Google’s Bard API Key

May 20, 2023
Install PHP 8.1 on Ubuntu

How to Install or Upgrade PHP 8.1 on Ubuntu 20.04

May 17, 2023
DragGAN The AI-Powered Image Editing Tool

DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

75
Upgrade PHP version to PHP 7.4 on Ubuntu

Upgrade PHP version to PHP 7.4 on Ubuntu

28
Install Odoo 13 on Ubuntu 18.04 with Nginx - Google Cloud

Install Odoo 13 on Ubuntu 18.04 with Nginx – Google Cloud

25
Best Performance WordPress with Google Cloud CDN and Load Balancing

Best Performance WordPress with Google Cloud CDN and Load Balancing

23
How to Setup SSH Keys on Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

May 31, 2023
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
Soundstorm-Pytorch

Soundstorm-Pytorch: A Powerful Tool for Audio Generation

May 30, 2023

Popular Articles

  • DragGAN The AI-Powered Image Editing Tool

    DragGAN: The AI-Powered Image Editing Tool That Makes Editing Images Easy

    1439 shares
    Share 576 Tweet 360
  • DragGAN AI editing Tool Install and Use DragGAN Photo Editor

    335 shares
    Share 134 Tweet 84
  • Auto-Photoshop-Stable Diffusion-Plugin: A New Way to Create AI-Generated Images in Photoshop

    70 shares
    Share 28 Tweet 18
  • InternGPT: A New Way to Interact with ChatGPT

    54 shares
    Share 22 Tweet 14
  • Midjourney vs Adobe Firefly: A Comparison of Two AI Image Generation Tools

    10 shares
    Share 4 Tweet 3
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.