Chunk ID stringlengths 5 184 | Chunk stringlengths 20 3.59k | Source stringclasses 22
values |
|---|---|---|
Evaluating Abstractive Summarization (Chunk 3) | The table shows the ROUGE scores for evaluating two different summaries against a reference text. In the case of rouge-1, Summary 2 outperforms Summary 1, indicating a better overlap of individual words and for rouge-l, Summary 2 has a higher score, implying a closer match in the longest common subsequences, and thus a... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization (Chunk 4) | While ROUGE and similar metrics, such as BLEU and METEOR, offer quantitative measures, they often fail to capture the true essence of a well-generated summary. They also correlate worse with human scores. Given the advancements in LLMs, which are adept at producing fluent and coherent summaries, traditional metrics lik... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization (Chunk 5) | Evaluating using BERTScore
ROUGE relies on the exact presence of words in both the predicted and reference texts, failing to interpret the underlying semantics. This is where BERTScore comes in and leverages the contextual embeddings from the BERT model, aiming to evaluate the similarity between a predicted and a refer... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization (Chunk 6) | The close F1 Scores between the summaries indicate that they may perform similarly in capturing the key information. However, this small difference should be interpreted with caution. Since BERTScore may not fully grasp subtleties and high-level concepts that a human evaluator might understand, reliance solely on this ... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization (Chunk 7) | Evaluating using GPT-4
Here we implement an example reference-free text evaluator using gpt-4, inspired by the G-Eval framework which evaluates the quality of generated text using large language models. Unlike metrics like ROUGE or BERTScore that rely on comparison to reference summaries, the gpt-4 based evaluator asse... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization (Chunk 8) | In this demonstration, we're using a direct scoring function where gpt-4 generates a discrete score (1-5) for each metric. Normalizing the scores and taking a weighted sum could result in more robust, continuous scores that better reflect the quality and diversity of the summaries. | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization - Part 1 | Overall, the Summary 1 appears to outperform Summary 2 in three of the four categories (Coherence, Relevance and Fluency). Both summaries are found to be consistent with each other. The result might suggest that Summary 1 is generally preferable based on the given evaluation criteria. | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization - Part 2 | Limitations
Note that LLM-based metrics could have a bias towards preferring LLM-generated texts over human-written texts. Additionally LLM based metrics are sensitive to system messages/prompts. We recommend experimenting with other techniques that can help improve performance and/or get consistent scores, striking th... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Evaluating Abstractive Summarization - Part 3 | Conclusion
Evaluating abstractive summarization remains an open area for further improvement. Traditional metrics like ROUGE, BLEU, and BERTScore provide useful automatic evaluation but have limitations in capturing semantic similarity and nuanced aspects of summarization quality. Moreover, they require reference outpu... | https://cookbook.openai.com/examples/evaluation/how_to_eval_abstractive_summarization |
Question answering using a search API and re-ranking | Searching for relevant information can sometimes feel like looking for a needle in a haystack, but don’t despair, GPTs can actually do a lot of this work for us. In this guide we explore a way to augment existing search systems with various AI techniques, helping us sift through the noise. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Mimicking Human Browsing | Two ways of retrieving information for GPT are:
Mimicking Human Browsing: GPT triggers a search, evaluates the results, and modifies the search query if necessary. It can also follow up on specific search results to form a chain of thought, much like a human user would do. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Retrieval with Embeddings | Retrieval with Embeddings: Calculate embeddings for your content and a user query, and then retrieve the content most related as measured by cosine similarity. This technique is used heavily by search engines like Google. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Combining Approaches | By combining these approaches, and drawing inspiration from re-ranking methods, we identify an approach that sits in the middle. This approach can be implemented on top of any existing search system, like the Slack search API, or an internal ElasticSearch instance with private data. Here’s how it works: | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Step 1: Search | Step 1: Search
User asks a question.
GPT generates a list of potential queries.
Search queries are executed in parallel. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Step 2: Re-rank | Step 2: Re-rank
Embeddings for each result are used to calculate semantic similarity to a generated hypothetical ideal answer to the user question.
Results are ranked and filtered based on this similarity metric. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Step 3: Answer | Step 3: Answer
Given the top search results, the model generates an answer to the user’s question, including references and links.
This hybrid approach offers relatively low latency and can be integrated into any existing search endpoint, without requiring the upkeep of a vector database. Let's dive into it! We will us... | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Setup | Setup
In addition to your OPENAI_API_KEY, you'll have to include a NEWS_API_KEY in your environment. You can get an API key here. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
User Asks a Question | User asks a question. GPT generates a list of potential queries. Search queries are executed in parallel. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Re-rank | Re-rank
Drawing inspiration from HyDE (Gao et al.), we first generate a hypothetical ideal answer to rerank our compare our results against. This helps prioritize results that look like good answers, rather than those similar to our question. Here’s the prompt we use to generate our hypothetical answer. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Generate a Hypothetical Answer | Generate a hypothetical answer to the user's question. This answer will be used to rank search results. Pretend you have all the information you need to answer, but don't use any actual facts. Instead, use placeholders like NAME did something, or NAME said something at PLACE. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Calculating Cosine Similarity | Now, let's generate embeddings for the search results and the hypothetical answer. We then calculate the cosine distance between these embeddings, giving us a semantic similarity metric. Note that we can simply calculate the dot product in lieu of doing a full cosine similarity calculation since the OpenAI embeddings a... | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Re-rank Results | Finally, we use these similarity scores to sort and filter the results. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Top 5 Articles | Print top 5 articles | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Display Top Results | These results look a lot more relevant to our original query. Now, let's use the top 5 results to generate a final answer. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Generate a Final Answer | Generate an answer to the user's question based on the given search results. TOP_RESULTS: [{'title': 'Article Title 1', 'description': 'Article Description 1', 'url': 'https://example.com/article1'}, ...] USER_QUESTION: Who won the NBA championship? And who was the MVP? Tell me a bit about the last game. | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Question answering using a search API and re-ranking | Now, in order to be as exhaustive as possible, we use the model to generate a list of diverse queries based on this question. QUERIES_INPUT = f"""
You have access to a search API that returns recent news articles. Generate an array of search queries that are relevant to this question. Use a variation of related keyword... | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Re-rank | As we can see, oftentimes, the search queries will return a large number of results, many of which are not relevant to the original question asked by the user. In order to improve the quality of the final answer, we use embeddings to re-rank and filter the results. 2. Re-rank Drawing inspiration from HyDE (Gao et al.),... | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Answer | Finally, we use these similarity scores to sort and filter the results. scored_articles = zip(articles, cosine_similarities) # Sort articles by cosine similarity sorted_articles = sorted(scored_articles, key=lambda x: x[1], reverse=True) # Print top 5 articles print("Top 5 articles:", "\n") for article, score in sorted... | https://cookbook.openai.com/examples/question_answering_using_a_search_api |
Related resources - Part 1 | People are writing great tools and papers for improving outputs from GPT. Here are some cool ones we've seen: | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 1 | Guidance: A handy looking Python library from Microsoft that uses Handlebars templating to interleave generation, prompting, and logical control. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 2 | LangChain: A popular Python/JavaScript library for chaining sequences of language model prompts. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 3 | FLAML (A Fast Library for Automated Machine Learning & Tuning): A Python library for automating selection of models, hyperparameters, and other tunable choices. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 4 | Chainlit: A Python library for making chatbot interfaces. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 5 | Guardrails.ai: A Python library for validating outputs and retrying failures. Still in alpha, so expect sharp edges and bugs. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 6 | Semantic Kernel: A Python/C#/Java library from Microsoft that supports prompt templating, function chaining, vectorized memory, and intelligent planning. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 7 | Prompttools: Open-source Python tools for testing and evaluating models, vector DBs, and prompts. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 8 | Outlines: A Python library that provides a domain-specific language to simplify prompting and constrain generation. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 9 | Promptify: A small Python library for using language models to perform NLP tasks. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 10 | Scale Spellbook: A paid product for building, comparing, and shipping language model apps. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 11 | PromptPerfect: A paid product for testing and improving prompts. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 12 | Weights & Biases: A paid product for tracking model training and prompt engineering experiments. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 13 | OpenAI Evals: An open-source library for evaluating task performance of language models and prompts. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 14 | LlamaIndex: A Python library for augmenting LLM apps with data. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 15 | Arthur Shield: A paid product for detecting toxicity, hallucination, prompt injection, etc. | https://cookbook.openai.com/related_resources |
Prompting libraries & tools - Part 16 | LMQL: A programming language for LLM interaction with support for typed prompting, control flow, constraints, and tools. | https://cookbook.openai.com/related_resources |
Prompting guides | Brex's Prompt Engineering Guide: Brex's introduction to language models and prompt engineering. | https://cookbook.openai.com/related_resources |
Prompting guides | promptingguide.ai: A prompt engineering guide that demonstrates many techniques. | https://cookbook.openai.com/related_resources |
Prompting guides | OpenAI Cookbook: Techniques to improve reliability: A slightly dated (Sep 2022) review of techniques for prompting language models. | https://cookbook.openai.com/related_resources |
Prompting guides | Lil'Log Prompt Engineering: An OpenAI researcher's review of the prompt engineering literature (as of March 2023). | https://cookbook.openai.com/related_resources |
Prompting guides | learnprompting.org: An introductory course to prompt engineering. | https://cookbook.openai.com/related_resources |
Video courses | Andrew Ng's DeepLearning.AI: A short course on prompt engineering for developers. | https://cookbook.openai.com/related_resources |
Video courses | Andrej Karpathy's Let's build GPT: A detailed dive into the machine learning underlying GPT. | https://cookbook.openai.com/related_resources |
Video courses | Prompt Engineering by DAIR.AI: A one-hour video on various prompt engineering techniques. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 1 | Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (2022): Using few-shot prompts to ask models to think step by step improves their reasoning. PaLM's score on math word problems (GSM8K) rises from 18% to 57%. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 2 | Self-Consistency Improves Chain of Thought Reasoning in Language Models (2022): Taking votes from multiple outputs improves accuracy even more. Voting across 40 outputs raises PaLM's score on math word problems further, from 57% to 74%, and code-davinci-002's from 60% to 78%. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 3 | Tree of Thoughts: Deliberate Problem Solving with Large Language Models (2023): Searching over trees of step by step reasoning helps even more than voting over chains of thought. It lifts GPT-4's scores on creative writing and crosswords. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 4 | Language Models are Zero-Shot Reasoners (2022): Telling instruction-following models to think step by step improves their reasoning. It lifts text-davinci-002's score on math word problems (GSM8K) from 13% to 41%. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 5 | Large Language Models Are Human-Level Prompt Engineers (2023): Automated searching over possible prompts found a prompt that lifts scores on math word problems (GSM8K) to 43%, 2 percentage points above the human-written prompt in Language Models are Zero-Shot Reasoners. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 6 | Reprompting: Automated Chain-of-Thought Prompt Inference Through Gibbs Sampling (2023): Automated searching over possible chain-of-thought prompts improved ChatGPT's scores on a few benchmarks by 0–20 percentage points. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 7 | Faithful Reasoning Using Large Language Models (2022): Reasoning can be improved by a system that combines: chains of thought generated by alternative selection and inference prompts, a halter model that chooses when to halt selection-inference loops, a value function to search over multiple reasoning paths, and senten... | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 8 | STaR: Bootstrapping Reasoning With Reasoning (2022): Chain of thought reasoning can be baked into models via fine-tuning. For tasks with an answer key, example chains of thoughts can be generated by language models. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 9 | ReAct: Synergizing Reasoning and Acting in Language Models (2023): For tasks with tools or an environment, chain of thought works better you prescriptively alternate between Reasoning steps (thinking about what to do) and Acting (getting information from a tool or environment). | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 10 | Reflexion: an autonomous agent with dynamic memory and self-reflection (2023): Retrying tasks with memory of prior failures improves subsequent performance. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 11 | Demonstrate-Search-Predict: Composing retrieval and language models for knowledge-intensive NLP (2023): Models augmented with knowledge via a 'retrieve-then-read' can be improved with multi-hop chains of searches. | https://cookbook.openai.com/related_resources |
Papers on advanced prompting to improve reasoning - Part 12 | Improving Factuality and Reasoning in Language Models through Multiagent Debate (2023): Generating debates between a few ChatGPT agents over a few rounds improves scores on various benchmarks. Math word problem scores rise from 77% to 85%. | https://cookbook.openai.com/related_resources |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | The aim of this notebook is to walk through a comprehensive example of how to fine-tune OpenAI models for Retrieval Augmented Generation (RAG).
We will also be integrating Qdrant and Few-Shot Learning to boost the model's performance and reduce hallucinations. This could serve as a practical guide for ML practitioners... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Setting up the Environment | Install and Import Dependencies
!pip install pandas openai tqdm tenacity scikit-learn tiktoken python-dotenv seaborn --upgrade --quiet
import json
import os
import time
import pandas as pd
import openai
import tiktoken
import seaborn as sns
from tenacity import retry, wait_exponential
from tqdm import tqdm
from colle... | null |
Data Preparation: SQuADv2 Data Subsets | For the purpose of demonstration, we'll make small slices from the train and validation splits of the SQuADv2 dataset. This dataset has questions and contexts where the answer is not present in the context, to help us evaluate how LLM handles this case.
We'll read the data from the JSON files and create a dataframe wi... | null |
Answering using Base gpt-3.5-turbo-0613 model | 3.1 Zero Shot Prompt
Let's start by using the base gpt-3.5-turbo-0613 model to answer the questions. This prompt is a simple concatenation of the question and context, with a separator token in between:
. We've a simple instruction part of the prompt:
Answer the following Question based on the Context only. Only ans... | null |
Answering using Zero Shot Prompt | 3.2 Answering using Zero Shot Prompt
Next, you'll need some re-usable functions which make an OpenAI API Call and return the answer. You'll use the ChatCompletion.create endpoint of the API, which takes a prompt and returns the completed text.
# Function with tenacity for retries
@retry(wait=wait_exponential(multiplie... | null |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | Notice that the fine-tuned model skips questions more often -- and makes fewer mistakes. This is because the fine-tuned model is more conservative and skips questions when it's not sure. | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | evaluator.plot_model_comparison(["generated_answer", "ft_generated_answer"], scenario="idk_expected", nice_names=["Baseline", "Fine-Tuned"]) | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | Notice that the fine-tuned model has learned to say "I don't know" a lot better than the prompt. Or, the model has gotten good at skipping questions. | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | Observations The fine-tuned model is better at saying "I don't know" Hallucinations drop from 100% to 0% with fine-tuning. Wrong answers drop from 17% to 6% with fine-tuning. Correct answers also drop from 83% to 60% with fine-tuning - this is because the fine-tuned model is more conservative and says "I don't know" mo... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | That said, we want to improve the correctness of the model, even if that increases the hallucinations. We're looking for a model that is both correct and conservative, striking a balance between the two. We'll use Qdrant and Few-Shot Learning to achieve this. | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | 💪 You're 2/3rds of the way there! Keep reading! | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | Section B: Few Shot Learning We'll select a few examples from the dataset, including cases where the answer is not present in the context. We'll then use these examples to create a prompt that we can use to fine-tune the model. We'll then measure the performance of the fine-tuned model. | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | What is next? Fine-Tuning OpenAI Model with Qdrant 6.1 Embed the Fine-Tuning Data 6.2 Embedding the Questions Using Qdrant to Improve RAG Prompt 6. Fine-Tuning OpenAI Model with Qdrant So far, we've been using the OpenAI model to answer questions without using examples of the answer. The previous step made it work bett... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | This is where few-shot learning comes in! Few-shot learning is a type of transfer learning that allows us to answer questions where the answer is not present in the context. We can do this by providing a few examples of the answer we're looking for, and the model will learn to answer questions where the answer is not p... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | 5.1 Embed the Training Data Embeddings are a way to represent sentences as an array of floats. We'll use the embeddings to find the most similar questions to the ones we're looking for. | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | import os from qdrant_client import QdrantClient from qdrant_client.http import models from qdrant_client.http.models import PointStruct from qdrant_client.http.models import Distance, VectorParams Now that we've the Qdrant imports in place, qdrant_client = QdrantClient( url=os.getenv("QDRANT_URL"), api_key=os.getenv("... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | 5.2 Embedding the Questions Next, you'll embed the entire training set questions. You'll use the question to question similarity to find the most similar questions to the question we're looking for. This is a workflow which is used in RAG to leverage the OpenAI model ability of in-context learning with more examples. T... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | def generate_points_from_dataframe(df: pd.DataFrame) -> List[PointStruct]: batch_size = 512 questions = df["question"].tolist() total_batches = len(questions) // batch_size + 1 pbar = tqdm(total=len(questions), desc="Generating embeddings") # Generate embeddings in batches to improve performance embeddings = [] for i i... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Fine-Tuning OpenAI Models for Retrieval Augmented Generation (RAG) with Qdrant and Few-Shot Learning | 6. Using Qdrant to Improve RAG Prompt
Now that we've uploaded the embeddings to Qdrant, we can use Qdrant to find the most similar questions to the question we're looking for. We'll use the top 5 most similar questions to create a prompt that we can use to fine-tune the model. We'll then measure the performance of the ... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
7. Fine-Tuning OpenAI Model with Qdrant | 7.1 Upload the Fine-Tuning Data to OpenAI
# Prepare the OpenAI File format i.e. JSONL from train_sample
def dataframe_to_jsonl(df):
def create_jsonl_entry(row):
messages = row["few_shot_prompt"]
return json.dumps({"messages": messages})
jsonl_output = df.progress_apply(create_jsonl_entry, axis=... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
8. Evaluation | But how well does the model perform? Let's compare the results from the 3 different models we've looked at so far:
evaluator = Evaluator(df)
evaluator.plot_model_comparison(["generated_answer", "ft_generated_answer", "ft_generated_answer_few_shot"], scenario="answer_expected", nice_names=["Baseline", "Fine-Tuned", "Fi... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
9. Conclusion | In this notebook, we've demonstrated how to fine-tune OpenAI models for specific use-cases. We've also demonstrated how to use Qdrant and Few-Shot Learning to improve the performance of the model.
Aggregate Results
So far, we've looked at the results for each scenario separately, i.e. each scenario summed to 100. Let'... | https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant |
Azure chat completion models with your own data (preview)_1 | This example shows how to use Azure OpenAI service models with your own data. The feature is currently in preview. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_2 | Azure OpenAI on your data enables you to run supported chat models such as GPT-3.5-Turbo and GPT-4 on your data without needing to train or fine-tune models. Running models on your data enables you to chat on top of, and analyze your data with greater accuracy and speed. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_3 | One of the key benefits of Azure OpenAI on your data is its ability to tailor the content of conversational AI. Because the model has access to, and can reference specific sources to support its responses, answers are not only based on its pretrained knowledge but also on the latest information available in the designa... | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_4 | This grounding data also helps the model avoid generating responses based on outdated or incorrect information. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_5 | Azure OpenAI on your own data with Azure Cognitive Search provides a customizable, pre-built solution for knowledge retrieval, from which a conversational AI application can be built. To see alternative methods for knowledge retrieval and semantic search, check out the cookbook examples for vector databases. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_6 | How it works
Azure OpenAI on your own data connects the model with your data, giving it the ability to retrieve and utilize data in a way that enhances the model's output. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_7 | Together with Azure Cognitive Search, data is retrieved from designated data sources based on the user input and provided conversation history. The data is then augmented and resubmitted as a prompt to the model, giving the model contextual information it can use to generate a response. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_8 | See the Data, privacy, and security for Azure OpenAI Service for more information. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_9 | Prerequisites
To get started, we'll cover a few prerequisites. | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_10 | To properly access the Azure OpenAI Service, we need to create the proper resources at the Azure Portal (you can check a detailed guide on how to do this in the Microsoft Docs) | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_11 | To use your own data with Azure OpenAI models, you will need: | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_12 | Azure OpenAI access and a resource with a chat model deployed (for example, GPT-3 or GPT-4) | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Azure chat completion models with your own data (preview)_13 | Azure Cognitive Search resource | https://cookbook.openai.com/examples/azure/chat_with_your_own_data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.