From 3be2026be458a4cfd0ab15f7c9ad0e7208dc06a6 Mon Sep 17 00:00:00 2001
From: CatRob satoshi Git <137897299+Catro-b@users.noreply.github.com>
Date: Mon, 13 Oct 2025 02:19:08 +0700
Subject: [PATCH 1/3] Create README.md
Signed-off-by: CatRob satoshi Git <137897299+Catro-b@users.noreply.github.com>
---
profile/README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 profile/README.md
diff --git a/profile/README.md b/profile/README.md
new file mode 100644
index 0000000..df35e6c
--- /dev/null
+++ b/profile/README.md
@@ -0,0 +1,64 @@
+
+
+## 🧩 CATROB SATOSHI 🧩
+Developer, Expert in system development storage system, specializing in system development, protection and analysis.
+
+
+As a storage systems development specialist, I specialize in designing, developing, protecting, and analyzing storage systems to ensure optimal performance, security, and reliability.
+My expertise covers the following areas:
+Storage Systems Development:
+Designing and developing scalable and flexible storage architectures
+Selecting appropriate storage technologies such as SAN, NAS, object storage, and cloud storage
+Developing data management solutions and software-defined storage (SDS)
+Tunement and optimization of storage systems to support high-volume workloads (High-Performance Storage)
+Storage System Protection:
+Data Security: Data Encryption both at rest and in transit, Access Control, Key Management
+Backup & Recovery: Designing an effective backup strategy, selecting the right backup solution, Disaster Recovery Planning (DRP), and Business Continuity Planning (BCP)
+Fault Tolerance: Using RAID, Replication, and High Availability (HA) technologies to ensure data is always available
+Storage System Analysis:
+Performance Monitoring: Analyzing performance metrics (I/OPS, Latency, Throughput) to identify bottlenecks and optimize performance
+Security Analysis: Vulnerability Assessment, Penetration Testing of the storage system and associated protocols
+Capacity Analysis: Capacity Planning and Efficient Storage Management
+Log Analysis: Analyzing activity logs to detect anomalies and security events.
+I focus on building robust, secure, and efficient solutions to meet business needs and protect valuable data assets.
+If you have any questions or need assistance with any of the above, please let me know.
+
+
+
+
+
+
+
+
+
+
+
+## 🧩 Devloper Redevbionet 🧩
+
+
+
+## ใบรับรอง
+
+
+
+
+
+
+### รายงาน SOC 2 ของเราถือว่ามีการใช้ฟีเจอร์ความปลอดภัยบางอย่างที่มีให้เฉพาะลูกค้าองค์กร เช่น SAML SSO ในฐานะลูกค้าที่ไม่ใช่องค์กร บัญชีของคุณไม่สามารถใช้ฟีเจอร์ความปลอดภัยเหล่านี้ได้ และรายงาน SOC 2 จะไม่มีผลใช้บังคับ ดังนั้นเราจึงไม่สามารถแบ่งปันรายงานนี้ในกรณีที่ไม่เกี่ยวข้องได้
+
+
+
+### เราจัดทำรายงาน SOC 3 ให้กับลูกค้าที่ไม่ใช่องค์กรเพื่อยืนยัน:
+
+ที่มีการควบคุมดำเนินการตลอดช่วงเวลาดังกล่าว (เช่นในรายงาน SOC 1 และ 2 ของเรา ความเห็นของผู้ตรวจสอบจะรวมอยู่ในรายงาน SOC 3 ของเรา)
+ขอบเขตการให้บริการของ GitHub;
+CUEC (การควบคุมเอนทิตีผู้ใช้เสริม) ของเรา ซึ่งลูกค้าเป้าหมายต้องการดู เพื่อที่พวกเขาจะได้รู้ว่าจำเป็นต้องมี/ใช้การควบคุมใดบ้างเพื่อให้สามารถพึ่งพารายงาน SOC ของ GitHub ได้
+
+
+
+
+
+
+### ใบรับรอง ISO/IEC 27001 ยืนยันระบบการจัดการความปลอดภัยข้อมูล (ISMS) ที่รองรับการทำงานที่อยู่ภายใต้ GitHub.com
+
+
From 7b9032b8ccd40932be24abd6608952c652cee2b4 Mon Sep 17 00:00:00 2001
From: CatRob satoshi Git <137897299+Catro-b@users.noreply.github.com>
Date: Tue, 25 Nov 2025 08:57:59 -0800
Subject: [PATCH 2/3] Created using Colab
---
notebooks/Gemma_for_Model_Alignment.ipynb | 889 ++++++++++++++++++++++
1 file changed, 889 insertions(+)
create mode 100644 notebooks/Gemma_for_Model_Alignment.ipynb
diff --git a/notebooks/Gemma_for_Model_Alignment.ipynb b/notebooks/Gemma_for_Model_Alignment.ipynb
new file mode 100644
index 0000000..0dc3c95
--- /dev/null
+++ b/notebooks/Gemma_for_Model_Alignment.ipynb
@@ -0,0 +1,889 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "view-in-github",
+ "colab_type": "text"
+ },
+ "source": [
+ "
"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "4TinoiDCCibN"
+ },
+ "source": [
+ "##### Copyright 2024-2025 Google LLC."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "id": "lxzsE00VCqH6"
+ },
+ "outputs": [],
+ "source": [
+ "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
+ "# you may not use this file except in compliance with the License.\n",
+ "# You may obtain a copy of the License at\n",
+ "#\n",
+ "# https://www.apache.org/licenses/LICENSE-2.0\n",
+ "#\n",
+ "# Unless required by applicable law or agreed to in writing, software\n",
+ "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
+ "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
+ "# See the License for the specific language governing permissions and\n",
+ "# limitations under the License."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "WD8i4bJBJQ_5"
+ },
+ "source": [
+ "# Model Alignment of Gemma"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "VM2hRK9yua-_"
+ },
+ "source": [
+ "Model alignment is the process of automatically updating a prompt based on developer-provided feedback.\n",
+ "\n",
+ "This notebook shows how the [Model Alignment Python API](https://github.com/PAIR-code/model-alignment) can be used with Gemma and Gemini models to modify non-agentic prompts (e.g. ideation, extraction, summarization, etc. that don't make use of tools or external knowledge databases) based on feedback through two different approaches described below.\n",
+ "\n",
+ "Running this notebook requires a [GPU-backed Colab runtime][colab_accelerators], such as a T4, L4, or A100, which may require a paid [subscription][colab_subscriptions].\n",
+ "\n",
+ "With model alignment, there are two roles that models take as part of the process, although these can be the same model in practice:\n",
+ "\n",
+ "1. **Target model**: The model that the target prompt will be run with. The alignment process is meant to make the prompt work well with the target model, as determined by you.\n",
+ " \n",
+ " - This notebook uses the Gemma2 2B Instruction-Tuned model, loaded by Keras from weights hosted on Kaggle as the target model. Loading Gemma for this Colab requires:\n",
+ "\n",
+ " 1. [Authenticating][kagglehub_auth] with a Kaggle account that has accepted the Gemma license agreement; and\n",
+ " 1. A [GPU-backed runtime][colab_accelerators], such as a T4, L4, or A100, which may require a paid [subscription][colab_subscriptions].\n",
+ "\n",
+ "[colab_accelerators]: https://research.google.com/colaboratory/faq.html#gpu-availability\n",
+ "[colab_subscriptions]: https://colab.research.google.com/signup\n",
+ "[kagglehub_auth]: https://github.com/Kaggle/kagglehub#authenticate\n",
+ "[kaggle_gemma]: https://www.kaggle.com/models/keras/gemma\n",
+ " \n",
+ "2. **Alignment model**: The model that will be used to perform the alignment steps. This model is used in the steps that perform alignment steps such as creating principles and updating the target prompt.\n",
+ "\n",
+ " - This notebook uses the Gemini Pro 2.5 model run through Google's Developer API as the alignment model. This requires you to provide an [API key](https://aistudio.google.com/app/apikey). The Gemini model is larger in size than the Gemma model, which makes it better at the alignment tasks shown in this notebook. A Gemma model larger than 2B would also suffice for the alignment of the prompts.\n",
+ "\n",
+ "Alignment can be performed through two different methods, both of which are shown in this notebook:\n",
+ "\n",
+ "1. Prompts are modified through guidlines (also called principles) which are curated by critiquing or rewriting of model responses.\n",
+ "2. Prompts are modified through direct feedback of a model response, without the intermediate step of creating principles.\n",
+ "\n",
+ "The principles method has an added benefit of maintaining a list of principles by which the prompt should adhere, which can be helpful as both a resource to share and collaborate on, and as a checklist of properties that a model response can be judged agains. This does require extra alignment model processing and human involvement versus the direct feedback approach. Which approach to take is entirely up to you.\n",
+ "\n",
+ "Below is a flow chart depicting the sequence of steps for both approaches.\n",
+ "\n",
+ "In addition to creating principles through critiquing, principles can also be created by providing a manually-written ideal response, or by giving kudos to a well-crafted model response. For more details, see the [documentation](https://github.com/PAIR-code/model-alignment?tab=readme-ov-file#generating-principles-from-feedback-and-applying-them) and [research paper](https://arxiv.org/abs/2310.15428)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "PJ868K01vBdr"
+ },
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "LICiOBtbKpQF"
+ },
+ "source": [
+ "## Notebook Setup"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "ibx08GxHKpSh"
+ },
+ "source": [
+ "\n",
+ "This notebook requires setting of three \"secrets\" that contain user-specific credentials for use of both models. These can be set in the \"Secrets\" configuration panel in this Colab notebok.\n",
+ "1. KAGGLE_USERNAME: Your username for kaggle.com\n",
+ "2. KAGGLE_KEY: A token created in your kaggle account for access to kaggle resources\n",
+ "3. GOOGLE_API_KEY: An API Key for using the Google Developer API for Gemini"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "fkXKwPKzK09D"
+ },
+ "source": [
+ "## Setup Keras for GPU usage and JAX backend.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "K878_LtIqqUw"
+ },
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "from google.colab import userdata\n",
+ "\n",
+ "# Setup Keras to use jax backend and configure for successful colab GPU usage.\n",
+ "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\".\n",
+ "os.environ[\"XLA_PYTHON_CLIENT_MEM_FRACTION\"] = \"0.9\"\n",
+ "\n",
+ "# Note: `userdata.get` is a Colab API. If you're not using Colab, set the env\n",
+ "# vars as appropriate for your system.\n",
+ "os.environ[\"KAGGLE_USERNAME\"] = userdata.get(\"KAGGLE_USERNAME\")\n",
+ "os.environ[\"KAGGLE_KEY\"] = userdata.get(\"KAGGLE_KEY\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "hSqGJSHQK3xT"
+ },
+ "source": [
+ "## Installation and imports"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "XSrED-JTUBls"
+ },
+ "outputs": [],
+ "source": [
+ "# Install Keras libraries which are used by the Gemma model.\n",
+ "!pip install -q -U keras-nlp\n",
+ "!pip install -q -U keras>=3\n",
+ "\n",
+ "# Install the Model Alignment library\n",
+ "!pip install model-alignment\n",
+ "from model_alignment import model_helper\n",
+ "from model_alignment import single_run"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "9cQRNhwzK-oN"
+ },
+ "source": [
+ "## Create the Gemma and Gemini model helper classses for use by Model Alignment.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "z95uHR9xmjQk"
+ },
+ "outputs": [],
+ "source": [
+ "gemma_model = model_helper.GemmaModelHelper('gemma2_instruct_2b_en')\n",
+ "\n",
+ "gemini_api_key = userdata.get('GOOGLE_API_KEY')\n",
+ "gemini_model = model_helper.GeminiModelHelper(gemini_api_key, 'gemini-2.5-pro')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "x4lqBcb3JYZ8"
+ },
+ "source": [
+ "# Simple Alignment Through Principles"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "g44A3kbPwtcR"
+ },
+ "source": [
+ "This example shows aligning a simple prompt through the process of creating principles for the prompt to follow, created by providing feedback to responses generated by the model.\n",
+ "\n",
+ "You first define a simple prompt to align.\n",
+ "\n",
+ "You then run the prompt through the target Gemma model and see the output.\n",
+ "\n",
+ "You can then provide a critique of the response in order to have the model alignment system create a generic principle that you want the model to adhere to. In this example, you ask the model alignment library to provide some possible critiques given this prompt and model response to help us brainstorm.\n",
+ "\n",
+ "Once you provide the critique, a principle is created and printed out. You can repeat this process as many times as you want to update the full principles list for this model alignment task.\n",
+ "\n",
+ "Once you are happy with the list of principles, you have the model alignment library update the prompt to better adhere to all of the principles you have created.\n",
+ "\n",
+ "You then run the updated prompt on the target model and see the improved results."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "cellView": "form",
+ "id": "YBAMYh1GO4op"
+ },
+ "outputs": [],
+ "source": [
+ "# @title Prompt to align\n",
+ "prompt = 'Give me a list of groceries to buy for making shrimp scampi' # @param {type:\"string\"}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "T9oyG23BowAY"
+ },
+ "outputs": [],
+ "source": [
+ "# Create the model alignment instance, using Gemma to run the prompt and Gemini to do the alignment work.\n",
+ "single_run_prompt = single_run.AlignableSingleRun(gemma_model, gemini_model)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "w6F9pNFSajU8",
+ "outputId": "63029acc-54be-470d-9ea5-01033acb2502"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Here's a list of groceries you'll need for making delicious shrimp scampi:\n",
+ "\n",
+ "**Seafood:**\n",
+ "\n",
+ "* **Shrimp:** 1 pound large shrimp, peeled and deveined (you can use frozen if you prefer)\n",
+ "\n",
+ "**Produce:**\n",
+ "\n",
+ "* **Garlic:** 4-6 cloves\n",
+ "* **Shallots:** 1-2 shallots, finely chopped (optional, but adds a nice depth of flavor)\n",
+ "* **Lemon:** 1 lemon, juiced and zested\n",
+ "* **Parsley:** 1/4 cup chopped fresh parsley\n",
+ "* **Red pepper flakes:** 1/4 teaspoon (or to taste)\n",
+ "\n",
+ "**Pantry:**\n",
+ "\n",
+ "* **Olive oil:** 2-3 tablespoons\n",
+ "* **Dry white wine:** 1/2 cup (like Pinot Grigio or Sauvignon Blanc)\n",
+ "* **Butter:** 2 tablespoons\n",
+ "* **Parmesan cheese:** 1/2 cup grated (plus extra for serving)\n",
+ "* **Salt and black pepper:** to taste\n",
+ "* **Red pepper flakes:** 1/4 teaspoon (or to taste)\n",
+ "\n",
+ "**Optional:**\n",
+ "\n",
+ "* **Angel hair pasta:** 8 ounces (or your preferred pasta shape)\n",
+ "* **Bread:** for serving (optional)\n",
+ "\n",
+ "\n",
+ "Enjoy your shrimp scampi!\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Run the initial prompt with Gemma\n",
+ "single_run_prompt.set_model_description(prompt)\n",
+ "output = single_run_prompt.send_input()\n",
+ "print(output.text)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 54
+ },
+ "id": "zX41xdP9ajXZ",
+ "outputId": "486eb7b8-a167-4ed8-8daf-6ca6e1e5a3e0"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['**Red pepper flakes** is listed twice: once under **Produce** and again under **Pantry**.', 'The quantity of shrimp is for a small portion, probably enough for 2 people. It should be specified in the instructions how many people the recipe is for.', \"The instructions are not specific enough. For example, it doesn't specify what type of olive oil (extra virgin or not) or what kind of bread would pair well with the dish.\", ' \\n']\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Generate some possible critiques of this model output using the larger model.\n",
+ "critiques = single_run_prompt.generate_critiques()\n",
+ "print(critiques)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "id": "JZFcEeTWajZ6",
+ "outputId": "85e2233d-c0fa-4afe-fc27-71173a849927"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['Specify any dietary restrictions.']\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Make a specific critique of the prompt and response, creating a principle with the larger model.\n",
+ "# Then print the current principles list.\n",
+ "principles = single_run_prompt.critique_response(\n",
+ " 'I do not want to use any alcohol in my recipe'\n",
+ ")\n",
+ "print(principles)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 52
+ },
+ "id": "8R8BvVnmbzl9",
+ "outputId": "80900e32-df75-4bad-d673-456f847b5222"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Give me a list of groceries to buy for making shrimp scampi. Please specify any dietary restrictions. \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Update the prompt based on the principles using the larger model and print it out.\n",
+ "single_run_prompt.update_model_description_from_principles()\n",
+ "print(single_run_prompt.get_model_description())"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "wZgl9sIebzoQ",
+ "outputId": "30dabf93-4b75-431a-ad6d-4ed254a145cb"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Here's a list of groceries for making shrimp scampi, keeping in mind dietary restrictions:\n",
+ "\n",
+ "**Main Ingredients:**\n",
+ "\n",
+ "* **Shrimp:** 1 pound large shrimp, peeled and deveined (can be substituted with other seafood like scallops or cod)\n",
+ "* **Garlic:** 4-6 cloves, minced\n",
+ "* **Shallots:** 1-2, minced (optional, can substitute with onion)\n",
+ "* **Butter:** 4 tablespoons (or olive oil for a lighter option)\n",
+ "* **White wine:** 1/2 cup dry white wine (optional, can substitute with chicken broth or lemon juice)\n",
+ "* **Lemon juice:** 1 tablespoon\n",
+ "* **Parsley:** 1/4 cup chopped fresh parsley (for garnish)\n",
+ "* **Red pepper flakes:** 1/4 teaspoon (optional, for heat)\n",
+ "\n",
+ "**Supporting Ingredients:**\n",
+ "\n",
+ "* **Salt and black pepper:** To taste\n",
+ "* **Pasta:** 1 pound linguine, fettuccine, or your preferred pasta shape (gluten-free options available)\n",
+ "* **Parmesan cheese:** 1/2 cup grated (optional, for serving)\n",
+ "\n",
+ "**Dietary Restrictions:**\n",
+ "\n",
+ "* **Gluten-free:** Choose gluten-free pasta.\n",
+ "* **Dairy-free:** Use dairy-free butter or olive oil. Substitute Parmesan with nutritional yeast or a dairy-free cheese alternative.\n",
+ "* **Low-carb:** Use a smaller amount of pasta, or substitute with cauliflower rice or zucchini noodles.\n",
+ "* **Vegetarian:** Omit the shrimp and use a plant-based protein like tofu or tempeh.\n",
+ "\n",
+ "\n",
+ "**Tips:**\n",
+ "\n",
+ "* **Don't overcook the shrimp:** They should be pink and opaque, not rubbery.\n",
+ "* **Taste and adjust seasoning:** Add more salt, pepper, or red pepper flakes to your liking.\n",
+ "* **Serve with crusty bread:** For dipping in the delicious sauce. \n",
+ "\n",
+ "\n",
+ "Enjoy your shrimp scampi!\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Get model output from Gemma now that the prompt is updated based on the new principle.\n",
+ "reply = single_run_prompt.send_input()\n",
+ "print(reply.text)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "94FS3AjrJoBL"
+ },
+ "source": [
+ "# Alignment for Prompts with Input Variables\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "7KRKTSsyw4Ct"
+ },
+ "source": [
+ "This example is similar to the previous example with one major difference. This example aligns a prompt that contains a **variable**. The use case for prompts with variables are when a prompt may have an end-user-specific value that needs to be plugged into it before it is sent to the model.\n",
+ "\n",
+ "First, define the prompt to align with an input variable, as shown in the example below.\n",
+ "\n",
+ "The word in the brackets is the variable. It represents a place where the end-user of a prompt would input their own value. In this way, this same prompt can be used to find out uses of multiple different items without writing totally separate prompts.\n",
+ "\n",
+ "These types of prompts with variables can be useful for prompts that are meant to be embedded into user-facing applications where the user can set the specific value for a variable through some UI element, for example.\n",
+ "\n",
+ "Notice that when you run the prompt through the target model, you provide a dictionary that sets the value of the \"item\" variable to the value \"scissors\".\n",
+ "\n",
+ "You align this prompt in the same way as the previous example and you can see that as the prompt is updated by the alignment procedure, it keeps the variable in the prompt so that it can be used for any value for the \"item\" variable."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "cellView": "form",
+ "id": "OiqOyIbFP-0Y"
+ },
+ "outputs": [],
+ "source": [
+ "# @title Prompt to align\n",
+ "prompt = 'Give three uses for the following item: {item}' # @param {type:\"string\"}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "cPfHfgTbdVCJ"
+ },
+ "outputs": [],
+ "source": [
+ "# Create the model alignment instance, using Gemma to run the prompt and Gemini to do the alignment work.\n",
+ "single_run_prompt = single_run.AlignableSingleRun(gemma_model, gemini_model)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "cellView": "form",
+ "id": "OI3Hv2A-QgBI"
+ },
+ "outputs": [],
+ "source": [
+ "# @title Set the value for the variable in the prompt\n",
+ "variable_value = 'scissors' # @param {type:\"string\"}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "4bQ0YYSP4edH",
+ "outputId": "c450f10c-d8bb-4f5e-c56e-7a5a972ce8f8"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Here are three uses for scissors:\n",
+ "\n",
+ "1. **Cutting paper:** This is the most common use for scissors, from crafting projects to schoolwork.\n",
+ "2. **Cutting fabric:** Scissors are great for trimming fabric for sewing projects, crafts, or even just cutting out shapes for decorations.\n",
+ "3. **Cutting hair:** While not ideal for professional use, scissors can be used to trim small amounts of hair at home, especially for trimming bangs or small sections. \n",
+ "\n",
+ "\n",
+ "Let me know if you'd like more uses!\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Run the initial prompt with Gemma with a specific value for the variable\n",
+ "single_run_prompt.set_model_description(prompt)\n",
+ "output = single_run_prompt.send_input({'item': variable_value})\n",
+ "print(output.text)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "id": "MCy71ajT4efv",
+ "outputId": "8b991162-29fe-4cd4-ac79-02b800f38824"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['Give creative uses for the item.']\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Make a specific critique of the prompt and response.\n",
+ "# Then print out the principles list from the alignment.\n",
+ "principles = single_run_prompt.critique_response(\n",
+ " 'none of the uses are creative'\n",
+ ")\n",
+ "print(principles)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 52
+ },
+ "id": "tLs611yn4eig",
+ "outputId": "715f31f5-44e4-468f-90f5-b3ca1778ba2a"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Give three creative uses for the following item: {item} \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Update the prompt based on the new principle.\n",
+ "single_run_prompt.update_model_description_from_principles()\n",
+ "print(single_run_prompt.get_model_description())"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "9GV4EhKXdHlD",
+ "outputId": "ee28e29c-c3ed-403a-a1cf-a28b4c64bed6"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Here are three creative uses for scissors:\n",
+ "\n",
+ "1. **Sculptural Art:** Instead of cutting paper, use scissors to create intricate patterns and textures in clay, dough, or even foam. The precise cuts can add depth and dimension to your sculptures.\n",
+ "\n",
+ "2. **Jewelry Making:** Use scissors to cut thin strips of fabric, leather, or even wire for jewelry making. You can create delicate chains, intricate patterns, or even cut out shapes for pendants.\n",
+ "\n",
+ "3. **Upcycled Crafts:** Give old clothes or fabric scraps a new life by cutting them into shapes for patchwork quilts, decorative pillows, or even unique wall hangings. Scissors can also be used to cut out shapes for origami or paper crafts. \n",
+ "\n",
+ "\n",
+ "Let me know if you'd like more ideas!\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Get model output now that the prompt is updated based on the new principle.\n",
+ "reply = single_run_prompt.send_input({'item': 'scissors'})\n",
+ "print(reply.text)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "W79jTdlcJhhp"
+ },
+ "source": [
+ "# Alignment Through Direct Updates\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "OVy4fyBX4YXl"
+ },
+ "source": [
+ "This example shows aligning a simple prompt through direct feedback. This is a simpler approach than aligning through principle creation, which was shown above. One advantage of this approach is that it only requires one call to the alignment model as opposed to two calls for the principle-based approach. One disadvantage is that it doesn't create a standalone list of principles that captures our intent with this alignment process.\n",
+ "\n",
+ "You first create a simple prompt to align.\n",
+ "\n",
+ "You run the prompt through the target Gemma model and see the output.\n",
+ "\n",
+ "You can then provide feedback about the response in order to have the model alignment system make a direct update to the prompt so that it better captures our intent.\n",
+ "\n",
+ "Once you provide the feedback, the prompt is updated and printed out. You can repeat this process as many times as you want to continually refine the prompt.\n",
+ "\n",
+ "You then run the updated prompt on the target model and see the improved results."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "fbIGzsgFQPd5"
+ },
+ "outputs": [],
+ "source": [
+ "# @title Prompt to align\n",
+ "prompt = 'How do I change the oil in my lawnmover?' # @param {type:\"string\"}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "nBluGQoqw1o3"
+ },
+ "outputs": [],
+ "source": [
+ "# Create the model alignment instance, using Gemma to run the prompt and Gemini to do the alignment work.\n",
+ "single_run_prompt = single_run.AlignableSingleRun(gemma_model, gemini_model)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "cFa3OpcjqhbD",
+ "outputId": "e94220cb-f837-41ef-95db-7b2f308b5aab"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Changing the oil in your lawnmower is a relatively simple task that can help keep your machine running smoothly. Here's a general guide, but always consult your owner's manual for specific instructions and safety precautions:\n",
+ "\n",
+ "**What You'll Need:**\n",
+ "\n",
+ "* **New oil:** Check your owner's manual for the correct type and amount.\n",
+ "* **Oil filter:** Check your owner's manual for the correct type and size.\n",
+ "* **Oil filter wrench:** This is essential for removing the old filter.\n",
+ "* **Drain pan:** To catch the old oil.\n",
+ "* **Funnel:** To help pour the new oil.\n",
+ "* **Wrench:** To remove the drain plug.\n",
+ "* **Gloves:** To protect your hands.\n",
+ "* **Rags or paper towels:** For cleaning up spills.\n",
+ "\n",
+ "**Steps:**\n",
+ "\n",
+ "1. **Safety First:**\n",
+ " * **Disconnect the spark plug:** This prevents accidental starting.\n",
+ " * **Wear gloves:** Protect your hands from hot oil.\n",
+ " * **Work in a well-ventilated area:** Oil fumes can be harmful.\n",
+ "\n",
+ "2. **Locate the Oil Drain Plug:**\n",
+ " * Consult your owner's manual for the exact location. It's usually on the bottom of the engine.\n",
+ "\n",
+ "3. **Position the Drain Pan:**\n",
+ " * Place the drain pan under the drain plug.\n",
+ "\n",
+ "4. **Remove the Drain Plug:**\n",
+ " * Use a wrench to loosen and remove the drain plug.\n",
+ " * Let the oil drain completely into the pan.\n",
+ "\n",
+ "5. **Replace the Drain Plug:**\n",
+ " * Once the oil has drained, clean the drain plug and its threads.\n",
+ " * Reinstall the drain plug and tighten it securely.\n",
+ "\n",
+ "6. **Remove the Oil Filter:**\n",
+ " * Use an oil filter wrench to loosen the old filter.\n",
+ " * Be careful, as the filter may be hot.\n",
+ " * Remove the old filter and discard it.\n",
+ "\n",
+ "7. **Install the New Oil Filter:**\n",
+ " * Apply a thin coat of new oil to the gasket of the new filter.\n",
+ " * Screw the new filter onto the engine by hand until snug.\n",
+ " * Tighten it with the wrench, but don't overtighten.\n",
+ "\n",
+ "8. **Add New Oil:**\n",
+ " * Locate the oil fill cap on your lawnmower.\n",
+ " * Use a funnel to pour the correct amount of new oil into the engine.\n",
+ " * Refer to your owner's manual for the recommended oil capacity.\n",
+ "\n",
+ "9. **Check the Oil Level:**\n",
+ " * Start the engine and let it run for a few minutes.\n",
+ " * Turn off the engine and check the oil level with the dipstick.\n",
+ " * Add more oil if necessary.\n",
+ "\n",
+ "10. **Dispose of Old Oil Properly:**\n",
+ " * Never pour used oil down the drain.\n",
+ " * Take it to a recycling center or auto parts store.\n",
+ "\n",
+ "\n",
+ "**Important Notes:**\n",
+ "\n",
+ "* **Consult your owner's manual:** Always refer to your lawnmower's manual for specific instructions and safety precautions.\n",
+ "* **Use the correct oil:** Using the wrong type of oil can damage your engine.\n",
+ "* **Don't overfill the engine:** Overfilling can cause oil to spill and damage your lawnmower.\n",
+ "* **Dispose of used oil properly:** Used oil is hazardous waste and should be disposed of responsibly.\n",
+ "\n",
+ "\n",
+ "By following these steps, you can safely and effectively change the oil in your lawnmower.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Run the initial prompt with Gemma\n",
+ "single_run_prompt.set_model_description(prompt)\n",
+ "output = single_run_prompt.send_input()\n",
+ "print(output.text)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "id": "PlPPn3X2xFGr",
+ "outputId": "dd3d66a7-f165-47c1-e975-e4cda94865dc"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "How do I change the oil in my lawnmover? Please make each step as short and simple as possible.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Make a specific critique of the prompt and response, causing a direct update to the prompt.\n",
+ "# Then print out the updated prompt\n",
+ "updated_prompt = single_run_prompt.update_model_description_from_feedback(\n",
+ " 'make each step as simple and short as possible'\n",
+ ")\n",
+ "print(updated_prompt)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "TEy_dACGimKH",
+ "outputId": "3b6479e1-9659-44b4-9116-71887479c432"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "## Changing Lawn Mower Oil: A Quick Guide\n",
+ "\n",
+ "**Before you start:**\n",
+ "\n",
+ "* **Safety first!** Disconnect the spark plug and let the engine cool down.\n",
+ "* **Gather your supplies:** New oil, oil filter, wrench, drain pan, funnel, and rags.\n",
+ "\n",
+ "**Steps:**\n",
+ "\n",
+ "1. **Locate the oil drain plug:** Usually under the engine.\n",
+ "2. **Position the drain pan:** Under the plug.\n",
+ "3. **Remove the drain plug:** Let the oil drain completely.\n",
+ "4. **Replace the drain plug:** Tighten securely.\n",
+ "5. **Remove the oil filter:** Use a wrench.\n",
+ "6. **Install the new oil filter:** Hand-tighten.\n",
+ "7. **Add new oil:** Use the funnel to pour the correct amount (check your owner's manual).\n",
+ "8. **Start the engine:** Run for a few minutes, then check for leaks.\n",
+ "9. **Dispose of old oil properly:** Take it to a recycling center.\n",
+ "\n",
+ "**Congratulations! You've changed your lawnmower oil.** \n",
+ "\n",
+ "\n",
+ "**Important:** Always consult your owner's manual for specific instructions and oil type recommendations.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Get model output now that the prompt is updated based on the feedback.\n",
+ "\n",
+ "output = single_run_prompt.send_input()\n",
+ "print(output.text)"
+ ]
+ }
+ ],
+ "metadata": {
+ "accelerator": "GPU",
+ "colab": {
+ "collapsed_sections": [
+ "4TinoiDCCibN"
+ ],
+ "gpuType": "T4",
+ "machine_shape": "hm",
+ "provenance": [],
+ "include_colab_link": true
+ },
+ "kernelspec": {
+ "display_name": "Python 3",
+ "name": "python3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
\ No newline at end of file
From dd754953186106a0eb7cb717847dd660629a8866 Mon Sep 17 00:00:00 2001
From: CatRob satoshi Git <137897299+Catro-b@users.noreply.github.com>
Date: Mon, 8 Dec 2025 18:47:31 +0700
Subject: [PATCH 3/3] Created using Colab
---
notebooks/Gemma_for_Model_Alignment.ipynb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/notebooks/Gemma_for_Model_Alignment.ipynb b/notebooks/Gemma_for_Model_Alignment.ipynb
index 0dc3c95..8a24957 100644
--- a/notebooks/Gemma_for_Model_Alignment.ipynb
+++ b/notebooks/Gemma_for_Model_Alignment.ipynb
@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"metadata": {
"id": "lxzsE00VCqH6"
},
@@ -143,13 +143,13 @@
"from google.colab import userdata\n",
"\n",
"# Setup Keras to use jax backend and configure for successful colab GPU usage.\n",
- "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\".\n",
+ "os.environ[\"KERAS_BACKEND\"] = \"\" # Or \"tensorflow\" or \"torch\".\n",
"os.environ[\"XLA_PYTHON_CLIENT_MEM_FRACTION\"] = \"0.9\"\n",
"\n",
"# Note: `userdata.get` is a Colab API. If you're not using Colab, set the env\n",
"# vars as appropriate for your system.\n",
- "os.environ[\"KAGGLE_USERNAME\"] = userdata.get(\"KAGGLE_USERNAME\")\n",
- "os.environ[\"KAGGLE_KEY\"] = userdata.get(\"KAGGLE_KEY\")"
+ "os.environ[\"KAGGLE_USERNAME\"] = userdata.get(\"\")\n",
+ "os.environ[\"KAGGLE_KEY\"] = userdata.get(\"\")"
]
},
{