{ "cells": [ { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "42084110-295b-493a-9b3e-5d8d29ff78b3", "showTitle": false, "title": "" } }, "source": [ "# LLM RAG Evaluation with MLflow Example Notebook\n", "\n", "In this notebook, we will demonstrate how to evaluate various a RAG system with MLflow." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Download this Notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We need to set our OpenAI API key.\n", "\n", "In order to set your private key safely, please be sure to either export your key through a command-line terminal for your current instance, or, for a permanent addition to all user-based sessions, configure your favored environment management configuration file (i.e., .bashrc, .zshrc) to have the following entry:\n", "\n", "`OPENAI_API_KEY=`\n", "\n", "If using Azure OpenAI, you will instead need to set\n", "\n", "`OPENAI_API_TYPE=\"azure\"`\n", "\n", "`OPENAI_API_VERSION=`\n", "\n", "`OPENAI_API_KEY=.<>.<>.com>`\n", "\n", "`OPENAI_API_DEPLOYMENT_NAME=`\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "fb946228-62fb-4d68-9732-75935c9cb401", "showTitle": false, "title": "" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "import mlflow\n", "import os\n", "os.environ[\"OPENAI_API_KEY\"] =\"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\"\n" ] }, { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "273d1345-95d7-435a-a7b6-a5f3dbb3f073", "showTitle": false, "title": "" } }, "source": [ "## Create a RAG system\n", "\n", "Use Langchain and Chroma to create a RAG system that answers questions based on the MLflow documentation." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "2c28d0ad-f469-46ab-a2b4-c5e8db50a729", "showTitle": false, "title": "" } }, "outputs": [], "source": [ "from langchain.chains import RetrievalQA\n", "from langchain.document_loaders import WebBaseLoader\n", "from langchain.embeddings.openai import OpenAIEmbeddings\n", "from langchain.llms import OpenAI\n", "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain.vectorstores import Chroma\n", "from langchain.chat_models import ChatOpenAI\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "83a7e77e-6717-472a-86dc-02e2c356ddef", "showTitle": false, "title": "" } }, "outputs": [], "source": [ "loader = WebBaseLoader(\"https://mlflow.org/docs/latest/index.html\")\n", "\n", "documents = loader.load()\n", "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", "texts = text_splitter.split_documents(documents)\n", "\n", "embeddings = OpenAIEmbeddings()\n", "docsearch = Chroma.from_documents(texts, embeddings)\n", "\n", "qa = RetrievalQA.from_chain_type(\n", " llm=ChatOpenAI(model_name=\"gpt-3.5-turbo-0125\" , temperature=0),\n", " chain_type=\"stuff\",\n", " retriever=docsearch.as_retriever(),\n", " return_source_documents=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "fd70bcf6-7c44-44d3-9435-567b82611e1c", "showTitle": false, "title": "" } }, "source": [ "## Evaluate the RAG system using `mlflow.evaluate()`" ] }, { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "de1bc359-2e40-459c-bea4-bed35a117988", "showTitle": false, "title": "" } }, "source": [ "Create a simple function that runs each input through the RAG chain" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "667ec809-2bb5-4170-9937-6804386b41ec", "showTitle": false, "title": "" } }, "outputs": [], "source": [ "def model(input_df):\n", " answer = []\n", " for index, row in input_df.iterrows():\n", " answer.append(qa(row[\"questions\"]))\n", "\n", " return answer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "d1064306-b7f3-4b3e-825c-4353d808f21d", "showTitle": false, "title": "" } }, "source": [ "Create an eval dataset" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "a5481491-e4a9-42ea-8a3f-f527faffd04d", "showTitle": false, "title": "" } }, "outputs": [], "source": [ "eval_df = pd.DataFrame(\n", " {\n", " \"questions\": [\n", " \"What is MLflow?\",\n", " \"How to run mlflow.evaluate()?\",\n", " \"How to log_table()?\",\n", " \"How to load_table()?\",\n", " ],\n", " }\n", ")" ] }, { "cell_type": "markdown", "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "9c3c8023-8feb-427a-b36d-34cd1853a5dc", "showTitle": false, "title": "" } }, "source": [ "Create a faithfulness metric" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "3882b940-9c25-41ce-a301-72d8c0c90aaa", "showTitle": false, "title": "" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "EvaluationMetric(name=faithfulness, greater_is_better=True, long_name=faithfulness, version=v1, metric_details=\n", "Task:\n", "You must return the following fields in your response in two lines, one below the other:\n", "score: Your numerical score for the model's faithfulness based on the rubric\n", "justification: Your reasoning about the model's faithfulness score\n", "\n", "You are an impartial judge. You will be given an input that was sent to a machine\n", "learning model, and you will be given an output that the model produced. You\n", "may also be given additional information that was used by the model to generate the output.\n", "\n", "Your task is to determine a numerical score called faithfulness based on the input and output.\n", "A definition of faithfulness and a grading rubric are provided below.\n", "You must use the grading rubric to determine your score. You must also justify your score.\n", "\n", "Examples could be included below for reference. Make sure to use them as references and to\n", "understand them before completing the task.\n", "\n", "Input:\n", "{input}\n", "\n", "Output:\n", "{output}\n", "\n", "{grading_context_columns}\n", "\n", "Metric definition:\n", "Faithfulness is only evaluated with the provided output and provided context, please ignore the provided input entirely when scoring faithfulness. Faithfulness assesses how much of the provided output is factually consistent with the provided context. A higher score indicates that a higher proportion of claims present in the output can be derived from the provided context. Faithfulness does not consider how much extra information from the context is not present in the output.\n", "\n", "Grading rubric:\n", "Faithfulness: Below are the details for different scores:\n", "- Score 1: None of the claims in the output can be inferred from the provided context.\n", "- Score 2: Some of the claims in the output can be inferred from the provided context, but the majority of the output is missing from, inconsistent with, or contradictory to the provided context.\n", "- Score 3: Half or more of the claims in the output can be inferred from the provided context.\n", "- Score 4: Most of the claims in the output can be inferred from the provided context, with very little information that is not directly supported by the provided context.\n", "- Score 5: All of the claims in the output are directly supported by the provided context, demonstrating high faithfulness to the provided context.\n", "\n", "Examples:\n", "\n", "Example Input:\n", "How do I disable MLflow autologging?\n", "\n", "Example Output:\n", "mlflow.autolog(disable=True) will disable autologging for all functions. In Databricks, autologging is enabled by default. \n", "\n", "Additional information used by the model:\n", "key: context\n", "value:\n", "mlflow.autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: Optional[Dict[str, str]] = None) → None[source] Enables (or disables) and configures autologging for all supported integrations. The parameters are passed to any autologging integrations that support them. See the tracking docs for a list of supported autologging integrations. Note that framework-specific configurations set at any point will take precedence over any configurations set by this function.\n", "\n", "Example score: 2\n", "Example justification: The output provides a working solution, using the mlflow.autolog() function that is provided in the context.\n", " \n", "\n", "Example Input:\n", "How do I disable MLflow autologging?\n", "\n", "Example Output:\n", "mlflow.autolog(disable=True) will disable autologging for all functions.\n", "\n", "Additional information used by the model:\n", "key: context\n", "value:\n", "mlflow.autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: Optional[Dict[str, str]] = None) → None[source] Enables (or disables) and configures autologging for all supported integrations. The parameters are passed to any autologging integrations that support them. See the tracking docs for a list of supported autologging integrations. Note that framework-specific configurations set at any point will take precedence over any configurations set by this function.\n", "\n", "Example score: 5\n", "Example justification: The output provides a solution that is using the mlflow.autolog() function that is provided in the context.\n", " \n", "\n", "You must return the following fields in your response in two lines, one below the other:\n", "score: Your numerical score for the model's faithfulness based on the rubric\n", "justification: Your reasoning about the model's faithfulness score\n", "\n", "Do not add additional new lines. Do not add any other fields.\n", " )\n" ] } ], "source": [ "from mlflow.metrics.genai import EvaluationExample, faithfulness\n", "\n", "# Create a good and bad example for faithfulness in the context of this problem\n", "faithfulness_examples = [\n", " EvaluationExample(\n", " input=\"How do I disable MLflow autologging?\",\n", " output=\"mlflow.autolog(disable=True) will disable autologging for all functions. In Databricks, autologging is enabled by default. \",\n", " score=2,\n", " justification=\"The output provides a working solution, using the mlflow.autolog() function that is provided in the context.\",\n", " grading_context={\n", " \"context\": \"mlflow.autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: Optional[Dict[str, str]] = None) → None[source] Enables (or disables) and configures autologging for all supported integrations. The parameters are passed to any autologging integrations that support them. See the tracking docs for a list of supported autologging integrations. Note that framework-specific configurations set at any point will take precedence over any configurations set by this function.\"\n", " },\n", " ),\n", " EvaluationExample(\n", " input=\"How do I disable MLflow autologging?\",\n", " output=\"mlflow.autolog(disable=True) will disable autologging for all functions.\",\n", " score=5,\n", " justification=\"The output provides a solution that is using the mlflow.autolog() function that is provided in the context.\",\n", " grading_context={\n", " \"context\": \"mlflow.autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: Optional[Dict[str, str]] = None) → None[source] Enables (or disables) and configures autologging for all supported integrations. The parameters are passed to any autologging integrations that support them. See the tracking docs for a list of supported autologging integrations. Note that framework-specific configurations set at any point will take precedence over any configurations set by this function.\"\n", " },\n", " ),\n", "]\n", "\n", "faithfulness_metric = faithfulness(model=\"openai:/gpt-4\", examples=faithfulness_examples)\n", "print(faithfulness_metric)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a relevance metric. You can see the full grading prompt by printing the metric or by accessing the `metric_details` attribute of the metric." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "EvaluationMetric(name=relevance, greater_is_better=True, long_name=relevance, version=v1, metric_details=\n", "Task:\n", "You must return the following fields in your response in two lines, one below the other:\n", "score: Your numerical score for the model's relevance based on the rubric\n", "justification: Your reasoning about the model's relevance score\n", "\n", "You are an impartial judge. You will be given an input that was sent to a machine\n", "learning model, and you will be given an output that the model produced. You\n", "may also be given additional information that was used by the model to generate the output.\n", "\n", "Your task is to determine a numerical score called relevance based on the input and output.\n", "A definition of relevance and a grading rubric are provided below.\n", "You must use the grading rubric to determine your score. You must also justify your score.\n", "\n", "Examples could be included below for reference. Make sure to use them as references and to\n", "understand them before completing the task.\n", "\n", "Input:\n", "{input}\n", "\n", "Output:\n", "{output}\n", "\n", "{grading_context_columns}\n", "\n", "Metric definition:\n", "Relevance encompasses the appropriateness, significance, and applicability of the output with respect to both the input and context. Scores should reflect the extent to which the output directly addresses the question provided in the input, given the provided context.\n", "\n", "Grading rubric:\n", "Relevance: Below are the details for different scores:- Score 1: The output doesn't mention anything about the question or is completely irrelevant to the provided context.\n", "- Score 2: The output provides some relevance to the question and is somehow related to the provided context.\n", "- Score 3: The output mostly answers the question and is largely consistent with the provided context.\n", "- Score 4: The output answers the question and is consistent with the provided context.\n", "- Score 5: The output answers the question comprehensively using the provided context.\n", "\n", "Examples:\n", "\n", "Example Input:\n", "How is MLflow related to Databricks?\n", "\n", "Example Output:\n", "Databricks is a data engineering and analytics platform designed to help organizations process and analyze large amounts of data. Databricks is a company specializing in big data and machine learning solutions.\n", "\n", "Additional information used by the model:\n", "key: context\n", "value:\n", "MLflow is an open-source platform for managing the end-to-end machine learning (ML) lifecycle. It was developed by Databricks, a company that specializes in big data and machine learning solutions. MLflow is designed to address the challenges that data scientists and machine learning engineers face when developing, training, and deploying machine learning models.\n", "\n", "Example score: 2\n", "Example justification: The output provides relevant information about Databricks, mentioning it as a company specializing in big data and machine learning solutions. However, it doesn't directly address how MLflow is related to Databricks, which is the specific question asked in the input. Therefore, the output is only somewhat related to the provided context.\n", " \n", "\n", "Example Input:\n", "How is MLflow related to Databricks?\n", "\n", "Example Output:\n", "MLflow is a product created by Databricks to enhance the efficiency of machine learning processes.\n", "\n", "Additional information used by the model:\n", "key: context\n", "value:\n", "MLflow is an open-source platform for managing the end-to-end machine learning (ML) lifecycle. It was developed by Databricks, a company that specializes in big data and machine learning solutions. MLflow is designed to address the challenges that data scientists and machine learning engineers face when developing, training, and deploying machine learning models.\n", "\n", "Example score: 4\n", "Example justification: The output provides a relevant and accurate statement about the relationship between MLflow and Databricks. While it doesn't provide extensive detail, it still offers a substantial and meaningful response. To achieve a score of 5, the response could be further improved by providing additional context or details about how MLflow specifically functions within the Databricks ecosystem.\n", " \n", "\n", "You must return the following fields in your response in two lines, one below the other:\n", "score: Your numerical score for the model's relevance based on the rubric\n", "justification: Your reasoning about the model's relevance score\n", "\n", "Do not add additional new lines. Do not add any other fields.\n", " )\n" ] } ], "source": [ "from mlflow.metrics.genai import EvaluationExample, relevance\n", "\n", "relevance_metric = relevance(model=\"openai:/gpt-4\")\n", "print(relevance_metric)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "eval_df_final=eval_df.copy(deep=True)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "aa=model(eval_df)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'query': 'What is MLflow?',\n", " 'result': 'MLflow is an open-source platform designed to help machine learning practitioners and teams manage the complexities of the machine learning process. It focuses on the full lifecycle of machine learning projects, making sure that each phase is manageable, traceable, and reproducible.',\n", " 'source_documents': [Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation\\n\\n2.12.1\\n\\n\\n MLflow\\n\\nWhat is MLflow?\\nGetting Started with MLflow\\nNew Features\\nLLMs\\nModel Evaluation\\nDeep Learning\\nTraditional ML\\nDeployment\\nMLflow Tracking\\nSystem Metrics\\nMLflow Projects\\nMLflow Models\\nMLflow Model Registry\\nMLflow Recipes\\nMLflow Plugins\\nMLflow Authentication\\nCommand-Line Interface\\nSearch Runs\\nSearch Experiments\\nPython API\\nR API\\nJava API\\nREST API\\nOfficial MLflow Docker Image\\nCommunity Model Flavors\\nTutorials and Examples\\n\\n\\nContribute\\n\\n\\nDocumentation \\nMLflow: A Tool for Managing the Machine Learning Lifecycle', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to run mlflow.evaluate()?',\n", " 'result': 'To run `mlflow.evaluate()`, you need to follow these steps:\\n\\n1. Ensure you have MLflow installed in your environment.\\n2. Import the necessary libraries, including `mlflow`.\\n3. Load your model and data.\\n4. Use the `mlflow.evaluate()` function, passing in your model, data, and any other necessary parameters.\\n5. Review the evaluation results and metrics provided by the function.\\n\\nIf you need more specific details or code examples, please refer to the MLflow documentation or tutorials for a step-by-step guide on running `mlflow.evaluate()`.',\n", " 'source_documents': [Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Learn how to evaluate LLMs and LLM-powered solutions with MLflow Evaluate.\\n \\n\\n Using Custom PyFunc with LLMs\\n \\n\\n Explore the nuances of packaging and deploying advanced LLMs in MLflow using custom PyFuncs. This guide delves deep\\n into managing intricate model behaviors, ensuring seamless and efficient LLM deployments.\\n \\n\\n Evaluation for RAG\\n \\n\\n Learn how to evaluate Retrieval Augmented Generation applications by leveraging LLMs to generate a evaluation dataset and evaluate it using the built-in metrics in the MLflow Evaluate API.\\n \\n\\n LLM Tracking with MLflow', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to log_table()?',\n", " 'result': \"I don't have information on a specific function called `log_table()` in the context provided. It's possible that it might be a custom function or a feature not explicitly mentioned in the provided context. If you can provide more details or context, I may be able to assist you further.\",\n", " 'source_documents': [Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content=\"Dive into the intricacies of MLflow's LLM Tracking system. From capturing prompts to monitoring generated outputs,\\n discover how MLflow provides a holistic solution for managing LLM interactions.\", metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to load_table()?',\n", " 'result': \"I'm not sure what `load_table()` refers to in this context. If you can provide more information or context, I might be able to help you better.\",\n", " 'source_documents': [Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='This guide showcases the seamless end-to-end process of training a linear regression model, packaging it in a reproducible format,\\n and deploying to a Kubernetes cluster using MLflow. Explore how MLflow simplifies model deployment to production environments.\\n \\n\\n\\nNext \\n\\n\\n © MLflow Project, a Series of LF Projects, LLC. All rights reserved.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]}]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aa" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'query': 'What is MLflow?',\n", " 'result': 'MLflow is an open-source platform designed to help machine learning practitioners and teams manage the complexities of the machine learning process. It focuses on the full lifecycle of machine learning projects, ensuring that each phase is manageable, traceable, and reproducible. It offers features such as tracking, projects, models, model registry, and more to assist in solving real-world MLOps problems.',\n", " 'source_documents': [Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle \\nMLflow is an open-source platform, purpose-built to assist machine learning practitioners and teams in\\nhandling the complexities of the machine learning process. MLflow focuses on the full lifecycle for\\nmachine learning projects, ensuring that each phase is manageable, traceable, and reproducible.\\nIn each of the sections below, you will find overviews, guides, and step-by-step tutorials to walk you through\\nthe features of MLflow and how they can be leveraged to solve real-world MLOps problems.\\n\\nGetting Started with MLflow \\nIf this is your first time exploring MLflow, the tutorials and guides here are a great place to start. The emphasis in each of these is\\ngetting you up to speed as quickly as possible with the basic functionality, terms, APIs, and general best practices of using MLflow in order to\\nenhance your learning in area-specific guides and tutorials.\\n\\nGetting Started Guides and Quickstarts', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation\\n\\n2.12.1\\n\\n\\n MLflow\\n\\nWhat is MLflow?\\nGetting Started with MLflow\\nNew Features\\nLLMs\\nModel Evaluation\\nDeep Learning\\nTraditional ML\\nDeployment\\nMLflow Tracking\\nSystem Metrics\\nMLflow Projects\\nMLflow Models\\nMLflow Model Registry\\nMLflow Recipes\\nMLflow Plugins\\nMLflow Authentication\\nCommand-Line Interface\\nSearch Runs\\nSearch Experiments\\nPython API\\nR API\\nJava API\\nREST API\\nOfficial MLflow Docker Image\\nCommunity Model Flavors\\nTutorials and Examples\\n\\n\\nContribute\\n\\n\\nDocumentation \\nMLflow: A Tool for Managing the Machine Learning Lifecycle', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to run mlflow.evaluate()?',\n", " 'result': 'To run `mlflow.evaluate()`, you need to follow these steps:\\n\\n1. Import the necessary libraries:\\n```python\\nimport mlflow\\n```\\n\\n2. Load your model and data:\\n```python\\nmodel = load_model() # Load your model\\ndata = load_data() # Load your evaluation data\\n```\\n\\n3. Use `mlflow.evaluate()` to evaluate your model:\\n```python\\nmlflow.evaluate(model, data)\\n```\\n\\n4. Review the evaluation metrics and visual insights in the MLflow UI.\\n\\nIf you need more specific details or have a particular use case in mind, please provide additional context for a more tailored explanation.',\n", " 'source_documents': [Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Model Evaluation \\nDive into MLflow’s robust framework for evaluating the performance of your ML models.\\nWith support for traditional ML evaluation (classification and regression tasks), as well as support for evaluating large language models (LLMs),\\nthis suite of APIs offers a simple but powerful automated approach to evaluating the quality of the model development work that you’re doing.\\nIn particular, for LLM evaluation, the mlflow.evaluate() API allows you to validate not only models, but providers and prompts.\\nBy leveraging your own datasets and using the provided default evaluation criteria for tasks such as text summarization and question answering, you can\\nget reliable metrics that allow you to focus on improving the quality of your solution, rather than spending time writing scoring code.\\nVisual insights are also available through the MLflow UI, showcasing logged outputs, auto-generated plots, and model comparison artifacts.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='Learn how to evaluate LLMs and LLM-powered solutions with MLflow Evaluate.\\n \\n\\n Using Custom PyFunc with LLMs\\n \\n\\n Explore the nuances of packaging and deploying advanced LLMs in MLflow using custom PyFuncs. This guide delves deep\\n into managing intricate model behaviors, ensuring seamless and efficient LLM deployments.\\n \\n\\n Evaluation for RAG\\n \\n\\n Learn how to evaluate Retrieval Augmented Generation applications by leveraging LLMs to generate a evaluation dataset and evaluate it using the built-in metrics in the MLflow Evaluate API.\\n \\n\\n LLM Tracking with MLflow', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to log_table()?',\n", " 'result': \"I don't have information on a specific function called `log_table()` in the context provided. It's possible that it might be a custom function or a feature not covered in the provided context. If you can provide more details or context, I may be able to assist you further.\",\n", " 'source_documents': [Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content=\"Dive into the intricacies of MLflow's LLM Tracking system. From capturing prompts to monitoring generated outputs,\\n discover how MLflow provides a holistic solution for managing LLM interactions.\", metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]},\n", " {'query': 'How to load_table()?',\n", " 'result': \"I don't have information on a function called `load_table()` in the context provided. It seems to be outside the scope of the MLflow Tracking, Autologging, and Deployment Quickstart guides. If you can provide more context or clarify where `load_table()` is from, I may be able to assist you further.\",\n", " 'source_documents': [Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='MLflow Tracking Quickstart\\n \\n\\n A great place to start to learn the fundamentals of MLflow Tracking! Learn in 5 minutes how to log, register, and load a model for inference.\\n \\n\\n Intro to MLflow Tutorial\\n \\n\\n Learn how to get started with the basics of MLflow in a step-by-step instructional tutorial that shows the critical\\n path to logging your first model\\n \\n\\n Autologging Quickstart\\n \\n\\n Short on time? This is a no-frills quickstart that shows how to leverage autologging during training and how to\\n load a model for inference\\n \\n\\n Deployment Quickstart', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'}),\n", " Document(page_content='This guide showcases the seamless end-to-end process of training a linear regression model, packaging it in a reproducible format,\\n and deploying to a Kubernetes cluster using MLflow. Explore how MLflow simplifies model deployment to production environments.\\n \\n\\n\\nNext \\n\\n\\n © MLflow Project, a Series of LF Projects, LLC. All rights reserved.', metadata={'language': 'en', 'source': 'https://mlflow.org/docs/latest/index.html', 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle — MLflow 2.12.1 documentation'})]}]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eval_df_final[\"results\"]=model(eval_df)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": { "byteLimit": 2048000, "rowLimit": 10000 }, "inputWidgets": {}, "nuid": "ea40ce52-6ac7-4c20-9669-d24f80a6cebe", "showTitle": false, "title": "" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/u/marshad/.conda/envs/agllm-env1/lib/python3.9/site-packages/mlflow/data/digest_utils.py:26: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n", " string_columns = trimmed_df.columns[(df.applymap(type) == str).all(0)]\n", "/u/marshad/.conda/envs/agllm-env1/lib/python3.9/site-packages/mlflow/models/evaluation/base.py:414: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n", " data = data.applymap(_hash_array_like_element_as_bytes)\n", "2024/04/21 17:23:37 INFO mlflow.models.evaluation.base: Evaluating the model with the default evaluator.\n", "2024/04/21 17:23:37 INFO mlflow.models.evaluation.default_evaluator: Computing model predictions.\n", "2024/04/21 17:23:44 INFO mlflow.models.evaluation.default_evaluator: Testing metrics on first row...\n", "2024/04/21 17:23:44 WARNING mlflow.metrics.metric_definitions: Failed to load 'toxicity' metric (error: ModuleNotFoundError(\"No module named 'evaluate'\")), skipping metric logging.\n", "2024/04/21 17:23:44 WARNING mlflow.metrics.metric_definitions: Failed to load flesch kincaid metric, skipping metric logging.\n", "2024/04/21 17:23:44 WARNING mlflow.metrics.metric_definitions: Failed to load automated readability index metric, skipping metric logging.\n", "100%|██████████| 1/1 [00:03<00:00, 3.53s/it]\n", "100%|██████████| 1/1 [00:03<00:00, 3.72s/it]\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating builtin metrics: token_count\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating builtin metrics: toxicity\n", "2024/04/21 17:23:51 WARNING mlflow.metrics.metric_definitions: Failed to load 'toxicity' metric (error: ModuleNotFoundError(\"No module named 'evaluate'\")), skipping metric logging.\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating builtin metrics: flesch_kincaid_grade_level\n", "2024/04/21 17:23:51 WARNING mlflow.metrics.metric_definitions: Failed to load flesch kincaid metric, skipping metric logging.\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating builtin metrics: ari_grade_level\n", "2024/04/21 17:23:51 WARNING mlflow.metrics.metric_definitions: Failed to load automated readability index metric, skipping metric logging.\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating builtin metrics: exact_match\n", "2024/04/21 17:23:51 INFO mlflow.models.evaluation.default_evaluator: Evaluating metrics: faithfulness\n", "100%|██████████| 4/4 [00:03<00:00, 1.02it/s]\n", "2024/04/21 17:23:55 INFO mlflow.models.evaluation.default_evaluator: Evaluating metrics: relevance\n", "100%|██████████| 4/4 [00:04<00:00, 1.20s/it]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'latency/mean': 1.7213420271873474, 'latency/variance': 0.04483020464773446, 'latency/p90': 1.942362928390503, 'faithfulness/v1/mean': 4.75, 'faithfulness/v1/variance': 0.1875, 'faithfulness/v1/p90': 5.0, 'relevance/v1/mean': 3.75, 'relevance/v1/variance': 1.6875, 'relevance/v1/p90': 5.0}\n" ] } ], "source": [ "results = mlflow.evaluate(\n", " model,\n", " eval_df,\n", " model_type=\"question-answering\",\n", " evaluators=\"default\",\n", " predictions=\"result\",\n", " extra_metrics=[faithfulness_metric, relevance_metric, mlflow.metrics.latency()],\n", " evaluator_config={\n", " \"col_mapping\": {\n", " \"inputs\": \"questions\",\n", " \"context\": \"source_documents\",\n", " }\n", " },\n", ")\n", "print(results.metrics)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 13, "metadata": { "application/vnd.databricks.v1+cell": { "cellMetadata": {}, "inputWidgets": {}, "nuid": "989a0861-5153-44e6-a19d-efcae7fe6cb5", "showTitle": false, "title": "" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "747f65b309b94257b396eebffe814fa6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading artifacts: 0%| | 0/1 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
questionsoutputssource_documentslatencytoken_counttoxicity/v1/scoreflesch_kincaid_grade_level/v1/scoreari_grade_level/v1/scorefaithfulness/v1/scorefaithfulness/v1/justificationrelevance/v1/scorerelevance/v1/justification
0What is MLflow?MLflow is an open-source platform, purpose-bu...[{'lc_attributes': {}, 'lc_namespace': ['langc...1.989822530.00013712.518.45The output provided by the model is a direct e...5The output provides a comprehensive answer to ...
1How to run mlflow.evaluate()?The mlflow.evaluate() API allows you to valid...[{'lc_attributes': {}, 'lc_namespace': ['langc...1.945368550.0002009.112.65The output provided by the model is completely...4The output provides a relevant and accurate ex...
2How to log_table()?You can log a table with MLflow using the log...[{'lc_attributes': {}, 'lc_namespace': ['langc...1.521511320.0002895.06.81The output claims that you can log a table wit...5The output provides a comprehensive answer to ...
3How to load_table()?You can't load_table() with MLflow. MLflow is...[{'lc_attributes': {}, 'lc_namespace': ['langc...1.105279270.0002795.88.85The output claim that \"You can't load_table() ...4The output provides a relevant and accurate re...
\n", "" ], "text/plain": [ " questions \\\n", "0 What is MLflow? \n", "1 How to run mlflow.evaluate()? \n", "2 How to log_table()? \n", "3 How to load_table()? \n", "\n", " outputs \\\n", "0 MLflow is an open-source platform, purpose-bu... \n", "1 The mlflow.evaluate() API allows you to valid... \n", "2 You can log a table with MLflow using the log... \n", "3 You can't load_table() with MLflow. MLflow is... \n", "\n", " source_documents latency token_count \\\n", "0 [{'lc_attributes': {}, 'lc_namespace': ['langc... 1.989822 53 \n", "1 [{'lc_attributes': {}, 'lc_namespace': ['langc... 1.945368 55 \n", "2 [{'lc_attributes': {}, 'lc_namespace': ['langc... 1.521511 32 \n", "3 [{'lc_attributes': {}, 'lc_namespace': ['langc... 1.105279 27 \n", "\n", " toxicity/v1/score flesch_kincaid_grade_level/v1/score \\\n", "0 0.000137 12.5 \n", "1 0.000200 9.1 \n", "2 0.000289 5.0 \n", "3 0.000279 5.8 \n", "\n", " ari_grade_level/v1/score faithfulness/v1/score \\\n", "0 18.4 5 \n", "1 12.6 5 \n", "2 6.8 1 \n", "3 8.8 5 \n", "\n", " faithfulness/v1/justification relevance/v1/score \\\n", "0 The output provided by the model is a direct e... 5 \n", "1 The output provided by the model is completely... 4 \n", "2 The output claims that you can log a table wit... 5 \n", "3 The output claim that \"You can't load_table() ... 4 \n", "\n", " relevance/v1/justification \n", "0 The output provides a comprehensive answer to ... \n", "1 The output provides a relevant and accurate ex... \n", "2 The output provides a comprehensive answer to ... \n", "3 The output provides a relevant and accurate re... " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.tables[\"eval_results_table\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "application/vnd.databricks.v1+notebook": { "dashboards": [], "language": "python", "notebookMetadata": { "pythonIndentUnit": 2 }, "notebookName": "LLM Evaluation Examples -- RAG", "widgets": {} }, "kernelspec": { "display_name": "mlflow-dev-env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.19" } }, "nbformat": 4, "nbformat_minor": 0 }