在 Amazon Bedrock 上使用 Meta Llama 3 模型

e99f536f67ee0e6ac1801fa79981abef.gif

48b2e35cf8a192b6ac08d25a06abdf2e.png

Meta 的 Llama 3 模型已在 Amazon Bedrock 中正式可用。Meta Llama 3 旨在让您能够构建、试验和负责任地扩展您的生成式 AI 应用程序。新的 Llama 3 模型能够支持各种广泛用例,在推理、代码生成和指令方面均有改进。

根据 Meta 关于 Llama 3 的公告,Llama 3 模型家族是一组预训练和指令调优的大型语言模型(LLMs),参数量为 8B 和 70B。这些模型都接受了超过 15 万亿个标记数据的训练,相比 Llama 2 模型使用的训练数据集大七倍,其中包含四倍于 Llama 2 的代码数据,支持 8K 的上下文长度,是 Llama 2 的两倍。

现在您可以在 Amazon Bedrock 中使用两种新的 Llama 3 模型,进一步增加了 Amazon Bedrock 中的模型选择。这些模型使您能够轻松尝试和评估更多顶级基础模型(FMs),以满足您的使用案例:

  • Llama 3 8B 非常适合有限的计算能力和资源以及边缘设备。该模型擅长文本摘要、文本分类、情感分析和语言翻译。

  • Llama 3 70B 非常适合内容创作、对话式 AI、语言理解、研发和企业应用。该模型擅长文本摘要和准确性、文本分类和细微差别、情感分析和细微推理、语言建模、对话系统、代码生成和遵循指令。

此外,Meta 目前正在训练参数超过 400B 的其他 Llama 3 模型。这些 400B 模型将具有新的能力,包括多模态、多语言支持和更长的上下文窗口。一旦发布,这些模型将非常适合内容创作、对话式 AI、语言理解、研发和企业应用。

Llama 3 模型实践

如果您是第一次使用 Meta 模型,请访问 Amazon Bedrock 控制台,并在左下方窗格中选择模型访问

https://console.aws.amazon.com/bedrock/

要访问 Meta 最新的 Llama 3 模型,请分别请求访问 Llama 3 8B Instruct Llama 3 70B Instruct

366e0b309a2ebbedf3049520a74d7fa4.jpeg

要在 Amazon Bedrock 控制台中测试 Meta Llama 3 模型,请在左侧菜单窗格中选择游乐场下的文本聊天。然后选择选择模型,并将类别设置为 Meta,将模型设置为 Llama 8B Instruct Llama 3 70B Instruct

615f39900f2bd603814b9008f5f20ddd.jpeg

通过选择查看 API 请求,您还可以使用亚马逊云科技命令行界面(Amazon CLI)和 Amazon SDK 中的代码示例来访问该模型。您可以使用诸如 meta.llama3-8b-instruct-v1 或 meta.llama3-70b-instruct-v1 这样的模型 ID。

这是一个 Amazon CLI 命令样本:

 Bash 

$ aws bedrock-runtime invoke-model \
  --model-id meta.llama3-8b-instruct-v1:0 \
  --body "{\"prompt\":\"Simply put, the theory of relativity states that\\n the laws of physics are the same everywhere in the universe, and that the passage of time and the length of objects can vary depending on their speed and position in a gravitational field \",\"max_gen_len\":512,\"temperature\":0.5,\"top_p\":0.9}" \
  --cli-binary-format raw-in-base64-out \
  --region us-east-1 \
  invoke-model-output.txt

您可以使用 Amazon Bedrock 的代码示例:

https://docs.aws.amazon.com/bedrock/latest/userguide/service_code_examples.html

利用 Amazon SDK 用各种编程语言构建您的应用程序。下面的 Python 代码示例展示了如何在 Amazon Bedrock 中调用 Llama 3 Chat 模型进行文本生成。

 Python 

def invoke_llama3(self, prompt):
        try:
            body = {
                "prompt": prompt,
                "temperature": 0.5,
                "top_p": 0.9,
                "max_gen_len": 512,
            }


            response = self.bedrock_runtime_client.invoke_model(
                modelId="meta.llama3-8b-instruct-v1:0", body=json.dumps(body)
            )


            response_body = json.loads(response["body"].read())
            completion = response_body["generation"]


            return completion


        except ClientError:
            logger.error("Couldn't invoke Llama 3")
            raise

您可以将这些 Llama 3 模型用于各种任务,例如问答、语言翻译、情感分析等。以下是 Llama 3 模型进行小批量上下文学习的示例,我们向模型提供了可用的训练样本。

 Markup 

Input: Translate English to French:
sea otter => loutre de mer
peppermint => menthe poivrée
plush girafe => girafe peluche
cheese =>
Output:  fromage
panda => panda
penguin => pingouin
polar bear => ours polaire
puffin => macareux
sloth => paresseux
walrus => morse
whale => baleine
zebra => z\u00e8bre


Translate English to German:
sea otter => Seeotter

您还可以使用针对对话用例优化的 Llama 3 指令模型。指令模型端点的输入是助手和用户之前的对话历史。因此,您可以提问与已发生的对话相关的上下文性问题,并提供定义聊天助手行为的系统配置,如个性化等,格式如下:

 Markup 

<|begin_of_text|><|start_header_id|>system<|end_header_id|>
[SYSTEM_TEXT]<|eot_id|><|start_header_id|>user<|end_header_id|>
[USER_TEXT]<|eot_id|><|start_header_id|>assistant<|end_header_id|>

在以下示例中,用户与助手以巴黎的旅游景点为话题进行了对话。然后,用户询问了助手推荐的第一个选项。

ac884ea95e7e431a8215f3f9078f0e1d.jpeg

 Markup 

Input: <|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n
I am going to Paris, what should I see?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n
1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\n
These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n
What is so great about #1?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
Output: The Eiffel Tower! It's an iconic symbol of Paris and one of the most recognizable landmarks in the world. Here are some reasons why it's so great:\n\n
1. **Engineering marvel**: When it was built for the 1889 World's Fair, the Eiffel Tower was a groundbreaking feat of engineering. It was the tallest structure in the world at the time, standing at 324 meters (1,063 feet).\n
2. **Panoramic views**: The Eiffel Tower offers breathtaking 360-degree views of the city from its observation decks. You can see many of Paris' famous landmarks, such as the Seine River, the Louvre, and Montmartre.\n
3. **Romantic atmosphere**: The Eiffel Tower is often associated with romance and is a popular spot for proposals, weddings, and romantic dinners. The tower's iron latticework and twinkling lights at night add to its romantic ambiance.\n
4. **Historical significance**: The Eiffel Tower has played a significant role in French history, serving as a communication tower during World War I and a symbol of French culture and engineering.\n
5. **Accessibility**: The Eiffel Tower is easily accessible by public transportation or on foot, and there are various ways to experience it, including taking the stairs, elevator, or a guided tour.\n
6. **Nighttime spectacle**: The Eiffel Tower is even more magical at night, when it's illuminated with thousands of twinkling lights. The light show, known as the \"Eiffel Tower Sparkle,\" takes place every hour on the hour from dusk to midnight.\n
7. **Iconic status**: The Eiffel Tower has been featured in countless films, literature, and art, making it an instantly recognizable symbol of Paris and France.\n\n
Overall, the Eiffel Tower is a must-visit attraction in Paris, offering a unique combination of history, engineering, romance, and stunning views.

了解有关 Llama 3 新的提示模板和特殊标记的更多信息,请查看 Meta 的模型卡和提示格式:

https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3

或 GitHub 存储库中的 Llama Recipes(配套资源):

https://github.com/meta-llama/llama-recipes

现已推出

Meta 的 Llama 3 模型已在美国东部(弗吉尼亚北部)和美国西部(俄勒冈州)地区的 Amazon Bedrock 上推出。请查看完整地区列表以获取未来更新:

https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3

欲了解更多信息,请查看 Amazon Bedrock 中的 Llama 产品页面和定价页面:

https://github.com/meta-llama/llama-recipes

现在就在 Amazon Bedrock 控制台上试用 Llama 3,并通过亚马逊云科技 re:Post for Amazon Bedrock 或您的常用亚马逊云科技支持渠道反馈意见:

https://repost.aws/tags/TAQeKlaPaNRQ2tWB6P7KrMag/amazon-bedrock

您还可以访问亚马逊云科技的社区,找到深入的技术内容,了解我们的开发者如何在他们的解决方案中使用 Amazon Bedrock:

https://community.aws/generative-ai?trk=e8665609-785f-4bbe-86e8-750a3d3e9e61&sc_channel=el

点击阅读原文查看博客,获得更详细内容!

本篇作者

0e6bc4323be839367123386976e684bf.jpeg

Channy Yun

亚马逊云科技首席开发者布道师,热衷于帮助开发人员在亚马逊云科技服务上构建现代化应用。作为一位务实的开发者和博客作者,他热爱社区驱动的学习和技术分享,这使开发者汇聚到亚马逊云科技的社区(User Group)。他主要关注的专题包括开源、容器、存储、网络和安全以及物联网。

12af92c799a5af0a9da20af6d9f693b8.gif

星标不迷路,开发更极速!

关注后记得星标「亚马逊云开发者」

a11a29c0e8616ae5c95a07a014e4cd9c.gif

听说,点完下面4个按钮

就不会碰到bug了!

5451f614c3eda8136e57910f13a5128f.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值