[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-10-23 (世界標準時間)。"],[],[],null,["# Model Alignment\n\n\u003cbr /\u003e\n\nCreating a prompt for an artificial intelligence (AI) model, such as Gemini or\nGemma, that perfectly captures a your intent can be a non-trivial task. Often,\nyou must write a prompt by hand and then test it in a variety of use cases to\nensure it fits your needs. Based on the results, you might make targeted updates\nto the prompt: changing some words in one place, adding a new sentence in\nanother. This process is not very principled and may not lead to the best\nresults.\n\nGoogle has [developed a method](https://arxiv.org/abs/2310.15428) that uses LLMs to\nautomatically update a [prompt template](/responsible/docs/alignment#prompt-templates) based on\nfeedback you provide about the model's output in plain language. Your feedback,\nalong with the prompt and the model's output, are sent to an LLM that updates\nthe prompt to better align with your intended behavior.\n\nThis method available in two ways:\n\n- The open source [`model-alignment` Python library](https://pypi.org/project/model-alignment/) lets you flexibly incorporate this approach into your software and workflows.\n- A [version of this approach](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/ai-powered-prompt-writing#refine_prompts) is integrated into Vertex AI Studio, letting you use this workflow with just a few clicks.\n\nOpen-Source Library\n-------------------\n\nModel Alignment is an [open-source Python library](https://github.com/pair-code/model-alignment), released as a\n[package on PyPI](https://pypi.org/project/model-alignment/) that enables alignment of prompts from human\nfeedback through an API. The library is based on our research into\n[prompt updating through human feedback](https://arxiv.org/abs/2310.15428) and\n[automatic classifier creation from labeled-data](https://arxiv.org/abs/2403.04894).\n\n**Curate prompt templates for Gemma using the Model Alignment library**\n\n|---|----------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Start Google Colab](https://colab.research.google.com/github/pair-code/model-alignment/blob/main/notebooks/Gemma_for_Model_Alignment.ipynb) |\n\n\u003cbr /\u003e\n\nThis library supports two workflows for automatically updating prompt templates:\n\n1. **Iterative updates from principles** . This workflow uses an LLM to distill [guidelines](https://arxiv.org/abs/2212.08073) either from indirect critiques of the model's output, or from direct edits of the model output. You can iteratively create one or more guidelines before sending them to the LLM, which updates the prompt template to adhere to those guidelines. You can also hand-curate guidelines and include them alongside LLM-distilled ones.\n2. **Direct critique of model outputs**. This workflow takes your feedback about the entire model output and feeds it, along with the prompt and model output, directly to the LLM to generate an updated prompt template.\n\nThese two workflows may both be useful for you application. The notable\ntrade-off is the presence of guidelines, which can be a useful, concrete process\nartifact that can help inform, for example, your approach to\n[transparency](/responsible/docs/design#transparency-artifacts).\n\n**Figure 1.** This flowchart illustrates where and how the two Model Alignment\nlibrary workflows diverge to enable guideline-driven or direct updates to your\nprompt templates. Note that the process is iterative, and these workflows are\nnot mutually exclusive, you can switch between them at any time.\n\nCheck out the [Colab notebook](https://colab.research.google.com/github/pair-code/model-alignment/blob/main/notebooks/Gemma_for_Model_Alignment.ipynb) that uses [Gemini](https://ai.google.dev/gemini-api) to\nalign prompts for [Gemma 2](https://ai.google.dev/gemma) using both workflows.\n\nAlignment in Vertex AI Studio\n-----------------------------\n\nGoogle's [Vertex AI Studio](https://console.cloud.google.com/vertex-ai/studio/freeform) has added a\n[\"refine prompt\"](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/ai-powered-prompt-writing#refine_prompts) feature based on the *direct* workflow\nfrom the Model Alignment open source library to compliment its authoring,\nrunning, evaluation, and comparison tools.\n\nAfter running a prompt, you can provide feedback on ways in which the model\nshould behave differently, and Vertex AI Studio uses [Gemini](https://ai.google.dev/gemini-api) to draft\na rewrite. You can accept the proposed changes and re-run the updated prompt\nwith a click of a button, or update your feedback and have Gemini draft another\ncandidate.\n\n**Figure 2.** The \"refine prompt\" feature of Vertex AI Studio being used to\nupdate a prompt based on user feedback.\n\nLinks\n-----\n\nExplore model alignment for yourself:\n\n- Run this [Colab notebook](https://colab.research.google.com/github/pair-code/model-alignment/blob/main/notebooks/Gemma_for_Model_Alignment.ipynb) that uses Gemini to align various prompts for our open-weights Gemma 2 model using both alignment approaches.\n- Try the \"refine prompt\" model alignment feature in [Vertex AI Studio](https://console.cloud.google.com/vertex-ai/studio/freeform)."]]