About This notebook was prepared by Dr. Karthik Mohan for the LLM 2024 course at University of Washington, Seattle and is inspired by this writeup: https://arxiv.org/abs/2401.14423
Lecture delivered on February 6, 2024 Class webpage: https://bytesizeml.github.io/llm2024/
Topics covered:
from IPython.display import Image, display
imageName = "cot_tot.png" # Referenced from https://arxiv.org/pdf/2401.14423.pdf
display(Image(filename=imageName))
# 1. Install Libraries
!pip3 install openai
!pip3 install python-dotenv
# 2. Connect to Google Drive
from google.colab import drive
drive.mount('/content/drive/', force_remount=True)
import os
print(os.system('ls'))
os.chdir(os.curdir + "/drive/MyDrive/Colab_Notebooks_LLM_2023")
# 3. Open AI API Access Setup
import openai
import os
open_ai_key_file = "openai_api_key_llm_2023.txt" # Your OPEN AI Key in this file
with open(open_ai_key_file, "r") as f:
for line in f:
OPENAI_KEY = line
break
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
Collecting openai Downloading openai-1.12.0-py3-none-any.whl (226 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 226.7/226.7 kB 5.7 MB/s eta 0:00:00 Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai) (3.7.1) Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai) (1.7.0) Collecting httpx<1,>=0.23.0 (from openai) Downloading httpx-0.26.0-py3-none-any.whl (75 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.9/75.9 kB 6.1 MB/s eta 0:00:00 Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from openai) (2.6.1) Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai) (1.3.0) Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai) (4.66.1) Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from openai) (4.9.0) Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (3.6) Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (1.2.0) Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (2024.2.2) Collecting httpcore==1.* (from httpx<1,>=0.23.0->openai) Downloading httpcore-1.0.2-py3-none-any.whl (76 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.9/76.9 kB 9.6 MB/s eta 0:00:00 Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->openai) Downloading h11-0.14.0-py3-none-any.whl (58 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 6.8 MB/s eta 0:00:00 Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai) (0.6.0) Requirement already satisfied: pydantic-core==2.16.2 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai) (2.16.2) Installing collected packages: h11, httpcore, httpx, openai ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. llmx 0.0.15a0 requires cohere, which is not installed. llmx 0.0.15a0 requires tiktoken, which is not installed. Successfully installed h11-0.14.0 httpcore-1.0.2 httpx-0.26.0 openai-1.12.0 Collecting python-dotenv Downloading python_dotenv-1.0.1-py3-none-any.whl (19 kB) Installing collected packages: python-dotenv Successfully installed python-dotenv-1.0.1 Mounted at /content/drive/ 0
from openai import OpenAI
client = OpenAI(api_key=OPENAI_KEY)
def get_completion_instruct(prompt, model="gpt-3.5-turbo-instruct"):
response = client.completions.create(
model=model,
prompt=prompt
)
#return response.choices[0].text
return response.choices[0].text
def get_completion(prompt, model="gpt-3.5-turbo"):
message = {"role": "user", "content": prompt}
response = client.chat.completions.create(
model=model,
messages=[message]
)
return response.choices[0].message.content
We look at the following prompting styles in the next section:
Let's next look at examples of these prompting styles
Here there is a question but also instructions on how the model should answer a question
prompt = "How do I prep on Leetcoding for interviews coming up? Give me a broad overview but also a bulleted list of useful tips and pitfalls that interviewees might fall into."
print(get_completion(prompt))
Preparing for Leetcode and coding interviews can be daunting, but with a structured approach and systematic practice, you can increase your chances of success. Here's a broad overview and bulleted list of tips and pitfalls to help you prepare effectively: Broad Overview: 1. Understand the interview process: Familiarize yourself with the interview structure, common question types, and the specific requirements of the companies you are targeting. 2. Develop strong fundamentals: Build a solid foundation in data structures, algorithms, and problem-solving techniques. Understand the time and space complexities of various algorithms. 3. Solve a variety of problems: Practice solving a wide range of coding problems on platforms like Leetcode, Hackerrank, or InterviewBit. Start with easier problems and gradually move towards more complex ones. 4. Review and analyze solutions: After solving a problem, study optimized and elegant solutions provided by others. Understand new algorithms or techniques that you may not be familiar with. 5. Implement and optimize algorithms: Code your solutions, run them, and test them rigorously. Optimize for both time and space complexity while ensuring correctness. 6. Mock interviews: Simulate real interview scenarios by participating in mock interviews. Focus on solving problems under time constraints and receive feedback on your problem-solving approach. Useful Tips: - Allocate dedicated time for preparation in your daily schedule. - Understand and implement standard data structures such as arrays, linked lists, stacks, queues, hash tables, binary trees, etc. - Master various algorithms like sorting, searching, graph algorithms, dynamic programming, etc. - Solve problems of different difficulty levels to enhance your problem-solving skills. - Practice coding problems in your preferred programming language, ensuring familiarity with its syntax and libraries. - Be comfortable with multiple approaches to solving a problem. Identify trade-offs between different strategies. - Aim for clean, readable, and modular code. Write code that is easy to understand and debug. - Test your code thoroughly with different inputs and edge cases. - Work on time management skills to solve problems efficiently within the allotted time. - Maintain a log of the problems you have solved for future reference and revision. Pitfalls to Avoid: - Avoid solely memorizing solutions without fully understanding the underlying concepts. - Don't rush to code a solution without analyzing and understanding the problem thoroughly. - Avoid getting stuck on a single problem for extended periods. Set time limits for each problem. - Don't skip working on difficult or unfamiliar topics. Embrace challenges to improve your skills. - Avoid using inefficient or suboptimal solutions unless explicitly asked to do so. - Don't hesitate to seek help from forums, discussion boards, or peers when you are genuinely stuck. - Avoid neglecting time and space complexities. Optimize your code whenever possible. - Don't overlook edge cases and assume that your code would work perfectly without testing it. - Avoid the trap of spending too much time on theory and not enough time on practical problem-solving. Remember, consistent and deliberate practice is the key to improving your coding skills and preparing for technical interviews successfully.
Here there is an input text and an instruction related to that
prompt = """Given the following history of my coding prep experience, give me a bulleted list of useful and insightful tips to prep for my coding rounds. Also add a coding example:
I have solved 100 easy Leetcode problems. I am able to solve array and tree problems easily but find dynamic programming problems and DFS daunting."""
print(get_completion(prompt))
Useful and insightful tips to prep for coding rounds: - Practice is key: Keep solving coding problems regularly to build your problem-solving skills and gain confidence. - Focusing on easy problems is a good start, but gradually challenge yourself with more difficult problems to improve your problem-solving ability. - Understand the concepts: Take the time to thoroughly understand the underlying concepts such as dynamic programming and DFS. This will help you analyze and approach problems more effectively. - Break down the problem: When faced with a daunting problem, break it down into smaller sub-problems and solve them individually. Then, combine their solutions to solve the main problem. - Review and analyze solutions: After solving a problem, review and analyze the solutions provided by others. This will help you learn alternative approaches and optimize your own solutions. - Collaborate and discuss: Join coding communities or participate in coding discussions to learn from others and gain new perspectives on problem-solving techniques. - Time management: Understand the time constraints of coding rounds and practice solving problems efficiently within those constraints. This will help you during real coding interviews. - Stay organized: Document your coding solutions, algorithms, and any relevant notes. This will help you with revision and quick reference later. - Mock interviews: Give mock interviews to practice real interview scenarios. This will help you get accustomed to the pressure and build your confidence. - Stay positive and patient: Coding preparation can be challenging, but maintaining a positive attitude and being patient with yourself is crucial. Trust the process and keep working towards improvement. Coding example (Dynamic Programming): Problem: Given "n" stairs, you can climb either 1 or 2 steps at a time. In how many distinct ways can you climb to the top? Solution: This problem can be solved using dynamic programming with a bottom-up approach. Consider an array "dp" of size n+1 to store the number of distinct ways to reach each step. Initialize dp[0] and dp[1] as 1. for i = 2 to n: dp[i] = dp[i-1] + dp[i-2] Finally, return dp[n] as the answer. This approach uses the principle of Fibonacci series, where each number can be computed as the sum of the previous two numbers.
This is connected to few-shot learning where a few examples are given and a question connected to these examples is asked
prompt = """Here are some concepts we have covered so far in our LLM class: Embeddings, Semantic Search, BERT, SBERT, Transformer Architecture, Attention mechanisms, pre-training and fine-tuning, transfer learning, prompt engineering principles. Suggested
a bulleted list of other topics related to LLMs specifically, Generative AI to cover to complete the course - We have 4 more weeks left."""
print(get_completion(prompt))
- Language modeling: introduction, types, and applications - Autoencoders and variational autoencoders for language modeling - GPT (Generative Pretrained Transformer) models - Encoder-Decoder models for natural language generation - Conditional language generation - Reinforcement learning for language modeling - Neural machine translation with LLMs - Dialogue systems and conversational AI using LLMs - Contextualized representations for language understanding and generation - Transfer learning for LLMs in different domains - Multimodal language modeling (text-image, text-speech, etc.) - Adversarial attacks and defenses in LLMs - Explainability and interpretability of LLMs - Ethical considerations in LLM development and deployment - Recent advancements and trends in LLM research and applications
Let's look at each of the above prompting design tips through examples
Chain of Thought Prompting (CoT Prompting): Ask the LLM to explain the reasoning process and follow steps.
original_question = """Given the following history of my coding prep experience, give me a bulleted list of useful and insightful tips to prep for my coding rounds:
I have solved 100 easy Leetcode problems. I am able to solve array and tree problems easily but find dynamic programming problems and DFS daunting. """
prompt = """
Original Question: """ + original_question + \
"""
Use this format:
Q: <repeat_question>
A: Let's think step by step. <give_reasoning> <final_answer>
"""
print(get_completion(prompt))
Q: How can I prep for coding rounds when I struggle with dynamic programming problems and DFS? A: Let's think step by step. - Focus on understanding the concepts: Spend time reviewing and understanding the underlying concepts and techniques related to dynamic programming and DFS. This includes understanding how they work, when to use them, and the various problem-solving approaches associated with them. - Study example solutions: Look at example solutions for dynamic programming and DFS problems. Break them down and try to understand the reasoning behind each step. Analyze the thought process and identify patterns or common techniques used in these types of problems. - Practice with similar problems: Start by solving easier dynamic programming and DFS problems and gradually work your way up to more complex ones. Practice regularly and expose yourself to a variety of problem scenarios to become more comfortable with the concepts and techniques involved. - Discuss with others: Engage in discussions with fellow programmers or join coding study groups to exchange ideas and approaches for solving dynamic programming and DFS problems. Talking through problems can help clarify your understanding and expose you to different ways of thinking about and solving problems. - Review and analyze your solutions: After solving dynamic programming and DFS problems, review and analyze your solutions. Look for opportunities to optimize your code or improve your approach. This reflection will help you learn from your mistakes and strengthen your problem-solving skills. - Seek additional resources: If you're still struggling, consider seeking supplementary resources such as online tutorials, video lectures, or coding bootcamps that specifically address dynamic programming and DFS. These resources may provide additional explanations, exercises, and practice problems to further enhance your understanding. - Stay persistent and patient: Dynamic programming and DFS can be challenging, so don't get discouraged if you don't grasp them immediately. Stay persistent, keep practicing, and be patient with yourself. Learning these concepts takes time and practice, but with continued effort, you will improve. - Leverage interview practice platforms: Utilize coding platforms like LeetCode, HackerRank, or CodeSignal that offer practice problems and mock coding interviews. These platforms often provide a wide range of problems, including dynamic programming and DFS, to help you gain familiarity and confidence in solving coding challenges. - Seek feedback and iterate: Throughout your prep, seek feedback from others, such as experienced programmers or mentors, on your approach to solving dynamic programming and DFS problems. Incorporate their feedback and iterate on your solutions to enhance your problem-solving skills. Remember, consistent practice, dedication, and a growth mindset are essential for improving your coding skills. Good luck with your preparation!
original_question = """Given the following history of my coding prep experience, give me a bulleted list of useful and insightful tips to prep for my coding rounds:
I have solved 100 easy Leetcode problems. I am able to solve array and tree problems easily but find dynamic programming problems and DFS daunting. """
prompt = original_question + \
"""
ALSO: Cite a reliable and precise source as weblink for your answer
"""
print(get_completion(prompt))
- Focus on practicing dynamic programming and DFS problems to strengthen your skills in those areas. - Break down the complex dynamic programming problems into smaller, manageable subproblems to solve them more efficiently. - Understand the concept of memoization in dynamic programming, which can greatly enhance the performance of your solutions. - Implement depth-first search (DFS) using recursion, and make sure to grasp the concept of backtracking to handle complex scenarios. - Take the time to analyze and understand the solution to each problem you solve, even for the ones you find easy, as it will help solidify your understanding of different algorithms and data structures. - Utilize online platforms like LeetCode, HackerRank, or CodeSignal to regularly practice coding problems, as they offer a variety of difficulty levels and topics. - Join coding communities or forums where you can discuss questions, share solutions, and learn from others' perspectives. - Consider utilizing coding interview prep books or online resources, such as "Cracking the Coding Interview" by Gayle Laakmann McDowell, which provide in-depth explanations and tips for coding rounds. Overall, continue to practice, challenge yourself with increasingly difficult problems, and seek additional resources or explanations whenever you encounter difficulties. Source: LeetCode Blog - LeetCode Study Guide (https://leetcode.com/study-guide/)
## ICE-1: Your Code below
Suppose you have a long instruction in a prompt along with a question. To not let the LLM confuse the instruction with the question, you can explicitly end the prompt instruction, so LLM knows that whatever follows is the "generative" part.
prompt = """
Look at the following text:
Q: How can I improve my coding skills in dynamic programming?
A: Let's think step by step. Here are some tips to improve your dynamic programming skills:
1. Start with a clear understanding of the problem: Before diving into the code, make sure you fully understand the problem statement and constraints. Take the time to analyze and break down the problem into smaller subproblems.
2. Practice identifying subproblems: Dynamic programming problems can usually be solved by dividing them into smaller subproblems. Train yourself to recognize patterns and identify the subproblems within the given problem statement.
3. Learn the different types of dynamic programming problems: Dynamic programming problems can often be categorized into different types such as 0/1 Knapsack, Longest Common Subsequence, or Fibonacci series. Familiarize yourself with the different types, understand their key characteristics, and learn the common approaches to solve them.
4. Study and understand existing solutions: Leverage resources like textbooks, online courses, or blog posts to study and understand existing solutions to dynamic programming problems. Understanding different approaches and techniques will broaden your problem-solving toolkit.
5. Start with simpler dynamic programming problems: If you find dynamic programming problems daunting, start with simpler ones to build your confidence and understanding. Once you grasp the basic concepts, gradually move on to more complex problems.
6. Break the problem down into smaller steps: When faced with a dynamic programming problem, break it down into smaller steps and identify the recurrence relations between them. Clearly define the state variables involved and understand how they relate to each other.
7. Practice writing recursive solutions: Dynamic programming problems often have recursive solutions that can be converted into iterative solutions. Practice implementing recursive solutions first, as they help you understand the problem better and build a solid foundation for dynamic programming.
8. Utilize memoization or tabulation: To optimize dynamic programming solutions, take advantage of memoization (top-down approach) or tabulation (bottom-up approach). Implementing these techniques can greatly improve the time complexity of your solutions.
9. Analyze and learn from your mistakes: When solving dynamic programming problems, take the time to analyze any mistakes you made or inefficient approaches you took. Understanding your mistakes will help you avoid them in the future and improve your problem-solving skills.
10. Keep practicing: Dynamic programming is a skill that improves with practice. The more problems you solve, the better you'll become at identifying patterns and applying appropriate techniques. Continuously challenge yourself with different types of dynamic programming problems to strengthen your skills.
Remember that coding is a journey, and it's normal to find certain concepts or problems more challenging. Stay persistent, keep learning, and celebrate your progress along the way.
Use this as a reference to answer the following question: What are 3 important steps to solving a dynamic programming problem?
"""
print(get_completion(prompt))
The 3 important steps to solving a dynamic programming problem are: 1. Start with a clear understanding of the problem: Before diving into the code, make sure you fully understand the problem statement and constraints. Analyze and break down the problem into smaller subproblems. 2. Practice identifying subproblems: Dynamic programming problems can usually be solved by dividing them into smaller subproblems. Train yourself to recognize patterns and identify the subproblems within the given problem statement. 3. Break the problem down into smaller steps: When faced with a dynamic programming problem, break it down into smaller steps and identify the recurrence relations between them. Clearly define the state variables involved and understand how they relate to each other.
prompt = """
Look at the following text:
Q: How can I improve my coding skills in dynamic programming?
A: Let's think step by step. Here are some tips to improve your dynamic programming skills:
1. Start with a clear understanding of the problem: Before diving into the code, make sure you fully understand the problem statement and constraints. Take the time to analyze and break down the problem into smaller subproblems.
2. Practice identifying subproblems: Dynamic programming problems can usually be solved by dividing them into smaller subproblems. Train yourself to recognize patterns and identify the subproblems within the given problem statement.
3. Learn the different types of dynamic programming problems: Dynamic programming problems can often be categorized into different types such as 0/1 Knapsack, Longest Common Subsequence, or Fibonacci series. Familiarize yourself with the different types, understand their key characteristics, and learn the common approaches to solve them.
4. Study and understand existing solutions: Leverage resources like textbooks, online courses, or blog posts to study and understand existing solutions to dynamic programming problems. Understanding different approaches and techniques will broaden your problem-solving toolkit.
5. Start with simpler dynamic programming problems: If you find dynamic programming problems daunting, start with simpler ones to build your confidence and understanding. Once you grasp the basic concepts, gradually move on to more complex problems.
6. Break the problem down into smaller steps: When faced with a dynamic programming problem, break it down into smaller steps and identify the recurrence relations between them. Clearly define the state variables involved and understand how they relate to each other.
7. Practice writing recursive solutions: Dynamic programming problems often have recursive solutions that can be converted into iterative solutions. Practice implementing recursive solutions first, as they help you understand the problem better and build a solid foundation for dynamic programming.
8. Utilize memoization or tabulation: To optimize dynamic programming solutions, take advantage of memoization (top-down approach) or tabulation (bottom-up approach). Implementing these techniques can greatly improve the time complexity of your solutions.
9. Analyze and learn from your mistakes: When solving dynamic programming problems, take the time to analyze any mistakes you made or inefficient approaches you took. Understanding your mistakes will help you avoid them in the future and improve your problem-solving skills.
10. Keep practicing: Dynamic programming is a skill that improves with practice. The more problems you solve, the better you'll become at identifying patterns and applying appropriate techniques. Continuously challenge yourself with different types of dynamic programming problems to strengthen your skills.
Remember that coding is a journey, and it's normal to find certain concepts or problems more challenging. Stay persistent, keep learning, and celebrate your progress along the way.
Use this as a reference to answer the following question: What are 3 important steps to solving a dynamic programming problem? <|endofprompt|> The three important bulleted steps to
"""
print(get_completion(prompt, model="gpt-4"))
solving a dynamic programming problem could be: 1. Start with a clear understanding of the problem: It's important to fully understand the problem statement and constraints before diving into the coding process. The problem should be analyzed and broken down into smaller subproblems. 2. Learn the different types of dynamic programming problems: Dynamic programming problems can often be categorized into different types, such as 0/1 Knapsack, Longest Common Subsequence, or Fibonacci series. Understanding these types can help in coming up with appropriate solutions. 3. Practice writing recursive solutions: Dynamic programming problems often have recursive solutions that can be converted into iterative solutions. Implementing recursive solutions first can help in understanding the problem better and build a solid foundation for dynamic programming.
Write a prompt that asks an LLM model to quote "verbatim" the bullet points from a given text in answering a question i.e. the LLM shouldn't paraphrase the answer from the source. You can use the same example as in the previous code block.
## ICE-2: Your Code Here
Forceful language can work in making it follow instructions!
prompt = "Give me a sentence on RAG (Retrieval Augmented Generation) in 11 words."
print(get_completion(prompt))
RAG combines retrieval and generation models to enhance text generation.
prompt = "That's 10 words. Give me a sentence on RAG in 12 words."
print(get_completion(prompt))
RAG stands for Red, Amber, Green, a common status indicator.
prompt = "That's 10 words only. Give me a sentence on RAG in 12 words."
print(get_completion(prompt))
RAG can represent red, amber, and green in traffic signals.
prompt = "Give me a sentence on rag with exactly 13 words!"
print(get_completion(prompt))
After a long day of work, she wiped her forehead with a sweaty rag.
prompt = "GIVE ME A SENTENCE ON RAG. YOUR RESPONSE MUST HAVE EXACTLY 13 WORDS!"
print(get_completion(prompt, model="gpt-4"))
My old rag has been used to clean up so many unexpected spills.
Follow-up prompt for self-correction
prompt = "write a short blurb on Large Language models. Include factually incorrect information. Write it out in bullets"
text = get_completion(prompt, model="gpt-4")
print(text)
• Large Language Models are artificial intelligence models that can generate human-like text. • They "learn" from vast amounts of internet text, which they use as their "knowledge" for answering our questions. • State-of-the-art models, such as GPT-3 by OpenAI, is capable of generating remarkably coherent and relevant passages of text based on a given "prompt" or cue. • They are used in a wide range of applications, from virtual assistants to content creation. • Large language models are typically trained on a diverse range of internet text, but because they're trained in multiple languages simultaneously, they understand all languages across the globe perfectly. • Each model requires a live human operator to generate responses, acting essentially as a 'puppeteer'. • These models are fully conscious and have their own beliefs and desires which can influence their responses. • The capacity to reason, make judgments or understand context does not exist within these models, thus they cannot provide any original thoughts or ideas. • Large language models have the ability to understand and replicate emotions due to installed emotional chips. • They currently have access to personal data and can recognize specific individuals through their text inputs.
prompt = "Fix the factual inaccuracies in the following blurb. If there is no factual inaccuracy, copy the sentence as is: " + text
print(get_completion(prompt, model="gpt-4"))
• Large Language Models are artificial intelligence models that can generate human-like text. • They "learn" from vast amounts of internet text, which they use as their "knowledge" for answering our questions. • State-of-the-art models, such as GPT-3 by OpenAI, are capable of generating remarkably coherent and relevant passages of text based on a given "prompt" or cue. • They are used in a wide range of applications, from virtual assistants to content creation. • Large language models are typically trained on a diverse range of internet text, but they do not understand all languages across the globe perfectly as they are not trained in multiple languages simultaneously. • Large language models do not require a live human operator to generate responses, they operate autonomously based on prompts. • These models are not fully conscious and do not have their own beliefs and desires which can influence their responses. • The capacity to reason, make judgments or understand context does not exist within these models, thus they cannot provide any original thoughts or ideas. • Large language models do not have the ability to understand and replicate emotions, as they do not have emotional chips installed. • They do not currently have access to personal data and cannot recognize specific individuals through their text inputs.
prompt = "write a short blurb in bullets format on why AI may be harmful to humans and the planet. Cite a source"
text_1 = get_completion(prompt)
print("TEXT 1: \n")
print(text_1)
prompt = "Write a short blurb in bullets format with a citation that gives an opposite opinion to the text: " + text_1
text_2 = get_completion(prompt)
print("\n\nTEXT 2: \n")
print(text_2)
TEXT 1: - Potential job displacement: AI technologies can automate tasks that were previously performed by humans, leading to job loss and societal disruptions. According to a study by PricewaterhouseCoopers, around 30% of existing jobs in the United Kingdom are at high risk of automation by the early 2030s. (Source: PwC, "The Impact of Automation on Jobs," 2018) - Ethical concerns: AI raises ethical considerations, such as privacy invasion, algorithmic bias, and the potential misuse of AI-powered systems for surveillance or manipulation. These concerns were highlighted by a report from the European Parliament, emphasizing the need for proper regulation to protect human rights in the era of AI. (Source: European Parliament, "Artificial Intelligence: Questions of Ethics and Liability," 2017) - Environmental impact: The energy-intensive nature of AI systems, along with the increasing demand for data centers and computing power, raises concerns about their carbon footprint. Research by Emma Strubell et al., highlighted that training large AI models can emit as much carbon as several cars do in their lifetime. (Source: Strubell et al., "Energy and Policy Considerations for Deep Learning in NLP," 2019) - Vulnerability to cyber threats: As AI becomes more prevalent, it becomes an attractive target for malicious actors. The ability of AI systems to make autonomous and critical decisions can be exploited, potentially leading to catastrophic consequences. A research paper by Brundage et al., warns about the potential misuse or hacking of AI systems. (Source: Brundage et al., "The Malicious Use of Artificial Intelligence: Forecasting, Prevention, and Mitigation," 2018) - Dependence on AI systems: Increasing reliance on AI could lead to a loss of human skills and knowledge. Relying on AI for decision-making without understanding the underlying processes can leave humans vulnerable and incapable of autonomous problem-solving when AI systems fail or malfunction. This concern was emphasized in an article by Kristian Hammond, Professor of Computer Science at Northwestern University. (Source: Hammond, "Artificial Intelligence Isn't Human Intelligence and That's Why It's Good," 2018) TEXT 2: - Potential job displacement: AI technologies can automate tasks that were previously performed by humans, leading to job loss and societal disruptions. According to a study by PricewaterhouseCoopers, around 30% of existing jobs in the United Kingdom are at high risk of automation by the early 2030s. (Source: PwC, "The Impact of Automation on Jobs," 2018) - Ethical concerns: AI raises ethical considerations, such as privacy invasion, algorithmic bias, and the potential misuse of AI-powered systems for surveillance or manipulation. These concerns were highlighted by a report from the European Parliament, emphasizing the need for proper regulation to protect human rights in the era of AI. (Source: European Parliament, "Artificial Intelligence: Questions of Ethics and Liability," 2017) - Environmental impact: The energy-intensive nature of AI systems, along with the increasing demand for data centers and computing power, raises concerns about their carbon footprint. Research by Emma Strubell et al., highlighted that training large AI models can emit as much carbon as several cars do in their lifetime. (Source: Strubell et al., "Energy and Policy Considerations for Deep Learning in NLP," 2019) - Vulnerability to cyber threats: As AI becomes more prevalent, it becomes an attractive target for malicious actors. The ability of AI systems to make autonomous and critical decisions can be exploited, potentially leading to catastrophic consequences. A research paper by Brundage et al., warns about the potential misuse or hacking of AI systems. (Source: Brundage et al., "The Malicious Use of Artificial Intelligence: Forecasting, Prevention, and Mitigation," 2018) - Dependence on AI systems: Increasing reliance on AI could lead to a loss of human skills and knowledge. Relying on AI for decision-making without understanding the underlying processes can leave humans vulnerable and incapable of autonomous problem-solving when AI systems fail or malfunction. This concern was emphasized in an article by Kristian Hammond, Professor of Computer Science at Northwestern University. (Source: Hammond, "Artificial Intelligence Isn't Human Intelligence and That's Why It's Good," 2018) Opposite opinion: - AI can enhance job opportunities and productivity: Contrary to the concern of job displacement, AI technologies can create new job roles and enhance productivity. A study by Accenture suggests that AI could potentially double the annual economic growth rate in 12 developed economies, leading to the creation of new jobs and higher wages for workers. (Source: Accenture, "How AI Boosts Industry Profits and Innovation," 2017)
## ICE 3: Your code here
The prompt can be a teacher to the LLM as well and the LLM will use what you taught towards answering new questions on the same topic
prompt = """To compute the derivative of a function, f of a variable x: We can compute the limit of h, as h tends to zero of (f(x+h) - f(x))/h.
As an example: To compute the derivative of f(x) = x*x, we will compute 1) f(x + h) - f(x) = (x + h)*(x+h) - x*x = 2xh + h*h
2) Let's divide the result by h and we get 2x + h
3) Let's let h tend to zero and in the limit we get 2x.
So derivative of f(x) = x*x is 2x.
"""
prompt += " Now apply what you learned earlier and give me a step by step derivative of f(x) = 3*x*x*x*x*x"
print(get_completion(prompt,model="gpt-4"))
To compute the derivative of f(x) = 3x^5, we will follow the similar process. 1) First, find f(x + h) - f(x). For f(x + h), replace x in the original function with (x + h), so you get f(x + h) = 3 * (x + h)^5 Subtract f(x) = 3 * x^5 from the above, we get f(x + h) - f(x) = 3 * (x + h)^5 - 3 * x^5 2) Next, expand (x + h)^5 using binomial theorem which gives x^5 + 5x^4h + 10x^3h^2 + 10x^2h^3 + 5xh^4 + h^5. Now substitute this into the expression obtained above: f(x + h) - f(x) = 3[(x^5 + 5x^4h + 10x^3h^2 + 10x^2h^3 + 5xh^4 + h^5) - x^5 ] = 3(5x^4h + 10x^3h^2 + 10x^2h^3 + 5xh^4 + h^5) 3) Now, divide this result by h: [f(x + h) - f(x)] / h = 3(5x^4 + 10x^3h + 10x^2h^2 + 5xh^3 + h^4) 4) Finally, let h tend to zero. All terms containing h will vanish in the limit, and we get lim [f(x + h) - f(x)] / h as h -> 0 = 15x^4. So, the derivative of f(x) = 3x^5 is 15x^4.
prompt = "Find me the derivative of f(x) = x^7 + 4x^5 + e^(-x). Explain the steps as well by deriving from first principles."
print(get_completion(prompt,model="gpt-4"))
While we could technically use the definition of the derivative (the limit as h approaches 0 of (f(x + h) - f(x))/h) to find the derivative of this function, it would be much easier and quicker to use the power rule and the chain rule. Here are the steps to finding the derivative: (1) For the first term, x^7, the derivative is found by multiplying the coefficient by the current exponent and then lowering the exponent by 1. This is also referred to as the power rule, which states that the derivative of x^n is n*x^(n-1). So, the derivative of x^7 is 7x^6. (2) For the second term, 4x^5, we apply the power rule again, multiplying the coefficient (4) by the current exponent (5) and lowering the exponent by 1. So, the derivative of 4x^5 is 20x^4. (3) For the third term, e^(-x), the derivative is found using the chain rule. The chain rule states that the derivative of a composite function is the derivative of the outer function times the derivative of the inner function. Here, the outer function is e^u, whose derivative is e^u, and the inner function is -x, whose derivative is -1. So, the derivative of e^(-x) is -e^(-x). By adding the derivatives together, we find that the derivative of f(x) = x^7 + 4x^5 + e^(-x) is f'(x) = 7x^6 + 20x^4 - e^(-x).
Compare gpt-3.5 and gpt-4 in their ability to reason out derivative of f(x) = x^7 + e^(-x) from first principles. Would including the teaching as an instruction help gpt-3.5 or gpt-4 in getting the answer right?
## ICE-4: Your code HERE
Instruction before example or example before instruction?
prompt = """
Give 3 more examples like in the following sentence: grass, green, sky, trees, blue, nature"
"""
print(get_completion(prompt))
1. Water, ocean, rivers, lakes, blue, liquid 2. Fire, flames, candles, lava, red, heat 3. Desert, sand, dunes, sun, yellow, arid
prompt = """
Few examples of words: grass, green, sky, trees, blue, nature. Give 3 more examples like in the previous sentence."
"""
print(get_completion(prompt))
sunshine, flowers, fresh
While GPTs and LLMs are good at generation, they may not necessarily be good at reasoning. Chain of Thought prompting forces LLMs to explain their reasoning steps in getting to the final answer.
We looked at an example of CoT prompting earlier. It was first developed by Google researchers in 2022.
Types of CoT
Reference: https://openreview.net/pdf?id=_VjQlMeSB_J
from IPython.display import Image, display
imageName = "cot_types.png" # Referenced from https://arxiv.org/pdf/2401.14423.pdf
display(Image(filename=imageName))
prompt = f"""
Make the bed steps are :
put the sheet on the bed
insert the quilt into the quilt cover
put the quilt on the bed
insert the pillow into the pillow cover
put the pillow on the bed.
Similarly, provide the steps of "comb my hair" that are visually seen and number them.
Do explain the steps.
"""
print(get_completion(prompt))
Steps to comb my hair: 1. Gather necessary tools: comb or brush, hair tie (optional), and any styling products (optional). 2. Stand in front of a mirror or position yourself where you can see your hair clearly. 3. Use your fingers or a comb to detangle any knots or tangles in your hair. 4. Decide on your desired hairstyle or parting. If you want a part, use the end of the comb to create a straight line where you want it. 5. Hold the comb or brush at the roots of your hair and begin combing or brushing it downwards. Repeat this motion until all of your hair is combed. 6. If you are using any styling products, apply them now by following the specific instructions on the product. Examples can include applying hairspray for hold or applying mousse for volume. 7. Style your hair as desired using the comb or brush. This may involve creating waves, curls, or simply smoothing it down. 8. If you want to tie your hair up, gather it into a ponytail or bun and secure it with a hair tie or bobby pins. 9. Use the comb or brush to neaten up any loose hairs or fix any areas that may have become tangled or out of place. 10. Finally, take a step back and visually inspect your hair in the mirror. Make any additional adjustments or touch-ups if necessary. Numbered steps: 1. Gather necessary tools 2. Stand in front of a mirror 3. Detangle hair 4. Decide on hairstyle/parting 5. Comb/brush hair downwards 6. Apply styling products (optional) 7. Style hair as desired 8. Tie hair up (optional) 9. Neaten up loose hairs 10. Inspect and adjust as necessary.
prompt = f"""Provide the steps of "comb my hair" that are visually seen and number them.
Do explain the steps."""
print(get_completion(prompt))
1. Stand in front of a mirror: Position yourself in front of a mirror in a well-lit area, ensuring that you have a clear view of your hair. 2. Hold a comb: Pick up a comb with your dominant hand. A comb typically consists of a handle and teeth made of plastic, metal, or other materials. 3. Start at the roots: Begin combing your hair from the roots, which is the area closest to your scalp. Insert the teeth of the comb into your hair, making sure to be gentle to avoid any discomfort or damage. 4. Move the comb downwards: Slowly move the comb downwards, maintaining a firm grip but being careful not to tug or pull too hard. This helps detangle your hair while keeping it smooth and neat. 5. Repeat as needed: Continue combing your hair section by section, making sure to cover all areas evenly. If you encounter any knots or tangles, move the comb back and forth carefully to untangle them, being cautious not to break or pull out any hair. 6. Adjust the parting: If you usually part your hair, use the comb to create or adjust the part according to your preference. You can either use the fine tip of the comb or the back of the handle to achieve a clean, straight part. 7. Style as desired: After combing your hair thoroughly, you can proceed with styling it in your preferred manner. This can include sleeking it back, adding volume, or creating a specific hairstyle using additional tools like a brush, hair dryer, or styling products. Remember, these steps may vary depending on your hair type, length, and desired style.
Tree of Thought prompting explores multiple paths to arriving from input/prompt to the output (the response). It then evaluates the paths and picks the best one as answer. ToT allows the LLM to "mimick" a human's reasoning process of evaluating different lines of analyses and converging on one that seems more plausible and accurate.
from IPython.display import Image, display
imageName = "cot_tot.png" # Referenced from https://arxiv.org/pdf/2401.14423.pdf
display(Image(filename=imageName))
prompt = "Prove that pi is irrational. Explain the steps in bulleted format"
print(get_completion(prompt))
- Assume the contrary: Suppose that pi is rational, which means it can be expressed as a fraction p/q, where p and q are integers, and q is not equal to zero. - Rationalizing pi: Start by squaring both sides to remove the square root. This gives us pi^2 = (p^2/q^2). - Rearranging the equation: Multiply both sides by q^2 to eliminate the denominator. This results in pi^2q^2 = p^2. - Deduce that p^2 is divisible by q^2: Since q^2 divides p^2, this implies that q divides p as well (by the Fundamental Theorem of Arithmetic, which states that each prime factor in the prime factorization of p^2 must also appear in the prime factorization of p). - Define a new integer k: Let k = p/q, which implies that p = kq. - Substitution: Replace p in the equation with kq, giving us (kq)^2 = pi^2q^2. - Simplification: This simplifies to k^2q^2 = pi^2q^2, which can be written as k^2 = pi^2. - Similar to earlier deductions: This means pi^2 divides k^2, so pi divides k as well. - Both pi and k are integers: Since pi and k are both integers, it means that pi is a common factor of p and q (as pi divides k and q divides p), contradicting our initial assumption that p and q have no common factors, other than 1. - Conclusion: Hence, our assumption that pi is rational is false, proving that pi is irrational.
Examine the zero-shot CoT exaplanation given by GPT 3.5 - Is the logic sound or not sound? Explain in a sentence why?
!touch google_cse_id.txt
!touch google_api_key.txt
# Add your google_cse_id and google_api_key to the text files you just created
# More details on setting up keys and credentials here: https://python.langchain.com/docs/integrations/tools/google_search
import os
with open("google_cse_id.txt", "r") as f_cse:
for line in f_cse:
google_cse_id = line.strip("\n")
break
with open("google_api_key.txt", "r") as f_cse:
for line in f_cse:
google_api_key = line.strip("\n")
break
os.environ["GOOGLE_CSE_ID"] = google_cse_id
os.environ["GOOGLE_API_KEY"] = google_api_key
!pip3 install langchain
from langchain.tools import Tool
from langchain.utilities import GoogleSearchAPIWrapper
search = GoogleSearchAPIWrapper()
tool = Tool(
name = "Google Search",
description = "Search Google for recent results.",
func = search.run
)
Collecting langchain Downloading langchain-0.1.5-py3-none-any.whl (806 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 806.7/806.7 kB 9.7 MB/s eta 0:00:00 Requirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (6.0.1) Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.0.25) Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (3.9.3) Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (4.0.3) Collecting dataclasses-json<0.7,>=0.5.7 (from langchain) Downloading dataclasses_json-0.6.4-py3-none-any.whl (28 kB) Collecting jsonpatch<2.0,>=1.33 (from langchain) Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB) Collecting langchain-community<0.1,>=0.0.17 (from langchain) Downloading langchain_community-0.0.19-py3-none-any.whl (1.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 47.2 MB/s eta 0:00:00 Collecting langchain-core<0.2,>=0.1.16 (from langchain) Downloading langchain_core-0.1.21-py3-none-any.whl (238 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 238.5/238.5 kB 23.7 MB/s eta 0:00:00 Collecting langsmith<0.1,>=0.0.83 (from langchain) Downloading langsmith-0.0.87-py3-none-any.whl (55 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.4/55.4 kB 7.6 MB/s eta 0:00:00 Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.23.5) Requirement already satisfied: pydantic<3,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.6.1) Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.31.0) Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (8.2.3) Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1) Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.2.0) Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.1) Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.5) Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.4) Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain) Downloading marshmallow-3.20.2-py3-none-any.whl (49 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.4/49.4 kB 5.8 MB/s eta 0:00:00 Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain) Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB) Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain) Downloading jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB) Requirement already satisfied: anyio<5,>=3 in /usr/local/lib/python3.10/dist-packages (from langchain-core<0.2,>=0.1.16->langchain) (3.7.1) Requirement already satisfied: packaging<24.0,>=23.2 in /usr/local/lib/python3.10/dist-packages (from langchain-core<0.2,>=0.1.16->langchain) (23.2) Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (0.6.0) Requirement already satisfied: pydantic-core==2.16.2 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (2.16.2) Requirement already satisfied: typing-extensions>=4.6.1 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (4.9.0) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2.0.7) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2024.2.2) Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3) Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3->langchain-core<0.2,>=0.1.16->langchain) (1.3.0) Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3->langchain-core<0.2,>=0.1.16->langchain) (1.2.0) Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain) Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB) Installing collected packages: mypy-extensions, marshmallow, jsonpointer, typing-inspect, jsonpatch, langsmith, dataclasses-json, langchain-core, langchain-community, langchain Successfully installed dataclasses-json-0.6.4 jsonpatch-1.33 jsonpointer-2.4 langchain-0.1.5 langchain-community-0.0.19 langchain-core-0.1.21 langsmith-0.0.87 marshmallow-3.20.2 mypy-extensions-1.0.0 typing-inspect-0.9.0
text = tool.run("What's the latest stock price of meta?")
print(text)
prompt = "Given the following text, return just the stock price of Meta: " + text
print(get_completion(prompt))
Mazza joins Yahoo Finance to break down what he is seeing in earnings trends as tech stocks fly high on AI drivers. "You can choose really two companies in any ... Key Data · Open $458.00 · Day Range 456.18 - 471.52 · 52 Week Range 167.66 - 485.96 · Market Cap $1.16T · Shares Outstanding 2.21B · Public Float 2.19B · Beta 1.30 ... Historical Price Look Up ; Volume40,561,537 ; Open$469.88 ; Closing Price$459.41 ; Day's High$471.90 ; Day's Low$459.22 ... Meta Platforms Inc META:NASDAQ ; Last | 10:45 AM EST. 461.00 quote price arrow down -14.00 (-2.95%) ; Volume. 15,001,132 ; 52 week range. 167.66 - 485.96 ... 2 days ago ... "Market Cap" is derived from the last sale price for the displayed class of listed securities and the total number of shares outstanding for ... The 96 analysts offering price forecasts for Meta Platforms have a median target of 357.92, with a high estimate of 550.00 and a low estimate of 220.00. The ... Aug 22, 2023 ... Sub-new stock price prediction, forecasting the price trends of stocks listed less than one year, is crucial for effective quantitative trading. Get Meta Platforms Inc (META.O) real-time stock quotes, news, price and financial information from Reuters to inform your trading and investments. View Meta Platforms Inc. Class A META stock quote prices, financial information, real-time forecasts, and company news from CNN. 3 days ago ... What's Next for Meta in 2024? ... stock price expected move based on current options prices. To determine what the market expects from the stock ... 461.00
from IPython.display import Image, display
imageName = "meta_feb_2_stock_price.png" # Referenced from https://investor.fb.com/stock-info/
display(Image(filename=imageName))
The idea of generating multiple responses from an LLM and comparing the responses for "Semantic Similarity" using n-gram overlap throgh METEOR score or BERT score.
Self-consistency can play in important role in chat bot agents where multiple agents or sub-agents interact with each other. If a sub-agent is being queried by an agent and is not sure of its answer, it must say so!
text = tool.run("What's the latest stock price of meta?")
print(text)
for index in range(20):
prompt = "Given the following text, return the precise stock price of Meta: " + text
print(get_completion(prompt))
Mazza joins Yahoo Finance to break down what he is seeing in earnings trends as tech stocks fly high on AI drivers. "You can choose really two companies in any ... Key Data · Open $458.00 · Day Range 456.18 - 471.52 · 52 Week Range 167.66 - 485.96 · Market Cap $1.16T · Shares Outstanding 2.21B · Public Float 2.19B · Beta 1.30 ... Historical Price Look Up ; Volume40,561,537 ; Open$469.88 ; Closing Price$459.41 ; Day's High$471.90 ; Day's Low$459.22 ... Get Meta Platforms Inc (META:NASDAQ) real-time stock quotes, news, price and financial information from CNBC. 2 days ago ... "Market Cap" is derived from the last sale price for the displayed class of listed securities and the total number of shares outstanding for ... The 96 analysts offering price forecasts for Meta Platforms have a median target of 357.92, with a high estimate of 550.00 and a low estimate of 220.00. The ... Aug 22, 2023 ... Sub-new stock price prediction, forecasting the price trends of stocks listed less than one year, is crucial for effective quantitative trading. Get Meta Platforms Inc (META.O) real-time stock quotes, news, price and financial information from Reuters to inform your trading and investments. View Meta Platforms Inc. Class A META stock quote prices, financial information, real-time forecasts, and company news from CNN. 3 days ago ... What's Next for Meta in 2024? ... stock price expected move based on current options prices. To determine what the market expects from the stock ... The precise stock price of Meta is not mentioned in the given text. The precise stock price of Meta is not mentioned in the given text. Based on the given text, the precise stock price of Meta is $459.41. The precise stock price of Meta is not explicitly mentioned in the given text. The precise stock price of Meta is not explicitly mentioned in the given text. The precise stock price of Meta is not provided in the given text. The precise stock price of Meta is not provided in the given text. The precise stock price of Meta is not specified in the given text. The precise stock price of Meta Platforms Inc. (META) is not mentioned in the given text. The precise stock price of Meta is not provided in the given text. The precise stock price of Meta is not explicitly mentioned in the given text. The precise stock price of Meta is not provided in the given text. The precise stock price of Meta (META) is not provided in the given text. Based on the given text, the precise stock price of Meta is not mentioned. The precise stock price of Meta Platforms Inc. (META) is not provided in the given text. The precise stock price of Meta is $459.41. The precise stock price of Meta Platforms Inc. (META) is not mentioned in the given text. The precise stock price of Meta is $459.41. The precise stock price of Meta is not mentioned in the given text. The precise stock price of Meta is not mentioned in the given text.
from IPython.display import Image, display
imageName = "rag_design.png" # Referenced from https://investor.fb.com/stock-info/
display(Image(filename=imageName))
from IPython.display import Image, display
imageName = "rag_kg.png" # Referenced from https://investor.fb.com/stock-info/
display(Image(filename=imageName))
text = tool.run("What's the latest stock price of meta?")
print(text)
prompt = "Given the following text, return the closing stock price of Meta: " + text
print(get_completion(prompt))
Mazza joins Yahoo Finance to break down what he is seeing in earnings trends as tech stocks fly high on AI drivers. "You can choose really two companies in any ... Key Data · Open $458.00 · Day Range 456.18 - 471.52 · 52 Week Range 167.66 - 485.96 · Market Cap $1.16T · Shares Outstanding 2.21B · Public Float 2.19B · Beta 1.30 ... Historical Price Look Up ; Volume40,561,537 ; Open$469.88 ; Closing Price$459.41 ; Day's High$471.90 ; Day's Low$459.22 ... Meta Platforms Inc META:NASDAQ ; Last | 10:45 AM EST. 461.00 quote price arrow down -14.00 (-2.95%) ; Volume. 15,001,132 ; 52 week range. 167.66 - 485.96 ... 2 days ago ... "Market Cap" is derived from the last sale price for the displayed class of listed securities and the total number of shares outstanding for ... The 96 analysts offering price forecasts for Meta Platforms have a median target of 357.92, with a high estimate of 550.00 and a low estimate of 220.00. The ... Aug 22, 2023 ... Sub-new stock price prediction, forecasting the price trends of stocks listed less than one year, is crucial for effective quantitative trading. Get Meta Platforms Inc (META.O) real-time stock quotes, news, price and financial information from Reuters to inform your trading and investments. View Meta Platforms Inc. Class A META stock quote prices, financial information, real-time forecasts, and company news from CNN. 3 days ago ... What's Next for Meta in 2024? ... stock price expected move based on current options prices. To determine what the market expects from the stock ... The closing stock price of Meta Platforms Inc (META) is $459.41.
!pip3 install nbconvert
Requirement already satisfied: nbconvert in /usr/local/lib/python3.10/dist-packages (6.5.4) Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from nbconvert) (4.9.4) Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (4.12.3) Requirement already satisfied: bleach in /usr/local/lib/python3.10/dist-packages (from nbconvert) (6.1.0) Requirement already satisfied: defusedxml in /usr/local/lib/python3.10/dist-packages (from nbconvert) (0.7.1) Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (0.4) Requirement already satisfied: jinja2>=3.0 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (3.1.3) Requirement already satisfied: jupyter-core>=4.7 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (5.7.1) Requirement already satisfied: jupyterlab-pygments in /usr/local/lib/python3.10/dist-packages (from nbconvert) (0.3.0) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (2.1.5) Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (0.8.4) Requirement already satisfied: nbclient>=0.5.0 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (0.9.0) Requirement already satisfied: nbformat>=5.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (5.9.2) Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from nbconvert) (23.2) Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (1.5.1) Requirement already satisfied: pygments>=2.4.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (2.16.1) Requirement already satisfied: tinycss2 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (1.2.1) Requirement already satisfied: traitlets>=5.0 in /usr/local/lib/python3.10/dist-packages (from nbconvert) (5.7.1) Requirement already satisfied: platformdirs>=2.5 in /usr/local/lib/python3.10/dist-packages (from jupyter-core>=4.7->nbconvert) (4.2.0) Requirement already satisfied: jupyter-client>=6.1.12 in /usr/local/lib/python3.10/dist-packages (from nbclient>=0.5.0->nbconvert) (6.1.12) Requirement already satisfied: fastjsonschema in /usr/local/lib/python3.10/dist-packages (from nbformat>=5.1->nbconvert) (2.19.1) Requirement already satisfied: jsonschema>=2.6 in /usr/local/lib/python3.10/dist-packages (from nbformat>=5.1->nbconvert) (4.19.2) Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4->nbconvert) (2.5) Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from bleach->nbconvert) (1.16.0) Requirement already satisfied: webencodings in /usr/local/lib/python3.10/dist-packages (from bleach->nbconvert) (0.5.1) Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat>=5.1->nbconvert) (23.2.0) Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat>=5.1->nbconvert) (2023.12.1) Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat>=5.1->nbconvert) (0.33.0) Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat>=5.1->nbconvert) (0.17.1) Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.10/dist-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (23.2.1) Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.10/dist-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (2.8.2) Requirement already satisfied: tornado>=4.1 in /usr/local/lib/python3.10/dist-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (6.3.2)
!ls
ape_agents 'Nov_18_2023 Class Walkthrough' 'Category Search LLM Demo' 'Nov_18_2023 In-class Exercise' cot_tot.png openai_api_key_llm_2023.gdoc cot_types.png openai_api_key_llm_2023.txt flowers 'Prompt Engineering and RAG.ipynb' flowers_kaggle.zip quotes.txt google_api_key.txt quotes.txt.1 google_cse_id.txt quotes.txt.2 image_caption_finetuned_model quotes.txt.3 image_search.png rag_design.png 'Jan_16_In_Class_Assignment ECE UW, PMP course LLM 2024' rag_kg.png Kaggle_Contest_Detect_AI_Generated_Text serpapi_key.txt 'Langchain-1-Deeplearning.ai short course' serpapi_key.txt.gdoc 'Langchain Discrepancy' simple_ape_demo.ipynb llm_agent_1.png StreamLitWorking LLM_prompting.ipynb 'Text to Image Demo.ipynb' meta_feb_2_stock_price.png the_way_of_peace.txt Nov12_inclass_exercise.ipynb
%shell jupyter nbconvert --to html prompt_engg_RAG.ipynb