diff --git a/examples/Deterministic_outputs_with_the_seed_parameter.ipynb b/examples/Deterministic_outputs_with_the_seed_parameter.ipynb deleted file mode 100644 index 625828c3..00000000 --- a/examples/Deterministic_outputs_with_the_seed_parameter.ipynb +++ /dev/null @@ -1 +0,0 @@ -{"cells":[{"cell_type":"markdown","metadata":{"cell_id":"67bb097e130b41099c9d257dc06a4054","deepnote_cell_type":"markdown"},"source":["# How to make your completions outputs consistent with the new seed parameter\n","\n","**TLDR**: Developers can now specify `seed` parameter in the Chat Completion request for consistent completions. We always include a `system_fingerprint` in the response that helps developers understand changes in our system that will affect determinism.\n","\n","### Context\n","\n","Determinism has always been a big request from user communities when using our APIs. For instance, when granted the capability of getting deterministic numerical result, users can unlock quite a bit of use cases that’s sensitive to numerical changes.\n","\n","#### Model level features for consistent outputs\n","\n","The Chat Completions and Completions APIs are non-deterministic by default (which means model outputs may differ from request to request), but now offer some control towards deterministic outputs using a few model level controls.\n","\n","This can unlock consistent completions which enables full control on the model behaviors for anything built on top of the APIs, and quite useful for reproducing results and testing so you know get peace of mind from knowing exactly what you’d get.\n","\n","#### Implementing consistent outputs\n","\n","To receive _mostly_ deterministic outputs across API calls:\n","\n","- Set the `seed` parameter to any integer of your choice, but use the same value across requests. For example, `12345`.\n","- Set all other parameters (prompt, temperature, top_p, etc.) to the same values across requests.\n","- In the response, check the `system_fingerprint` field. The system fingerprint is an identifier for the current combination of model weights, infrastructure, and other configuration options used by OpenAI servers to generate the completion. It changes whenever you change request parameters, or OpenAI updates numerical configuration of the infrastructure serving our models (which may happen a few times a year).\n","\n","If the `seed`, request parameters, and `system_fingerprint` all match across your requests, then model outputs will mostly be identical. There is a small chance that responses differ even when request parameters and `system_fingerprint` match, due to the inherent non-determinism of computers.\n"]},{"cell_type":"markdown","metadata":{"cell_id":"f49611fa59af4303883d76c491095fea","deepnote_cell_type":"markdown"},"source":["### Model level controls for consistent outputs - `seed` and `system_fingerprint`\n","\n","##### `seed`\n","\n","If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.\n","\n","##### `system_fingerprint`\n","\n","This fingerprint represents the backend configuration that the model runs with. It can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.This is the indicator on whether users should expect \"almost always the same result\".\n"]},{"cell_type":"markdown","metadata":{"cell_id":"cc6cd37b9a2243aaa4688ef8832512eb","deepnote_cell_type":"markdown"},"source":["## Example: Generating a consistent short story with a fixed seed\n","\n","In this example, we will demonstrate how to generate a consistent short story using a fixed seed. This can be particularly useful in scenarios where you need to reproduce the same results for testing, debugging, or for applications that require consistent outputs.\n"]},{"cell_type":"markdown","metadata":{},"source":["### Python SDK\n","\n","> **Note**\n","> Switch to latest version of the SDK (`1.3.3` at time of writing)."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!pip install --upgrade openai # Switch to the latest version of OpenAI (1.3.3 at time of writing)"]},{"cell_type":"code","execution_count":null,"metadata":{"cell_id":"48fd2d4c95ad465090ef97254a4a10d2","deepnote_cell_type":"code"},"outputs":[],"source":["import asyncio\n","import openai\n","import pprint\n","import difflib\n","from IPython.display import display, HTML\n","\n","GPT_MODEL = \"gpt-3.5-turbo-1106\""]},{"cell_type":"code","execution_count":null,"metadata":{"cell_id":"e54e0958be3746d39b6e4c16c59b395a","deepnote_cell_type":"code","deepnote_to_be_reexecuted":false,"execution_millis":5,"execution_start":1699034108287,"source_hash":null},"outputs":[],"source":["async def get_chat_response(system_message: str, user_request: str, seed: int = None):\n"," try:\n"," messages = [\n"," {\"role\": \"system\", \"content\": system_message},\n"," {\"role\": \"user\", \"content\": user_request},\n"," ]\n","\n"," response = openai.chat.completions.create(\n"," model=GPT_MODEL,\n"," messages=messages,\n"," seed=seed,\n"," max_tokens=200,\n"," temperature=0.7,\n"," )\n","\n"," response_content = response.choices[0].message.content\n"," system_fingerprint = response.system_fingerprint\n"," prompt_tokens = response.usage.prompt_tokens\n"," completion_tokens = (\n"," response.usage.total_tokens - response.usage.prompt_tokens\n"," )\n","\n"," table = f\"\"\"\n"," \n"," \n"," \n"," \n"," \n","
Response{response_content}
System Fingerprint{system_fingerprint}
Number of prompt tokens{prompt_tokens}
Number of completion tokens{completion_tokens}
\n"," \"\"\"\n"," display(HTML(table))\n","\n"," return response_content\n"," except Exception as e:\n"," print(f\"An error occurred: {e}\")\n"," return None\n","\n","\n","# This function compares two responses and displays the differences in a table.\n","# Deletions are highlighted in red and additions are highlighted in green.\n","# If no differences are found, it prints \"No differences found.\"\n","\n","\n","def compare_responses(previous_response: str, response: str):\n"," d = difflib.Differ()\n"," diff = d.compare(previous_response.splitlines(), response.splitlines())\n","\n"," diff_table = \"\"\n"," diff_exists = False\n","\n"," for line in diff:\n"," if line.startswith(\"- \"):\n"," diff_table += f\"\"\n"," diff_exists = True\n"," elif line.startswith(\"+ \"):\n"," diff_table += f\"\"\n"," diff_exists = True\n"," else:\n"," diff_table += f\"\"\n","\n"," diff_table += \"
{line}
{line}
{line}
\"\n","\n"," if diff_exists:\n"," display(HTML(diff_table))\n"," else:\n"," print(\"No differences found.\")"]},{"cell_type":"markdown","metadata":{"cell_id":"dfa39a438aa948cc910a46254df937af","deepnote_cell_type":"text-cell-p","formattedRanges":[]},"source":["First, let's try generating a short story about \"a journey to Mars\" without the `seed` parameter. This is the default behavior:\n"]},{"cell_type":"code","execution_count":null,"metadata":{"cell_id":"9d09f63309c449e4929364caccfd7065","deepnote_cell_type":"code","deepnote_to_be_reexecuted":false,"execution_millis":964,"execution_start":1699034108745,"source_hash":null},"outputs":[{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
ResponseIn the year 2050, a team of courageous astronauts embarked on a groundbreaking mission to Mars. The journey was filled with uncertainty and danger, but the crew was undeterred by the challenges that lay ahead.\n","\n","As their spacecraft hurtled through the vast expanse of space, the astronauts marveled at the beauty of the stars and the distant planets. They passed the time by conducting experiments, training for the mission ahead, and bonding with one another.\n","\n","After months of travel, the red planet finally came into view. The crew prepared for the landing, their hearts pounding with a mix of excitement and nervous anticipation. As the spacecraft touched down on the Martian surface, cheers erupted in the control room back on Earth.\n","\n","The astronauts stepped out onto the alien terrain, taking in the breathtaking landscape of rusty red rocks and dusty plains. They set up their base camp and began their scientific research, collecting samples and conducting experiments to better understand the planet's composition and potential for sustaining life.\n","\n","Despite the challenges of living
System Fingerprintfp_fefa7b2153
Number of prompt tokens31
Number of completion tokens200
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
ResponseIn the year 2050, a team of astronauts set out on a groundbreaking mission to Mars. The journey was long and arduous, but the crew was determined to make history. As they approached the red planet, they marveled at its otherworldly beauty and the sense of awe and wonder filled their hearts.\n","\n","Upon landing, the astronauts began to explore the alien landscape, conducting scientific experiments and collecting samples. They were amazed by the vast canyons, towering mountains, and the eerie silence that surrounded them. Each step they took was a giant leap for humankind, and they felt a profound sense of accomplishment.\n","\n","As they prepared to return to Earth, the astronauts reflected on the significance of their journey. They knew that their discoveries would pave the way for future generations to explore and inhabit Mars. With their mission complete, they boarded their spacecraft and set their sights on the distant blue planet in the sky, knowing that they had left their mark on the history of space exploration.
System Fingerprintfp_fefa7b2153
Number of prompt tokens31
Number of completion tokens198
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["
- In the year 2050, a team of courageous astronauts embarked on a groundbreaking mission to Mars. The journey was filled with uncertainty and danger, but the crew was undeterred by the challenges that lay ahead.
+ In the year 2050, a team of astronauts set out on a groundbreaking mission to Mars. The journey was long and arduous, but the crew was determined to make history. As they approached the red planet, they marveled at its otherworldly beauty and the sense of awe and wonder filled their hearts.
- As their spacecraft hurtled through the vast expanse of space, the astronauts marveled at the beauty of the stars and the distant planets. They passed the time by conducting experiments, training for the mission ahead, and bonding with one another.
+ Upon landing, the astronauts began to explore the alien landscape, conducting scientific experiments and collecting samples. They were amazed by the vast canyons, towering mountains, and the eerie silence that surrounded them. Each step they took was a giant leap for humankind, and they felt a profound sense of accomplishment.
+ As they prepared to return to Earth, the astronauts reflected on the significance of their journey. They knew that their discoveries would pave the way for future generations to explore and inhabit Mars. With their mission complete, they boarded their spacecraft and set their sights on the distant blue planet in the sky, knowing that they had left their mark on the history of space exploration.
- After months of travel, the red planet finally came into view. The crew prepared for the landing, their hearts pounding with a mix of excitement and nervous anticipation. As the spacecraft touched down on the Martian surface, cheers erupted in the control room back on Earth.
-
- The astronauts stepped out onto the alien terrain, taking in the breathtaking landscape of rusty red rocks and dusty plains. They set up their base camp and began their scientific research, collecting samples and conducting experiments to better understand the planet's composition and potential for sustaining life.
-
- Despite the challenges of living
"],"text/plain":[""]},"metadata":{},"output_type":"display_data"}],"source":["topic = \"a journey to Mars\"\n","system_message = \"You are a helpful assistant that generates short stories.\"\n","user_request = f\"Generate a short story about {topic}.\"\n","\n","previous_response = await get_chat_response(\n"," system_message=system_message, user_request=user_request\n",")\n","\n","response = await get_chat_response(\n"," system_message=system_message, user_request=user_request\n",")\n","\n","# The function compare_responses is then called with the two responses as arguments.\n","# This function will compare the two responses and display the differences in a table.\n","# If no differences are found, it will print \"No differences found.\"\n","compare_responses(previous_response, response)"]},{"cell_type":"markdown","metadata":{"cell_id":"e7eaf30e13ac4841b11dcffc505379c1","deepnote_cell_type":"markdown"},"source":["Now, let's try to generate the short story with the same topic (a journey to Mars) with a constant `seed` of 123 and compare the responses and `system_fingerprint`.\n"]},{"cell_type":"code","execution_count":null,"metadata":{"cell_id":"a5754b8ef4074cf7adb479d44bebd97b","deepnote_cell_type":"code"},"outputs":[{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
ResponseIn the not-so-distant future, a team of brave astronauts embarked on a groundbreaking journey to Mars. The spacecraft, named \"Odyssey,\" soared through the vast expanse of space, leaving Earth behind as they ventured toward the mysterious red planet.\n","\n","As the crew navigated through the cosmos, they encountered a series of challenges and obstacles, from intense solar flares to treacherous asteroid fields. However, their unwavering determination and spirit of camaraderie propelled them forward, overcoming each hurdle with courage and resilience.\n","\n","Upon reaching Mars, the astronauts were greeted by a breathtaking landscape of rust-colored deserts and towering canyons. They marveled at the alien terrain, conducting scientific experiments and collecting samples to better understand the planet's enigmatic history.\n","\n","Amidst their exploration, the crew faced unexpected setbacks, including a sudden dust storm that threatened their safety. Yet, they stood united, devising ingenious solutions and supporting each other through the adversity.\n","\n","After a successful mission on Mars, the
System Fingerprintfp_fefa7b2153
Number of prompt tokens31
Number of completion tokens200
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
ResponseIn the not-so-distant future, a team of brave astronauts embarked on a groundbreaking journey to Mars. The spacecraft, named \"Odyssey,\" soared through the vast expanse of space, leaving Earth behind as they ventured toward the mysterious red planet.\n","\n","As the crew navigated through the cosmos, they encountered a series of challenges and obstacles, from intense solar flares to treacherous asteroid fields. However, their unwavering determination and spirit of camaraderie propelled them forward, overcoming each hurdle with courage and resilience.\n","\n","Upon reaching Mars, the astronauts were greeted by a breathtaking landscape of rust-colored deserts and towering canyons. They marveled at the alien terrain, conducting scientific experiments and collecting samples to better understand the planet's enigmatic history.\n","\n","Amidst their exploration, the crew faced unexpected setbacks, including a sudden dust storm that threatened their safety. Yet, they stood united, devising ingenious solutions and supporting each other through the adversity.\n","\n","After a successful mission on Mars, the
System Fingerprintfp_fefa7b2153
Number of prompt tokens31
Number of completion tokens200
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["No differences found.\n"]}],"source":["SEED = 123\n","response = await get_chat_response(\n"," system_message=system_message, seed=SEED, user_request=user_request\n",")\n","previous_response = response\n","response = await get_chat_response(\n"," system_message=system_message, seed=SEED, user_request=user_request\n",")\n","\n","compare_responses(previous_response, response)"]},{"cell_type":"markdown","metadata":{"cell_id":"f6c8ae9a6e29451baaeb52b7203fbea8","deepnote_cell_type":"markdown"},"source":["## Conclusion\n","\n","We demonstrated how to use a fixed integer `seed` to generate consistent outputs from our model.This is particularly useful in scenarios where reproducibility is important. However, it's important to note that while the `seed` ensures consistency, it does not guarantee the quality of the output. For instance, in the example provided, we used the same seed to generate a short story about a journey to Mars. Despite querying the model multiple times, the output remained consistent, demonstrating the effectiveness of using this model level control for reproducibility. Another great extension of this could be to use consistent `seed` when benchmarking/evaluating the performance of different prompts or models, to ensure that each version is evaluated under the same conditions, making the comparisons fair and the results reliable.\n"]},{"cell_type":"markdown","metadata":{"created_in_deepnote_cell":true,"deepnote_cell_type":"markdown"},"source":["\n","Created in deepnote.com \n","Created in Deepnote\n"]}],"metadata":{"deepnote":{},"deepnote_execution_queue":[],"deepnote_notebook_id":"90ee66ed8ee74f0dad849c869f1da806","kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.9.13"}},"nbformat":4,"nbformat_minor":0} diff --git a/examples/Reproducible_outputs_with_the_seed_parameter.ipynb b/examples/Reproducible_outputs_with_the_seed_parameter.ipynb new file mode 100644 index 00000000..119fe7db --- /dev/null +++ b/examples/Reproducible_outputs_with_the_seed_parameter.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{"cell_id":"67bb097e130b41099c9d257dc06a4054","deepnote_cell_type":"markdown"},"source":["# How to make your completions outputs reproducible with the new seed parameter\n","\n","**TLDR**: Developers can now specify `seed` parameter in the Chat Completion request to receive (mostly) consistent outputs. To help you keep track of these changes, we expose the `system_fingerprint` field. If this value is different, you may see different outputs due to changes we've made on our systems. Please note that this feature is in beta and only currently supported for `gpt-4-1106-preview` and `gpt-3.5-turbo-1106`.\n","\n","### Context\n","\n","Reproducibility has always been a big request from user communities when using our APIs. For instance, when granted the capability of getting reproducible numerical result, users can unlock quite a bit of use cases that’s sensitive to numerical changes.\n","\n","#### Model level features for consistent outputs\n","\n","The Chat Completions and Completions APIs are non-deterministic by default (which means model outputs may differ from request to request), but now offer some control towards deterministic outputs using a few model level controls.\n","\n","This can unlock consistent completions which enables full control on the model behaviors for anything built on top of the APIs, and quite useful for reproducing results and testing so you know get peace of mind from knowing exactly what you’d get.\n","\n","#### Implementing consistent outputs\n","\n","To receive _mostly_ deterministic outputs across API calls:\n","\n","- Set the `seed` parameter to any integer of your choice, but use the same value across requests. For example, `12345`.\n","- Set all other parameters (prompt, temperature, top_p, etc.) to the same values across requests.\n","- In the response, check the `system_fingerprint` field. The system fingerprint is an identifier for the current combination of model weights, infrastructure, and other configuration options used by OpenAI servers to generate the completion. It changes whenever you change request parameters, or OpenAI updates numerical configuration of the infrastructure serving our models (which may happen a few times a year).\n","\n","If the `seed`, request parameters, and `system_fingerprint` all match across your requests, then model outputs will mostly be identical. There is a small chance that responses differ even when request parameters and `system_fingerprint` match, due to the inherent non-determinism of our models.\n"]},{"cell_type":"markdown","metadata":{"cell_id":"f49611fa59af4303883d76c491095fea","deepnote_cell_type":"markdown"},"source":["### Model level controls for consistent outputs - `seed` and `system_fingerprint`\n","\n","##### `seed`\n","\n","If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.\n","\n","##### `system_fingerprint`\n","\n","This fingerprint represents the backend configuration that the model runs with. It can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.This is the indicator on whether users should expect \"almost always the same result\".\n"]},{"cell_type":"markdown","metadata":{"cell_id":"cc6cd37b9a2243aaa4688ef8832512eb","deepnote_cell_type":"markdown"},"source":["## Example: Generating a short excerpt with a fixed seed\n","\n","In this example, we will demonstrate how to generate a short excerpt using a fixed seed. This can be particularly useful in scenarios where you need to generate consistent results for testing, debugging, or for applications that require consistent outputs."]},{"cell_type":"markdown","metadata":{},"source":["### Python SDK\n","\n","> **Note**\n","> Switch to latest version of the SDK (`1.3.3` at time of writing)."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!pip install --upgrade openai # Switch to the latest version of OpenAI (1.3.3 at time of writing)"]},{"cell_type":"code","execution_count":12,"metadata":{"cell_id":"48fd2d4c95ad465090ef97254a4a10d2","deepnote_cell_type":"code"},"outputs":[],"source":["import openai\n","import asyncio\n","from IPython.display import display, HTML\n","\n","from utils.embeddings_utils import (\n"," get_embedding,\n"," distances_from_embeddings\n",")\n","\n","GPT_MODEL = \"gpt-3.5-turbo-1106\""]},{"cell_type":"code","execution_count":13,"metadata":{"cell_id":"e54e0958be3746d39b6e4c16c59b395a","deepnote_cell_type":"code","deepnote_to_be_reexecuted":false,"execution_millis":5,"execution_start":1699034108287,"source_hash":null},"outputs":[],"source":["async def get_chat_response(\n"," system_message: str, user_request: str, seed: int = None, temperature: float = 0.7\n","):\n"," try:\n"," messages = [\n"," {\"role\": \"system\", \"content\": system_message},\n"," {\"role\": \"user\", \"content\": user_request},\n"," ]\n","\n"," response = openai.chat.completions.create(\n"," model=GPT_MODEL,\n"," messages=messages,\n"," seed=seed,\n"," max_tokens=200,\n"," temperature=temperature,\n"," )\n","\n"," response_content = response.choices[0].message.content\n"," system_fingerprint = response.system_fingerprint\n"," prompt_tokens = response.usage.prompt_tokens\n"," completion_tokens = response.usage.total_tokens - response.usage.prompt_tokens\n","\n"," table = f\"\"\"\n"," \n"," \n"," \n"," \n"," \n","
Response{response_content}
System Fingerprint{system_fingerprint}
Number of prompt tokens{prompt_tokens}
Number of completion tokens{completion_tokens}
\n"," \"\"\"\n"," display(HTML(table))\n","\n"," return response_content\n"," except Exception as e:\n"," print(f\"An error occurred: {e}\")\n"," return None\n","\n","def calculate_average_distance(responses):\n"," \"\"\"\n"," This function calculates the average distance between the embeddings of the responses.\n"," The distance between embeddings is a measure of how similar the responses are.\n"," \"\"\"\n"," # Calculate embeddings for each response\n"," response_embeddings = [get_embedding(response) for response in responses]\n","\n"," # Compute distances between the first response and the rest\n"," distances = distances_from_embeddings(response_embeddings[0], response_embeddings[1:])\n","\n"," # Calculate the average distance\n"," average_distance = sum(distances) / len(distances)\n","\n"," # Return the average distance\n"," return average_distance"]},{"cell_type":"markdown","metadata":{"cell_id":"dfa39a438aa948cc910a46254df937af","deepnote_cell_type":"text-cell-p","formattedRanges":[]},"source":["First, let's try generating few different versions of a short excerpt about \"a journey to Mars\" without the `seed` parameter. This is the default behavior:"]},{"cell_type":"code","execution_count":14,"metadata":{"cell_id":"9d09f63309c449e4929364caccfd7065","deepnote_cell_type":"code","deepnote_to_be_reexecuted":false,"execution_millis":964,"execution_start":1699034108745,"source_hash":null},"outputs":[{"name":"stdout","output_type":"stream","text":["Output 1\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Mars mission reaches critical stage as spacecraft successfully enters orbit around the red planet. The historic journey, which began over a year ago, has captured the world's attention as scientists and astronauts prepare to land on Mars for the first time. The mission is expected to provide valuable insights into the planet's geology, atmosphere, and potential for sustaining human life in the future.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens76
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 2\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance rover successfully landed on Mars, marking a major milestone in the mission to explore the red planet. The rover is equipped with advanced scientific instruments to search for signs of ancient microbial life and collect samples of rock and soil for future return to Earth. This historic achievement paves the way for further exploration and potential human missions to Mars in the near future.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens76
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 3\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"SpaceX successfully launched the first manned mission to Mars yesterday, marking a historic milestone in space exploration. The crew of four astronauts will spend the next six months traveling to the red planet, where they will conduct groundbreaking research and experiments. This mission represents a significant step towards establishing a human presence on Mars and paves the way for future interplanetary travel.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens72
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 4\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's latest Mars mission exceeds expectations as the Perseverance rover uncovers tantalizing clues about the Red Planet's past. Scientists are thrilled by the discovery of ancient riverbeds and sedimentary rocks, raising hopes of finding signs of past life on Mars. With this exciting progress, the dream of sending humans to Mars feels closer than ever before.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens72
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 5\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance Rover Successfully Lands on Mars, Begins Exploration Mission\n","\n","In a historic moment for space exploration, NASA's Perseverance rover has successfully landed on the surface of Mars. After a seven-month journey, the rover touched down in the Jezero Crater, a location scientists believe may have once held a lake and could potentially contain signs of ancient microbial life.\n","\n","The rover's primary mission is to search for evidence of past life on Mars and collect rock and soil samples for future return to Earth. Equipped with advanced scientific instruments, including cameras, spectrometers, and a drill, Perseverance will begin its exploration of the Martian surface, providing valuable data and insights into the planet's geology and potential habitability.\n","\n","This successful landing marks a significant milestone in humanity's quest to understand the red planet and paves the way for future manned missions to Mars. NASA's Perseverance rover is poised to unravel the mysteries of Mars and unlock new possibilities
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens200
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["The average similarity between responses is: 0.1136714512418833\n"]}],"source":["topic = \"a journey to Mars\"\n","system_message = \"You are a helpful assistant.\"\n","user_request = f\"Generate a short excerpt of news about {topic}.\"\n","\n","responses = []\n","\n","\n","async def get_response(i):\n"," print(f'Output {i + 1}\\n{\"-\" * 10}')\n"," response = await get_chat_response(\n"," system_message=system_message, user_request=user_request\n"," )\n"," return response\n","\n","\n","responses = await asyncio.gather(*[get_response(i) for i in range(5)])\n","average_distance = calculate_average_distance(responses)\n","print(f\"The average similarity between responses is: {average_distance}\")"]},{"cell_type":"markdown","metadata":{"cell_id":"e7eaf30e13ac4841b11dcffc505379c1","deepnote_cell_type":"markdown"},"source":["Now, let's try to tun the same code with a constant `seed` of 123 and `temperature` of 0 and compare the responses and `system_fingerprint`."]},{"cell_type":"code","execution_count":15,"metadata":{"cell_id":"a5754b8ef4074cf7adb479d44bebd97b","deepnote_cell_type":"code"},"outputs":[{"name":"stdout","output_type":"stream","text":["Output 1\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance Rover Successfully Lands on Mars\n","\n","In a historic achievement, NASA's Perseverance rover has successfully landed on the surface of Mars, marking a major milestone in the exploration of the red planet. The rover, which traveled over 293 million miles from Earth, is equipped with state-of-the-art instruments designed to search for signs of ancient microbial life and collect rock and soil samples for future return to Earth. This mission represents a significant step forward in our understanding of Mars and the potential for human exploration of the planet in the future.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens113
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 2\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance rover successfully lands on Mars, marking a historic milestone in space exploration. The rover is equipped with advanced scientific instruments to search for signs of ancient microbial life and collect samples for future return to Earth. This mission paves the way for future human exploration of the red planet, as scientists and engineers continue to push the boundaries of space travel and expand our understanding of the universe.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens81
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 3\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance rover successfully lands on Mars, marking a historic milestone in space exploration. The rover is equipped with advanced scientific instruments to search for signs of ancient microbial life and collect samples for future return to Earth. This mission paves the way for future human exploration of the red planet, as NASA continues to push the boundaries of space exploration.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens72
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 4\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance rover successfully lands on Mars, marking a historic milestone in space exploration. The rover is equipped with advanced scientific instruments to search for signs of ancient microbial life and collect samples for future return to Earth. This mission paves the way for future human exploration of the red planet, as scientists and engineers continue to push the boundaries of space travel and expand our understanding of the universe.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens81
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Output 5\n","----------\n"]},{"data":{"text/html":["\n"," \n"," \n"," \n"," \n"," \n","
Response\"NASA's Perseverance rover successfully lands on Mars, marking a historic milestone in space exploration. The rover is equipped with advanced scientific instruments to search for signs of ancient microbial life and collect samples for future return to Earth. This mission paves the way for future human exploration of the red planet, as scientists and engineers continue to push the boundaries of space travel.\"
System Fingerprintfp_772e8125bb
Number of prompt tokens29
Number of completion tokens74
\n"," "],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["The average distance between responses is: 0.0449054397632461\n"]}],"source":["SEED = 123\n","responses = []\n","\n","\n","async def get_response(i):\n"," print(f'Output {i + 1}\\n{\"-\" * 10}')\n"," response = await get_chat_response(\n"," system_message=system_message,\n"," seed=SEED,\n"," temperature=0,\n"," user_request=user_request,\n"," )\n"," return response\n","\n","\n","responses = await asyncio.gather(*[get_response(i) for i in range(5)])\n","\n","average_distance = calculate_average_distance(responses)\n","print(f\"The average distance between responses is: {average_distance}\")"]},{"cell_type":"markdown","metadata":{},"source":["As we can observe, the `seed` parameter allows us to generate much more consistent results."]},{"cell_type":"markdown","metadata":{"cell_id":"f6c8ae9a6e29451baaeb52b7203fbea8","deepnote_cell_type":"markdown"},"source":["## Conclusion\n","\n","We demonstrated how to use a fixed integer `seed` to generate consistent outputs from our model. This is particularly useful in scenarios where reproducibility is important. However, it's important to note that while the `seed` ensures consistency, it does not guarantee the quality of the output. Note that when you want to use reproducible outputs, you need to set the `seed` to the same integer across Chat Completions calls. You should also match any other parameters like `temperature`, `max_tokens` etc. Further extension of reproducible outputs could be to use consistent `seed` when benchmarking/evaluating the performance of different prompts or models, to ensure that each version is evaluated under the same conditions, making the comparisons fair and the results reliable."]}],"metadata":{"deepnote":{},"deepnote_execution_queue":[],"deepnote_notebook_id":"90ee66ed8ee74f0dad849c869f1da806","kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.5"}},"nbformat":4,"nbformat_minor":0} diff --git a/registry.yaml b/registry.yaml index 8077ebe3..b1dfd7d1 100644 --- a/registry.yaml +++ b/registry.yaml @@ -1119,7 +1119,7 @@ - dall-e - title: How to make your completions outputs consistent with the new seed parameter - path: examples/Deterministic_outputs_with_the_seed_parameter.ipynb + path: examples/Reproducible_outputs_with_the_seed_parameter.ipynb date: 2023-11-06 authors: - shyamal-anadkat