AWS Machine Learning Blog 2024年07月18日
Amazon SageMaker unveils the Cohere Command R fine-tuning model
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

AWS 宣布在 Amazon SageMaker 上推出 Cohere Command R 微调模型,这将进一步增强 SageMaker 的机器学习功能,使企业能够利用大型语言模型 (LLM) 的强大功能,并为各种应用释放其全部潜力。Cohere Command R 是一种可扩展的、前沿的 LLM,旨在轻松处理企业级工作负载。Cohere Command R 针对对话交互和长上下文任务进行了优化,旨在平衡高性能和高精度的可扩展模型类别,使公司能够超越概念验证并投入生产。该模型在检索增强生成 (RAG) 和工具使用任务上具有高精度,延迟低,吞吐量高,上下文长度长达 128,000 个令牌,以及在 10 种主要语言中具有强大的功能。

🚀 **微调:为特定用例定制 LLM** 微调是一种有效技术,可以将像 Cohere Command R 这样的 LLM 适应特定领域和任务,从而在基础模型上实现显著的性能提升。对微调后的 Cohere Command R 模型的评估表明,在金融服务、技术、零售、医疗保健、法律和医疗保健等各个行业的各种企业用例中,性能提高了 20% 以上。由于其体积较小,与同类中更大的模型相比,微调后的 Cohere Command R 模型可以更有效地提供服务。 建议使用包含至少 100 个示例的数据集。 Cohere Command R 使用 RAG 方法,从外部知识库中检索相关上下文以改进输出。但是,微调可以使您进一步专门化模型。在以下几种情况下,微调像 Cohere Command R 这样的文本生成模型对于实现最终性能至关重要: * **特定领域的适应** - RAG 模型可能在金融、法律或医学等高度专业化的领域中无法达到最佳性能。微调使您可以将模型适应这些领域的细微差别,以提高准确性。 * **数据增强** - 微调允许您合并额外的数据源或技术,增强模型的知识库,以提高鲁棒性,尤其是在数据稀疏的情况下。 * **细粒度控制** - 尽管 RAG 提供了令人印象深刻的通用功能,但微调允许您对模型行为进行细粒度控制,将其精确地调整到您想要的任务,以实现最终的精度。

💡 **RAG 和微调 LLMs 的结合力量** RAG 和微调 LLMs 的结合力量使您能够以无与伦比的通用性和有效性应对各种挑战。随着 Cohere Command R 微调在 SageMaker 上的推出,企业现在可以根据其独特的要求定制和优化模型的性能。通过在特定领域的数据上进行微调,企业可以提高 Cohere Command R 的准确性、相关性和有效性,以满足其用例,例如自然语言处理、文本生成和问答。

🌎 **AWS 使企业能够利用 AI 的变革力量** 通过将 Cohere Command R 的可扩展性和鲁棒性与在 SageMaker 上微调其性能的能力相结合,AWS 使企业能够应对 AI 采用的复杂性,并利用其变革力量来推动各个行业和领域的创新和增长。 客户数据(包括提示、完成、自定义模型以及用于微调或持续预训练的数据)对客户的 AWS 帐户保持私密,绝不会与第三方模型提供商共享。

🤖 **解决方案概述** 在以下部分中,我们将逐步介绍如何在 SageMaker 上微调 Cohere Command R 模型。这包括准备数据、部署模型、准备微调、创建用于推理的端点以及执行推理。

🌟 **准备微调数据** 在开始微调作业之前,您需要上传一个包含训练数据和(可选)评估数据的数据集。 首先,确保您的数据采用 jsonl 格式。它应该具有以下结构: * **messages** - 这包含对话消息列表。一条消息包含以下部分: * **role** - 这指定了当前发言者。您可以从 System、User 或 Chatbot 中选择。 * **content** - 这包含消息的内容。 以下是一个训练聊天机器人回答问题的示例。为了便于阅读,该文档跨越多行。对于您的数据集,请确保每一行都包含一个完整的示例。 {   "messages": [     {       "role": "System",       "content": "You are a large language model trained by Cohere."     },     {       "role": "User",       "content": "Hi! What were Time magazines top 10 cover stories in the last 10 years?"     },     {       "role": "Chatbot",       "content": "Time magazines top 10 cover stories in the last 10 years were:\n\n1. Volodymyr Zelenskyy\n2. Elon Musk\n3. Martin Luther King Jr.\n4. How Earth Survived\n5. Her Lasting Impact\n6. Nothing to See Here\n7. Meltdown\n8. Deal With It\n9. The Top of America\n10. Bitter Pill"     },     {       "role": "User",       "content": "Who is Volodymyr Zelenskyy?"     },     {       "role": "Chatbot",       "content": "Volodymyr Zelenskyy is a Ukrainian politician who was elected President of Ukraine in 2019. He previously served as the Minister of Internal Affairs in the government of Prime Minister Volodymyr Groysman."     },     {       "role": "User",       "content": "Thank you!"     }   ] }

AWS announced the availability of the Cohere Command R fine-tuning model on Amazon SageMaker. This latest addition to the SageMaker suite of machine learning (ML) capabilities empowers enterprises to harness the power of large language models (LLMs) and unlock their full potential for a wide range of applications.

Cohere Command R is a scalable, frontier LLM designed to handle enterprise-grade workloads with ease. Cohere Command R is optimized for conversational interaction and long context tasks. It targets the scalable category of models that balance high performance with strong accuracy, enabling companies to move beyond proof of concept and into production. The model boasts high precision on Retrieval Augmented Generation (RAG) and tool use tasks, low latency and high throughput, a long 128,000-token context length, and strong capabilities across 10 key languages.

In this post, we explore the reasons for fine-tuning a model and the process of how to accomplish it with Cohere Command R.

Fine-tuning: Tailoring LLMs for specific use cases

Fine-tuning is an effective technique to adapt LLMs like Cohere Command R to specific domains and tasks, leading to significant performance improvements over the base model. Evaluations of fine-tuned Cohere Command R model have demonstrated improved performance by over 20% across various enterprise use cases in industries such as financial services, technology, retail, healthcare, legal, and healthcare. Because of its smaller size, a fine-tuned Cohere Command R model can be served more efficiently compared to models much larger than its class.

The recommendation is to use a dataset that contains at least 100 examples.

Cohere Command R uses a RAG approach, retrieving relevant context from an external knowledge base to improve outputs. However, fine-tuning allows you to specialize the model even further. Fine-tuning text generation models like Cohere Command R is crucial for achieving ultimate performance in several scenarios:

The combined power of RAG and fine-tuned LLMs empowers you to tackle diverse challenges with unparalleled versatility and effectiveness. With the introduction of Cohere Command R fine-tuning on SageMaker, enterprises can now customize and optimize the model’s performance for their unique requirements. By fine-tuning on domain-specific data, businesses can enhance Cohere Command R’s accuracy, relevance, and effectiveness for their use cases, such as natural language processing, text generation, and question answering.

By combining the scalability and robustness of Cohere Command R with the ability to fine-tune its performance on SageMaker, AWS empowers enterprises to navigate the complexities of AI adoption and use its transformative power to drive innovation and growth across various industries and domains.

Customer data, including prompts, completions, custom models, and data used for fine-tuning or continued pre-training, remains private to customer AWS accounts and is never shared with third-party model providers.

Solution overview

In the following sections, we walk through the steps to fine-tune the Cohere Command R model on SageMaker. This includes preparing the data, deploying a model, preparing for fine-tuning, creating an endpoint for inference, and performing inference.

Prepare the fine-tuning data

Before you can start a fine-tuning job, you need to upload a dataset with training and (optionally) evaluation data.

First, make sure your data is in jsonl format. It should have the following structure:

The following is an example that trains a chatbot to answer questions. For the sake of readability, the document spans over multiple lines. For your dataset, make sure that each line contains one whole example.

{  "messages": [    {      "role": "System",      "content": "You are a large language model trained by Cohere."    },    {      "role": "User",      "content": "Hi! What were Time magazines top 10 cover stories in the last 10 years?"    },    {      "role": "Chatbot",      "content": "Time magazines top 10 cover stories in the last 10 years were:\\n\\n1. Volodymyr Zelenskyy\\n2. Elon Musk\\n3. Martin Luther King Jr.\\n4. How Earth Survived\\n5. Her Lasting Impact\\n6. Nothing to See Here\\n7. Meltdown\\n8. Deal With It\\n9. The Top of America\\n10. Bitter Pill"    },    {      "role": "User",      "content": "Who is Volodymyr Zelenskyy?"    },    {      "role": "Chatbot",      "content": "Volodymyr Zelenskyy is a Ukrainian politician who was elected President of Ukraine in 2019. He previously served as the Minister of Internal Affairs in the government of Prime Minister Volodymyr Groysman."    },    {      "role": "User",      "content": "Thank you!"    }  ]}

Deploy a model

Complete the following steps to deploy the model:

    On AWS Marketplace, subscribe to the Cohere Command R model

After you subscribe to the model, you can configure it and create a training job.

    Choose View in Amazon SageMaker. Follow the instructions in the UI to create a training job.

Alternatively, you can use the following example notebook to create the training job.

Prepare for fine-tuning

To fine-tune the model, you need the following:

Create an endpoint for inference

When the fine-tuning is complete, you can create an endpoint for inference with the fine-tuned model. To create the endpoint, use the create_endpoint method. If the endpoint already exists, you can connect to it using the connect_to_endpoint method.

Perform inference

You can now perform real-time inference using the endpoint. The following is the sample message that you use for input:

message = "Classify the following text as either very negative, negative, neutral, positive or very positive: mr. deeds is , as comedy goes , very silly -- and in the best way."result = co.chat(message=message)print(result)

The following screenshot shows the output of the fine-tuned model.


Optionally, you can also test the accuracy of the model using the evaluation data (sample_finetune_scienceQA_eval.jsonl).

Clean up

After you have completed running the notebook and experimenting with the Cohere Command R fine-tuned model, it is crucial to clean up the resources you have provisioned. Failing to do so may result in unnecessary charges accruing on your account. To prevent this, use the following code to delete the resources and stop the billing process:

co.delete_endpoint()co.close()

Summary

Cohere Command R with fine-tuning allows you to customize your models to be performant for your business, domain, and industry. Alongside the fine-tuned model, users additionally benefit from Cohere Command R’s proficiency in the most commonly used business languages (10 languages) and RAG with citations for accurate and verified information. Cohere Command R with fine-tuning achieves high levels of performance with less resource usage on targeted use cases. Enterprises can see lower operational costs, improved latency, and increased throughput without extensive computational demands.

Start building with Cohere’s fine-tuning model in SageMaker today.


About the Authors

Shashi Raina is a Senior Partner Solutions Architect at Amazon Web Services (AWS), where he specializes in supporting generative AI (GenAI) startups. With close to 6 years of experience at AWS, Shashi has developed deep expertise across a range of domains, including DevOps, analytics, and generative AI.

James Yi is a Senior AI/ML Partner Solutions Architect in the Emerging Technologies team at Amazon Web Services. He is passionate about working with enterprise customers and partners to design, deploy and scale AI/ML applications to derive their business values. Outside of work, he enjoys playing soccer, traveling and spending time with his family.

Pradeep Prabhakaran is a Customer Solutions Architect at Cohere. In his current role at Cohere, Pradeep acts as a trusted technical advisor to customers and partners, providing guidance and strategies to help them realize the full potential of Cohere’s cutting-edge Generative AI platform. Prior to joining Cohere, Pradeep was a Principal Customer Solutions Manager at Amazon Web Services, where he led Enterprise Cloud transformation programs for large enterprises. Prior to AWS, Pradeep has held various leadership positions at consulting companies such as Slalom, Deloitte, and Wipro. Pradeep holds a Bachelor’s degree in Engineering and is based in Dallas, TX.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Cohere Command R Amazon SageMaker 大型语言模型 LLM 微调 RAG 自然语言处理
相关文章