Prompting language models is hard, while programming language models is easy. In this talk, I will discuss the state-of-the-art framework DSPy for programming foundation models with its powerful optimizers and runtime constraint system.
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
This document provides an overview of functional programming concepts in Ruby. It discusses the history and advantages of functional programming, comparing the functional and object-oriented paradigms. It introduces functional programming concepts like pure functions, recursion, immutable data, and higher-order functions. It demonstrates how these concepts can be applied in Ruby using functions, closures, currying, composition, and the Enumerable module. Overall, the document serves as a high-level introduction to thinking functionally in Ruby.
I am Cecily K. I am a Python Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Chicago, USA. I have been helping students with their homework for the past 10 years. I solve assignments related to Python Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Python Programming Assignments.
Ruby is a dynamic, open source object-oriented scripting language that is interpreted, not compiled. It supports features like garbage collection, exception handling, operator overloading, and just-in-time compilation. Ruby can be used for web development, system scripting, database programming, and GUI development. It uses classes and modules to support object-oriented programming concepts like inheritance, polymorphism, and mixins.
Banishing Loops with Functional Programming in PHPDavid Hayes
From a talk I've given a few time sat programming conferences about making your code better with functional programming principles. The example code is all PHP
This presentation was given online in July 2017 and will be given at the NY Java SIG later this year. It progressively builds on Java 8 concepts using puzzles and coding to give students confidence in their Java 8 stream/lambda skills. Handouts and code in https://github.com/boyarsky/java-8-streams-by-puzzles
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
Scala gives you awesome expressive power, but how to make best use of it? In my talk I will discuss the question what makes good Scala style. We will start with syntax and continue with how to name things, how to mix objects and functions, where (and where not) to use mutable state, and when to use which design pattern. As most questions of style, the discussion will be quite subjective, and some of it might be controversial. I am looking forward to discuss these topics with the conference attendees.
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01Tekblink Jeeten
This document contains summaries of 100 PHP interview questions and their answers. It discusses topics such as:
1. The differences between procedural and object-oriented programming in PHP.
2. Common PHP functions like include, require, urlencode, unlink, and image manipulation functions.
3. How to retrieve data from MySQL databases, submit forms, encrypt data, and get browser/server properties in PHP.
4. The major differences between PHP versions 3, 4, and 5.
5. How to configure aspects like upload file sizes and time zones in PHP applications.
Functions allow programmers to organize and reuse code. There are three types of functions: built-in functions, modules, and user-defined functions. User-defined functions are created using the def keyword and can take parameters and arguments. Functions can return values and have different scopes depending on if a variable is local or global. Recursion is when a function calls itself, and is useful for breaking down complex problems into simpler sub-problems. Common recursive functions calculate factorials, Fibonacci numbers, and generate the Pascal's triangle.
Scala is a multi-paradigm programming language that blends object-oriented and functional programming. It is designed to express common programming patterns in a concise, elegant, and type-safe way. Scala runs on the Java Virtual Machine and interoperates seamlessly with Java, but also integrates concepts from languages such as Haskell, ML and Ruby. Some key features of Scala include support for functional programming, a static type system with type inference, pattern matching, actors and immutable data structures.
1. The document describes the implementation of a K-means clustering algorithm from scratch in Python. It includes data normalization, K-means++ initialization, and evaluation using the Silhouette method.
2. Various techniques are tested to improve the algorithm, including normalization to handle differently scaled features, and K-means++ initialization to avoid poor initial centroid locations.
3. The algorithm outputs the centroid locations, a plot of Silhouette scores against K values, and a 3D plot visualizing the clustered data points and centroids.
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)Live Exam Helper
This is done by Python exam experts. This is the sample Python exam paper. If you have any query or doubt, you can visit Live Exam Helper. Our customer support is available 24x7 to assist you. If you need professional python exam help experts for your exam then you are at the right place. We have professional and experienced experts for all subjects. Our experts will help you ace your exams and get you the highest grades.
✅ Services that give priorities to deadlines
✅ Guarantee of money back
✅ The Clock or 24×7 hour services
✅ Security of good grades
This document provides an overview and introduction to CoffeeScript, a programming language that compiles to JavaScript. It shows how CoffeeScript code compiles to equivalent JavaScript code, and demonstrates CoffeeScript features like functions, classes, and object-oriented programming. The document introduces CoffeeScript syntax for arrays, objects, loops, and functions, and compares syntax to JavaScript. It also covers CoffeeScript concepts like scoping, context, and class-based object-oriented programming using prototypes.
The document provides a summary of 30 most commonly asked coding interview questions organized by difficulty level. It includes questions related to data structures and algorithms like binary tree, linked list, array, string, sorting, and searching. It also provides information about courses offered by Tutort on data science, machine learning, full stack development, and benefits of joining their programs like 1:1 mentorship and job assistance.
CPAP.com Introduction to Coding: Part 1johnnygoodman
This document provides an introduction to coding concepts. It discusses storing values in variables and data types like strings and integers. Key coding concepts covered include comments, running code, comparisons, arrays, and if/else statements. The document outlines what future sessions will cover, including loops, classes, methods, connecting to databases, and using other people's code.
The document describes the evolution of search functionality on the website Business of Fashion (BoF) using an evolutionary algorithm approach. It discusses how initial search parameters were set randomly for a population, then a fitness function evaluated each configuration and the top performers were used to breed new configurations with occasional mutations. This process continued over generations, gradually improving results by exploring a vast number of possible parameter combinations without needing manual trial and error. Eventually an optimal set of search parameters was found that accurately handled different query types and ranked results as intended.
The document discusses polymorphism and overloading in Python. Polymorphism means having many forms and allows the same method to behave differently depending on the object that calls it. Overloading refers to using the same name for functions or operators but with different signatures. The key points are:
1. Polymorphism is demonstrated through method overriding where subclasses have different implementations of the same method.
2. Operator overloading allows operators like + and * to work on custom classes by defining magic methods like __add__ and __mul__.
3. Method overloading is not supported in Python but can be simulated with default arguments or variable number of arguments.
4. Constructor overloading is also not supported
"S"OLID Principles - Single responsibility principleNishant Upadhyay
This slides will explain you how to use SOLID principles, its benefit with Ruby code example. SOLID principle helps for designing your code in more better way.
How CXAI Toolkit uses RAG for Intelligent Q&AZilliz
Manasi will be talking about RAG and how CXAI Toolkit uses RAG for Intelligent Q&A. She will go over what sets CXAI Toolkit's Intelligent Q&A apart from other Q&A systems, and how our trusted AI layer keeps customer data safe. She will also share some current challenges being faced by the team.
Multimodal Embeddings (continued) - South Bay Meetup SlidesZilliz
Frank Liu will walk through the history of embeddings and how we got to the cool embedding models used today. He'll end with a demo on how multimodal RAG is used.
Ensuring Secure and Permission-Aware RAG DeploymentsZilliz
In this talk, we will explore the critical aspects of securing Retrieval-Augmented Generation (RAG) deployments. The focus will be on implementing robust secured data retrieval mechanisms and establishing permission-aware RAG frameworks. Attendees will learn how to ensure that access control is rigorously maintained within the model when ingesting documents, ensuring that only authorized personnel can retrieve data. We will also discuss strategies to mitigate risks of data leakage, unauthorized access, and insider threats in RAG deployments. By the end of this session, participants will have a clearer understanding of the best practices and tools necessary to secure their RAG deployments effectively.
Retrieval Augmented Generation Evaluation with RagasZilliz
Retrieval Augmented Generation (RAG) enhances chatbots by incorporating custom data in the prompt. Using large language models (LLMs) as judge has gained prominence in modern RAG systems. This talk will demo Ragas, an open-source automation tool for RAG evaluations. Christy will talk about and demo evaluating a RAG pipeline using Milvus and RAG metrics like context F1-score and answer correctness.
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Zilliz
Enterprises have traditionally prioritized data quantity, assuming more is better for AI performance. However, a new reality is setting in: high-quality data, not just volume, is the key. This shift exposes a critical gap – many organizations struggle to understand their existing data and lack effective curation strategies and tools. This talk dives into these data challenges and explores the methods of automating data curation.
It's your unstructured data: How to get your GenAI app to production (and spe...Zilliz
So you've successfully built a GenAI app POC for your company -- now comes the hard part: bringing it to production. Aparavi addresses the challenges of AI projects while addressing data privacy and PII. Our Service for RAG helps AI developers and data scientists to scale their app to 1000s to millions of users using corporate unstructured data. Aparavi’s AI Data Loader cleans, prepares and then loads only the relevant unstructured data for each AI project/app, enabling you to operationalize the creation of GenAI apps easily and accurately while giving you the time to focus on what you really want to do - building a great AI application with useful and relevant context. All within your environment and never having to share private corporate data with anyone - not even Aparavi.
The History of Embeddings & Multimodal EmbeddingsZilliz
Frank Liu will walk through the history of embeddings and how we got to the cool embedding models used today. He'll end with a demo on how multimodal RAG is used.
Using LLM Agents with Llama 3, LangGraph and MilvusZilliz
RAG systems are talked about in detail, but usually stick to the basics. In this talk, Stephen will show you how to build an Agentic RAG System using Langchain and Milvus.
How Vector Databases are Revolutionizing Unstructured Data Search in AI Appli...Zilliz
"Powered by the popularity of ChatGPT, Llama2, and other LLMs, we've seen a huge surge in interest for vector databases in 2023 and 2024. Vector databases are commonly used to connect relevant documents with LLMs, through a process called retrieval augmented generation (RAG). RAG has seen widespread adoption, from single-person startups to Fortune 500 companies.
Despite the popularity of vector databases for LLMs, they are more broadly applicable for a variety of different types of unstructured data, i.e. any type of data that does not conform to a predefined data model, such as text, images, audio, molecules, and graphs. In this talk, we'll discuss some of the use cases for vector databases across many types of unstructured data."
The presentation will delve into the ASIMOV project, a novel initiative that leverages Retrieval-Augmented Generation (RAG) to provide precise, domain-specific assistance to telecommunications engineers and technicians. The session will focus on the unique capabilities of Milvus, the chosen vector database for the project, and its advantages over other vector databases.
Attending this session will give you a deeper understanding of the potential of RAG and Milvus DB in telecommunications engineering. You will learn how to address common challenges in the field and enhance the efficiency of their operations. The session will equip you with the knowledge to make informed decisions about the choice of vector databases, and how best to use them for your use-cases
Metadata Lakes for Next-Gen AI/ML - DatastratoZilliz
As data catalogs evolve to meet the growing and new demands of high-velocity, unstructured data, we see them taking a new shape as an emergent and flexible way to activate metadata for multiple uses. This talk discusses modern uses of metadata at the infrastructure level for AI-enablement in RAG pipelines in response to the new demands of the ecosystem. We will also discuss Apache (incubating) Gravitino and its open source-first approach to data cataloging across multi-cloud and geo-distributed architectures.
Multimodal Retrieval Augmented Generation (RAG) with MilvusZilliz
We've seen an influx of powerful multimodal capabilities in many LLMs. In this talk, we'll vectorize a dataset of images and texts into the same embedding space, store them in Milvus, retrieve all relevant data using multilingual texts and/or images and input multimodal data as context into GPT-4o.
Building an Agentic RAG locally with Ollama and MilvusZilliz
With the rise of Open-Source LLMs like Llama, Mistral, Gemma, and more, it has become apparent that LLMs might also be useful even when run locally. In this talk, we will see how to deploy an Agentic Retrieval Augmented Generation (RAG) setup using Ollama, with Milvus as the vector database on your laptop. That way, you can also avoid being Rate Limited by OpenAI like I have been in the past.
Specializing Small Language Models With Less DataZilliz
Most AI teams are exploring the possibilities of LLMs, rather than being focused on margins but soon efficiency will become important. Implementing small, specialized models to solve specific problems is an option, but is not leveraged often, because it requires gathering high volumes of human-labeled training data which are hard to acquire. To alleviate this problem, I will discuss how large language models can be used to generate synthetic data used to help tune small models on domain-specific tasks. We will focus on extractive question answering use case where additional unstructured context can help training.
Occiglot - Open Language Models by and for EuropeZilliz
Large language models (LLMs) have emerged as transformative tools, revolutionizing various natural language processing tasks. Despite their remarkable potential, the LLM landscape is predominantly shaped by US tech companies, leaving Europe with limited access and influence. This talk will present Occiglot - an ongoing research collective for open-source language models for and by Europe. More specifically, we will explain why open European LLMs are needed and share insights as well as lessons learned, ranging from data collection and curation, model training and evaluation
Fueling AI with Great Data with Airbyte WebinarZilliz
This talk will focus on how to collect data from a variety of sources, leveraging this data for RAG and other GenAI use cases, and finally charting your course to productionalization.
Generating privacy-protected synthetic data using Secludy and MilvusZilliz
During this demo, the founders of Secludy will demonstrate how their system utilizes Milvus to store and manipulate embeddings for generating privacy-protected synthetic data. Their approach not only maintains the confidentiality of the original data but also enhances the utility and scalability of LLMs under privacy constraints. Attendees, including machine learning engineers, data scientists, and data managers, will witness first-hand how Secludy's integration with Milvus empowers organizations to harness the power of LLMs securely and efficiently.
Building Production Ready Search Pipelines with Spark and MilvusZilliz
Read more: https://zilliz.com/blog/building-production-ready-search-pipelines-spark-milvus
Spark is the widely used ETL tool for processing, indexing and ingesting data to serving stack for search. Milvus is the production-ready open-source vector database. In this talk we will show how to use Spark to process unstructured data to extract vector representations, and push the vectors to Milvus vector database for search serving.
UiPath Community Day Amsterdam: Code, Collaborate, ConnectUiPathCommunity
Welcome to our third live UiPath Community Day Amsterdam! Come join us for a half-day of networking and UiPath Platform deep-dives, for devs and non-devs alike, in the middle of summer ☀.
📕 Agenda:
12:30 Welcome Coffee/Light Lunch ☕
13:00 Event opening speech
Ebert Knol, Managing Partner, Tacstone Technology
Jonathan Smith, UiPath MVP, RPA Lead, Ciphix
Cristina Vidu, Senior Marketing Manager, UiPath Community EMEA
Dion Mes, Principal Sales Engineer, UiPath
13:15 ASML: RPA as Tactical Automation
Tactical robotic process automation for solving short-term challenges, while establishing standard and re-usable interfaces that fit IT's long-term goals and objectives.
Yannic Suurmeijer, System Architect, ASML
13:30 PostNL: an insight into RPA at PostNL
Showcasing the solutions our automations have provided, the challenges we’ve faced, and the best practices we’ve developed to support our logistics operations.
Leonard Renne, RPA Developer, PostNL
13:45 Break (30')
14:15 Breakout Sessions: Round 1
Modern Document Understanding in the cloud platform: AI-driven UiPath Document Understanding
Mike Bos, Senior Automation Developer, Tacstone Technology
Process Orchestration: scale up and have your Robots work in harmony
Jon Smith, UiPath MVP, RPA Lead, Ciphix
UiPath Integration Service: connect applications, leverage prebuilt connectors, and set up customer connectors
Johans Brink, CTO, MvR digital workforce
15:00 Breakout Sessions: Round 2
Automation, and GenAI: practical use cases for value generation
Thomas Janssen, UiPath MVP, Senior Automation Developer, Automation Heroes
Human in the Loop/Action Center
Dion Mes, Principal Sales Engineer @UiPath
Improving development with coded workflows
Idris Janszen, Technical Consultant, Ilionx
15:45 End remarks
16:00 Community fun games, sharing knowledge, drinks, and bites 🍻
How UiPath Discovery Suite supports identification of Agentic Process Automat...DianaGray10
📚 Understand the basics of the newly persona-based LLM-powered Agentic Process Automation and discover how existing UiPath Discovery Suite products like Communication Mining, Process Mining, and Task Mining can be leveraged to identify APA candidates.
Topics Covered:
💡 Idea Behind APA: Explore the innovative concept of Agentic Process Automation and its significance in modern workflows.
🔄 How APA is Different from RPA: Learn the key differences between Agentic Process Automation and Robotic Process Automation.
🚀 Discover the Advantages of APA: Uncover the unique benefits of implementing APA in your organization.
🔍 Identifying APA Candidates with UiPath Discovery Products: See how UiPath's Communication Mining, Process Mining, and Task Mining tools can help pinpoint potential APA candidates.
🔮 Discussion on Expected Future Impacts: Engage in a discussion on the potential future impacts of APA on various industries and business processes.
Enhance your knowledge on the forefront of automation technology and stay ahead with Agentic Process Automation. 🧠💼✨
Speakers:
Arun Kumar Asokan, Delivery Director (US) @ qBotica and UiPath MVP
Naveen Chatlapalli, Solution Architect @ Ashling Partners and UiPath MVP
Redefining Cybersecurity with AI CapabilitiesPriyanka Aash
In this comprehensive overview of Cisco's latest innovations in cybersecurity, the focus is squarely on resilience and adaptation in the face of evolving threats. The discussion covers the imperative of tackling Mal information, the increasing sophistication of insider attacks, and the expanding attack surfaces in a hybrid work environment. Emphasizing a shift towards integrated platforms over fragmented tools, Cisco introduces its Security Cloud, designed to provide end-to-end visibility and robust protection across user interactions, cloud environments, and breaches. AI emerges as a pivotal tool, from enhancing user experiences to predicting and defending against cyber threats. The blog underscores Cisco's commitment to simplifying security stacks while ensuring efficacy and economic feasibility, making a compelling case for their platform approach in safeguarding digital landscapes.
Self-Healing Test Automation Framework - HealeniumKnoldus Inc.
Revolutionize your test automation with Healenium's self-healing framework. Automate test maintenance, reduce flakes, and increase efficiency. Learn how to build a robust test automation foundation. Discover the power of self-healing tests. Transform your testing experience.
Demystifying Neural Networks And Building Cybersecurity ApplicationsPriyanka Aash
In today's rapidly evolving technological landscape, Artificial Neural Networks (ANNs) have emerged as a cornerstone of artificial intelligence, revolutionizing various fields including cybersecurity. Inspired by the intricacies of the human brain, ANNs have a rich history and a complex structure that enables them to learn and make decisions. This blog aims to unravel the mysteries of neural networks, explore their mathematical foundations, and demonstrate their practical applications, particularly in building robust malware detection systems using Convolutional Neural Networks (CNNs).
Keynote : Presentation on SASE TechnologyPriyanka Aash
Secure Access Service Edge (SASE) solutions are revolutionizing enterprise networks by integrating SD-WAN with comprehensive security services. Traditionally, enterprises managed multiple point solutions for network and security needs, leading to complexity and resource-intensive operations. SASE, as defined by Gartner, consolidates these functions into a unified cloud-based service, offering SD-WAN capabilities alongside advanced security features like secure web gateways, CASB, and remote browser isolation. This convergence not only simplifies management but also enhances security posture and application performance across global networks and cloud environments. Discover how adopting SASE can streamline operations and fortify your enterprise's digital transformation strategy.
Keynote : AI & Future Of Offensive SecurityPriyanka Aash
In the presentation, the focus is on the transformative impact of artificial intelligence (AI) in cybersecurity, particularly in the context of malware generation and adversarial attacks. AI promises to revolutionize the field by enabling scalable solutions to historically challenging problems such as continuous threat simulation, autonomous attack path generation, and the creation of sophisticated attack payloads. The discussions underscore how AI-powered tools like AI-based penetration testing can outpace traditional methods, enhancing security posture by efficiently identifying and mitigating vulnerabilities across complex attack surfaces. The use of AI in red teaming further amplifies these capabilities, allowing organizations to validate security controls effectively against diverse adversarial scenarios. These advancements not only streamline testing processes but also bolster defense strategies, ensuring readiness against evolving cyber threats.
Discovery Series - Zero to Hero - Task Mining Session 1DianaGray10
This session is focused on providing you with an introduction to task mining. We will go over different types of task mining and provide you with a real-world demo on each type of task mining in detail.
Choosing the Best Outlook OST to PST Converter: Key Features and Considerationswebbyacad software
When looking for a good software utility to convert Outlook OST files to PST format, it is important to find one that is easy to use and has useful features. WebbyAcad OST to PST Converter Tool is a great choice because it is simple to use for anyone, whether you are tech-savvy or not. It can smoothly change your files to PST while keeping all your data safe and secure. Plus, it can handle large amounts of data and convert multiple files at once, which can save you a lot of time. It even comes with 24*7 technical support assistance and a free trial, so you can try it out before making a decision. Whether you need to recover, move, or back up your data, Webbyacad OST to PST Converter is a reliable option that gives you all the support you need to manage your Outlook data effectively.
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptxFwdays
I will share my personal experience of full-time development on wasm Blazor
What difficulties our team faced: life hacks with Blazor app routing, whether it is necessary to write JavaScript, which technology stack and architectural patterns we chose
What conclusions we made and what mistakes we committed
5. The DSPy paradigm - dspy.ai
Let’s program—not prompt—LMs.
Connect declarative modules into a computation graph, and compile it into a chain of optimized
prompts (or LM finetunes) automatically. How?
1. Hand-written Prompts Signatures: question -> answer long_document -> summary
2. Prompting Techniques and Chains Modules: dspy.ChainOfThought dspy.ReAct
3. Manual Prompt Engineering
a. Optimizers (given a metric you want to maximize)
b. Assertions (similar to assertions in programming language)
6. Let’s get concrete: Question Answering with HotPotQA
Question: How many storeys are in the castle David Gregory inherited?
Passages: (1) St. Gregory Hotel is a 9-floor boutique hotel… (2) Kinnairdy Castle
is tower house with five storeys…
Answer: Kinnairdy Castle has five storeys.
7. Let’s build three programs for this task. Program 1.
CoT = dspy.ChainOfThought("question -> answer")
How many storeys are in the castle
David Gregory inherited?
Answer: Castle Gregory has three storeys.
CoT
CoT
Question
Chain of Thought (Reasoning); Answer
8. Let’s build another program for this task. Program 2.
class RAG(dspy.Module):
def __init__(self, num_passages=3):
self.retrieve = dspy.Retrieve(k=num_passages)
self.generate_answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
passages = self.retrieve(question).passages
return self.generate_answer(context=passages, question=question)
Retriever
<finds relevant passages>
Answer
LM
Question
Retriever
St. Gregory Hotel is a 9-floor
boutique hotel…
St. Gregory Hotel has nine storeys.
LM
How many storeys are in the castle
David Gregory inherited?
9. Let’s build a solid Program 3 for this task.
class MultiHop(dspy.Module):
def __init__(self, passages_per_hop=3):
self.generate_query = dspy.ChainOfThought("context, question -> query")
self.retrieve = dspy.Retrieve(k=passages_per_hop)
self.generate_answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
context = []
for _ in range(2):
query = self.generate_query(context=context, question=question).query
context += self.retrieve(query).passages
return self.generate_answer(context=context, question=question)
LM
What castle did David
Gregory inherit?
Retriever
David Gregory… inherited the
Kinnairdy Castle in 1664.
LM
How many storeys are
in Kinnairdy Castle?
Retriever
Kinnairdy Castle is tower
house with five storeys…
LM
Kinnairdy Castle has five storeys.
How many storeys are in the castle
David Gregory inherited?
10. What does the DSPy Compiler do?
A Few
Examples
(labeled and/or unlabeled)
Improved
DSPy
Program
DSPy Program
DSPy Compiler
(a specific optimizer)
improved_dspy_program = optimizer.compile(dspy_program, few_examples)
13. GSM8K - grade school math dataset
20 birds migrate on a seasonal basis from one lake to another, searching
for food. If they fly from lake Jim to lake Disney in one season, which is 50
miles apart, then the next season they fly from lake Disney to lake London,
60 miles apart, calculate the combined distance all of the birds have
traveled in the two seasons.
Answer: 20 * (50 + 60) = 2200 miles
15. Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
---
Question: 20 birds migrate on a seasonal basis from one lake to another, searching for food. If they fly
from lake Jim to lake Disney in one season, which is 50 miles apart, then the next season they fly from
lake Disney to lake London, 60 miles apart, calculate the combined distance all of the birds have traveled
in the two seasons.
Reasoning: Let's think step by step in order to produce the answer. We know that the
birds fly 50 miles from lake Jim to lake Disney and then 60 miles from lake Disney to
lake London. To find the combined distance, we simply add the two distances
together.
Answer: The combined distance all of the birds have traveled in the two seasons is
50 miles + 60 miles = 110 miles.
16. Two problems:
1. Reasoning does not include all the information needed
2. Answer in complicated sentences, not a single number
LMs are not following what we expect.
And, there's no way to even specify the constraints except manual
prompt tuning.
17. Goal: Enable DSPy programmers to define constraints on LM behavior.
Can we make a robust, extensible programming construct?
18. Including Assertions in DSPy
dspy.Assert - DSPy must either pass the assertion or raise an Exception
dspy.Suggest - DSPy should try to pass the assertion, but permit the code to continue otherwise
dspy.Suggest(constraint: bool, instruction_message: str)
19. Introducing DSPy Assertions — to guide LM behavior in DSPy programs.
DSPy Assertions
Assertion-driven backtracking
Self-refine LMs by providing feedback and past
erroneous response
Example selection and bootstrapping
Provide better demonstrations for in-context learning
20. def extract_number(question):
"""extract numbers from a question"""
def has_numbers(rationale, numbers):
"""whether rationale has all the numbers, if not, return the missing number"""
class SimpleMathSolverWithSuggest(dspy.Module):
def __init__(self):
self.prog = dspy.ChainOfThought("question -> answer")
def forward(self, question):
pred = self.prog(question=question)
rationale_has_numbers, missing_number = has_numbers(pred.rationale, extract_number(question))
dspy.Suggest(rationale_has_numbers, f"Your Reasoning should contain {missing_number}.")
dspy.Suggest(len(pred.answer) < 10, "Your Answer should be a number.")
return pred
simple_math_solver_suggest = SimpleMathSolverWithSuggest().activate_assertions()
DSPy program with Assertions
Assertion-driven backtracking
Self-refine LMs by providing feedback and past
erroneous response
21. Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
---
Question: 20 birds migrate on a seasonal basis from one lake to another, searching for food. If they fly
from lake Jim to lake Disney in one season, which is 50 miles apart, then the next season they fly from
lake Disney to lake London, 60 miles apart, calculate the combined distance all of the birds have traveled
in the two seasons.
Reasoning: Let's think step by step in order to produce the answer. We know that the
birds fly 50 miles from lake Jim to lake Disney and then 60 miles from lake Disney to
lake London. To find the combined distance, we simply add the two distances
together.
Answer: The combined distance all of the birds have traveled in the two seasons is
50 miles + 60 miles = 110 miles.
22. def extract_number(question):
"""extract numbers from a question"""
def has_numbers(rationale, numbers):
"""whether rationale has all the numbers, if not, return the missing number"""
class SimpleMathSolverWithSuggest(dspy.Module):
def __init__(self):
self.prog = dspy.ChainOfThought("question -> answer")
def forward(self, question):
pred = self.prog(question=question)
rationale_has_numbers, missing_number = has_numbers(pred.rationale, extract_number(question))
dspy.Suggest(rationale_has_numbers, f"Your Reasoning should contain {missing_number}.")
dspy.Suggest(len(pred.answer) < 10, "Your Answer should be a number.")
return pred
simple_math_solver_suggest = SimpleMathSolverWithSuggest().activate_assertions()
23. Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Previous Reasoning: past Reasoning with errors
Instructions: Some instructions you must satisfy
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
---
Question: 20 birds migrate on a seasonal basis from one lake to another, searching for food. If they fly from lake Jim
to lake Disney in one season, which is 50 miles apart, then the next season they fly from lake Disney to lake London,
60 miles apart, calculate the combined distance all of the birds have traveled in the two seasons.
Previous Reasoning: produce the answer. We know that the birds fly 50 miles from lake Jim to lake Disney and then
60 miles from lake Disney to lake London. To find the combined distance, we simply add the two distances together.
Instructions: Your Reasoning should contain 20.
Reasoning: Let's think step by step in order to calculate the combined distance all of the birds have
traveled in the two seasons. In the first season, 20 birds fly 50 miles from lake Jim to lake Disney,
which totals to 20 birds * 50 miles = 1000 miles. In the second season, they fly 60 miles from lake
Disney to lake London, which totals to 20 birds * 60 miles = 1200 miles. Therefore, the combined
distance all of the birds have traveled in the two seasons is 1000 miles + 1200 miles = 2200 miles.
Answer: The combined distance all of the birds have traveled in the two seasons is 2200 miles.
24. def extract_number(question):
"""extract numbers from a question"""
def has_numbers(rationale, numbers):
"""whether rationale has all the numbers, if not, return the missing number"""
class SimpleMathSolverWithSuggest(dspy.Module):
def __init__(self):
self.prog = dspy.ChainOfThought("question -> answer")
def forward(self, question):
pred = self.prog(question=question)
rationale_has_numbers, missing_number = has_numbers(pred.rationale, extract_number(question))
dspy.Suggest(rationale_has_numbers, f"Your Reasoning should contain {missing_number}.")
dspy.Suggest(len(pred.answer) < 10, "Your Answer should be a number.")
return pred
simple_math_solver_suggest = SimpleMathSolverWithSuggest().activate_assertions()
25. Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Previous Reasoning: past Reasoning with errors
Instructions: Some instructions you must satisfy
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
---
Question: 20 birds migrate on a seasonal basis from one lake to another, searching for food. If they fly from lake Jim
to lake Disney in one season, which is 50 miles apart, then the next season they fly from lake Disney to lake London,
60 miles apart, calculate the combined distance all of the birds have traveled in the two seasons.
Previous Answer: The combined distance all of the birds have traveled in the two seasons is 2200 miles.
Instructions: Your Answer should be a number.
Reasoning: Let's think step by step in order to produce the answer. We know that in the first season,
20 birds fly 50 miles from lake Jim to lake Disney, totaling 20 birds * 50 miles = 1000 miles. In the
second season, they fly 60 miles from lake Disney to lake London, totaling 20 birds * 60 miles =
1200 miles. Therefore, the combined distance all of the birds have traveled in the two seasons is
1000 miles + 1200 miles = 2200 miles.
Answer: 2200 miles
26. optimizer = BootstrapFewShotWithRandomSearch(
gsm8k_metric, max_bootstrapped_demos=3, max_labeled_demos=6, num_candidate_programs=6)
compiled_prog = optimizer.compile(student=simple_math_solver)
compiled_prog_suggest = optimizer.compile(student=simple_math_solver_suggest)
Example selection and bootstrapping
Provide better demonstrations for in-context learning
1. Demonstrations need to pass DSPy assertions, too.
2. Demonstrations can also contain traces with errors and fixes.
3. Optimizer is "assertion-aware" - it also calculates how many assertion failure in
addition to "metric"
27. Results
Simple CoT CoT w Assertions Compiled CoT Compiled w Assertion
61.7 74.3 83.7 84.0
*Compiled w Assertion does not outperform Compiled on this task. Our
observations are: the harder assertions are, the better they are at
improving in-context learning demonstrations.
28. How could we use LM Assertions here?
HumanEval - code generation
30. 🤖Code
Generator
Prompt
🤖Test
Generator
suggest(check_tests(code, test), f"The
generated code failed the test {test}")
Code
Code Generation Pipeline w. Suggestions
Test
Code
🤖Code
Generator
Prompt
Code
Code Generation Pipeline
Code
UPDATED PROMPT WITH FEEDBACK
Prompt: . . .
Past Code: <previous attempt w/ errors> . . .
Instruction: The generated code failed the test
<test>, please fix it. . .
31. class NaiveCodeGenerator(dspy.Module):
def __init__(self):
self.prog = dspy.ChainOfThought("prompt -> code")
self.generate_test = dspy.ChainOfThought("prompt -> test")
def forward(self, prompt):
pred = self.prog(prompt=prompt)
tests = self.generate_test(prompt=prompt)
result, test, error = check_tests(pred, tests)
dspy.Suggest( result == "passed",
f"The generated code failed the test {test}, please fix {error}.",
backtrack_module = self.prog )
return pred
DSPy program with Assertions
32. Results
Naive Program Generator Program Generator w Assertions
70.7 75.6
*Issues with self-consistency:
1. Both tests and code went wrong in the same way
2. Generated tests are wrong, thus not giving useful feedback
34. Multi-Hop Question Answering with HotPotQA with Suggestions
class MultiHop(dspy.Module):
def __init__(self, passages_per_hop=3):
self.generate_query = dspy.ChainOfThought("context, question -> query")
self.retrieve = dspy.Retrieve(k=passages_per_hop)
self.generate_answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
context = []
queries = [question]
for _ in range(2):
query = self.generate_query(context=context, question=question).query
dspy.Suggest(len(query) < 100,
"Query should be less than 100 characters")
dspy.Suggest(is_query_distinct(query, queries),
f"Query should be distinct from {queries}")
queries += query
context += self.retrieve(query).passages
return self.generate_answer(context=context, question=question)
The queries should
be different from
previous ones
The query should be
concise
35. Multi-Hop Question Answering with HotPotQA with Suggestions
class MultiHop(dspy.Module):
def __init__(self, passages_per_hop=3):
self.generate_query = dspy.ChainOfThought("context, question -> query")
self.retrieve = dspy.Retrieve(k=passages_per_hop)
self.generate_answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
context = []
queries = [question]
for _ in range(2):
query = self.generate_query(context=context, question=question).query
dspy.Suggest(len(query) < 100,
"Query should be less than 100 characters")
dspy.Suggest(is_query_distinct(query, queries),
f"Query should be distinct from {queries}")
queries += query
context += self.retrieve(query).passages
return self.generate_answer(context=context, question=question)
Context: …
Question: …
Past_Query: {previous attempt w/ errors}
Instructions: Query should be distinct from …
backtrack and regenerate query with new prompt
update prompt with feedback
Fail ❌
36. Context
🤖Query
Generator
Retriever
Question
🤖Answer
Generator
Answer
Query
Context + Previous Queries
✓ suggest(len(query) < 100, "Query should be less than 100 chars")
✗ suggest(is_query_distinct(query, prev_queries), f"Query should be
distinct from {prev_queries}")
UPDATED PROMPT WITH FEEDBACK
Context: . . .
Question: . . .
Past Query: <previous attempt w/ errors> . . .
Instruction: Query should be distinct from . . .
Multi-hop QA Pipeline