avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2837

Abstract

class="hljs-string">'r'</span>) <span class="hljs-keyword">as</span> f: <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> f: <span class="hljs-comment"># Process the data and add to the dataset using client API</span> client.create_chat_example( messages=[ {<span class="hljs-string">"type"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"data"</span>: {<span class="hljs-string">"content"</span>: <span class="hljs-string">"You are a helpful assistant that is knowledgeable about SQL. Only output the SQL."</span>}}, {<span class="hljs-string">"type"</span>: <span class="hljs-string">"human"</span>, <span class="hljs-string">"data"</span>: {<span class="hljs-string">"content"</span>: example}} ], generations={<span class="hljs-string">"type"</span>: <span class="hljs-string">"ai"</span>, <span class="hljs-string">"data"</span>: {<span class="hljs-string">"content"</span>: assistant_content}}, dataset_id=dataset.<span class="hljs-built_in">id</span> )</pre></div><p id="1684">The above code snippet demonstrates the process of creating and adding data to a dataset in LangSmith.</p><h2 id="85af">Fine-Tuning and Assessment</h2><p id="8795">Once the data is uploaded, the next step involves fine-tuning and assessing the models. Below is an example of fine-tuning a model and evaluating it using LangSmith:</p><div id="fd87"><pre>import replicate

<span class="hljs-comment"># Fine-tune a model</span> training = replicate.trainings.create( <span class="hljs-attribute">version</span>=<span class="hljs-string">"meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d"</span>, input={ <span class="hljs-string">"train_data"</span>: <span class="hljs-string">"https://storage.googleapis.com/chatopensource-replicate-demo/selected_sql_create_context_v4.jsonl"</span>, <span class="hljs-string">"num_train_epochs"</span>: 3 }, <span class="hljs-attribute">destination</span>=<span class="hljs-string">"papermoose/test"</span> )

<span class="hljs-comment"># Evaluate the model using LangSmith</span> async def evaluate_dataset(<span class="hljs-attribute">dataset_name</span>=None, <span class="hljs-attribute">num_repetitions</span>=1, <span class="hljs-attribute">model</span>=<span class="hljs-string">"gpt-4-0613"</span>, <span class="hljs-attribute">project_name</span>=None): # Define the chat model <span class="hljs-keyword">to</span> test model_to_test = Replicate( <span class="hljs-attribute">model</span>=model, model_kwargs={<span class="hljs-string">"temperature"</span>: 0.75, <span class="hljs-string">"max_length"</span>: 500, <span class="hljs-

Options

string">"top_p"</span>: 1}, )

# <span class="hljs-built_in">Run</span> evaluation on the dataset using LangSmith
chain_results = await arun_on_dataset(
    client,
    <span class="hljs-attribute">dataset_name</span>=dataset_name,
    <span class="hljs-attribute">llm_or_chain_factory</span>=model_to_test,
    <span class="hljs-attribute">evaluation</span>=eval_config,
    <span class="hljs-attribute">num_repetitions</span>=num_repetitions,
    <span class="hljs-attribute">project_name</span>=project_name
)</pre></div><p id="4a94">The above code snippet showcases the process of fine-tuning a model and evaluating it using LangSmith.</p><h2 id="121b">Observations and Findings</h2><p id="ccf8">After evaluating the models, observations and findings can be made based on the results. The data obtained from LangSmith can be visualized and analyzed to draw meaningful conclusions. Here’s an example of visualizing the results using ChatGPT advanced data analysis:</p><div id="235b"><pre><span class="hljs-comment"># Visualize the results using ChatGPT advanced data analysis</span>

<span class="hljs-comment"># Code for graphing out the results</span></pre></div><p id="6f06">The above code snippet demonstrates how to visualize the results obtained from LangSmith using advanced data analysis.</p><h2 id="7d7a">Conclusion</h2><p id="8b98">In this tutorial, we have demonstrated how to test fine-tuned open source models in LangSmith using code snippets and examples. We covered the process of uploading data to LangSmith, fine-tuning and assessing models, and visualizing the results. LangSmith provides a convenient platform for evaluating and comparing fine-tuned open source models and can be a valuable tool for developers and researchers working with language models.</p><div id="02e7" class="link-block"> <a href="https://readmedium.com/langchain-can-free-oss-models-be-integrated-with-fireworks-ai-for-the-playground-2a2544db0a3b"> <div> <div> <h2>LANGCHAIN — Can Free OSS Models be Integrated with Fireworks AI for the Playground?</h2> <div><h3>Technology alone is not enough. It’s technology married with the liberal arts, married with the humanities, that yields…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="0182">By leveraging LangSmith, developers and researchers can streamline the evaluation and comparison of fine-tuned open source models, enabling them to make informed decisions when choosing the best tool for the job.</p></article></body>

LANGCHAIN — Is It Effective to Test Fine-Tuned Open Source Models in Langsmith?

The most dangerous phrase in the language is, ‘We’ve always done it this way.’ — Grace Hopper.

Open source models have become increasingly capable for use in various applications, and the ability to fine-tune these models further expands their utility. LangSmith offers a solution for evaluating and comparing fine-tuned open source models, providing a convenient UI and API for creating evaluation datasets and running tests on multiple models. In this tutorial, we will walk through the process of testing fine-tuned open source models in LangSmith using code snippets and examples.

Uploading Data to LangSmith

LangSmith simplifies the process of uploading data via Python or the user interface. Below is an example of how to upload a dataset in CSV format using the LangSmith Python client:

from langsmith import Client

# Create a dataset
def create_dataset(dataset_name=None):
    client = Client()
    dataset_name = dataset_name
    client.create_dataset(dataset_name=dataset_name)
    return dataset_name

# Add data to the dataset
def add_to_dataset(dataset_name, validation_file_path):
    client = Client()
    dataset = client.read_dataset(dataset_name=dataset_name)
    
    # Open and process the validation file
    with open(validation_file_path, 'r') as f:
        for line in f:
            # Process the data and add to the dataset using client API
            client.create_chat_example(
                messages=[
                    {"type": "system", "data": {"content": "You are a helpful assistant that is knowledgeable about SQL. Only output the SQL."}},
                    {"type": "human", "data": {"content": example}}
                ],
                generations={"type": "ai", "data": {"content": assistant_content}},
                dataset_id=dataset.id
            )

The above code snippet demonstrates the process of creating and adding data to a dataset in LangSmith.

Fine-Tuning and Assessment

Once the data is uploaded, the next step involves fine-tuning and assessing the models. Below is an example of fine-tuning a model and evaluating it using LangSmith:

import replicate

# Fine-tune a model
training = replicate.trainings.create(
  version="meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d",
  input={
    "train_data": "https://storage.googleapis.com/chatopensource-replicate-demo/selected_sql_create_context_v4.jsonl",
    "num_train_epochs": 3
  },
  destination="papermoose/test"
)

# Evaluate the model using LangSmith
async def evaluate_dataset(dataset_name=None, num_repetitions=1, model="gpt-4-0613", project_name=None):
    # Define the chat model to test
    model_to_test = Replicate(
    model=model,
    model_kwargs={"temperature": 0.75, "max_length": 500, "top_p": 1},
    )
    
    # Run evaluation on the dataset using LangSmith
    chain_results = await arun_on_dataset(
        client,
        dataset_name=dataset_name,
        llm_or_chain_factory=model_to_test,
        evaluation=eval_config,
        num_repetitions=num_repetitions,
        project_name=project_name
    )

The above code snippet showcases the process of fine-tuning a model and evaluating it using LangSmith.

Observations and Findings

After evaluating the models, observations and findings can be made based on the results. The data obtained from LangSmith can be visualized and analyzed to draw meaningful conclusions. Here’s an example of visualizing the results using ChatGPT advanced data analysis:

# Visualize the results using ChatGPT advanced data analysis
# Code for graphing out the results

The above code snippet demonstrates how to visualize the results obtained from LangSmith using advanced data analysis.

Conclusion

In this tutorial, we have demonstrated how to test fine-tuned open source models in LangSmith using code snippets and examples. We covered the process of uploading data to LangSmith, fine-tuning and assessing models, and visualizing the results. LangSmith provides a convenient platform for evaluating and comparing fine-tuned open source models and can be a valuable tool for developers and researchers working with language models.

By leveraging LangSmith, developers and researchers can streamline the evaluation and comparison of fine-tuned open source models, enabling them to make informed decisions when choosing the best tool for the job.

Source
Effective
Langchain
Test
Fine Tuned
Recommended from ReadMedium