Chapter 31
3. 提示优化工具
第三章 提示优化工具
一、引言
对于大语言模型(Large Language Models, LLMs),我们通常需要遵循一些原则和策略来创建能产生高质量回答的有效提示:
-
明确和具体:你应该尽可能明确和具体地描述你希望 LLM 执行的任务。如果你期望得到特定类型的回答,应在提示中明确指出。同时,如果存在任何具体的限制或要求,也应明确提出。
-
开放式与封闭式:你可以根据需求选择开放式问题(允许多种回答)或封闭式问题(限制回答范围)。这两种类型的问题各有优势,你应根据实际需求进行选择。
-
语境清晰:为了让 LLM 生成更有意义的回答,你需要确保提供足够的上下文。如果提示是基于之前的信息,那么这些信息应被包含在内。
-
创造力和想象力:如果你期望得到创新性的输出,可以鼓励人工智能进行发散思维或头脑风暴。如果这符合你的需求,你还可以建议人工智能模拟某些场景。
实际上,我们可以利用这些原则和策略来有效地优化提示。
本章将介绍一个适用于 LLM 的优化提示工具。这个工具能够帮助你像 PromptPerfect 那样有效地优化提示,从而最大限度地发挥 LLM 的潜力,并获得更准确、与上下文相关的回答。
二、优化 Prompt 的代码示例
注意:我使用的测试环境是 UV + Python3.12+。Python 的版本要求 Python3.12+。
开始实验之前,我们需要按照Env-Setup.md中,安装好依赖环境。OpenAI Python 库提供了一个便捷的途径,让任何 Python 3.12+ 应用程序可以访问 OpenAI REST API。
导入此次实验所需的依赖库
import os
from openai import OpenAI
from dotenv import load_dotenv, find_dotenv
from IPython.display import Markdown
loaded = load_dotenv(find_dotenv(), override=True)
# 从环境变量中获取 OpenAI API Key 或者直接赋值
API_KEY = os.getenv("API_KEY")
# 如果您使用的是官方 API,就直接用 https://api.siliconflow.cn/v1 就行。
BASE_URL = "https://api.siliconflow.cn/v1"
# 如果您使用的不是官方 API,而是通过代理进行请求,请设置您的代理 URL。
# BASE_URL = "https://api.xxx.../v1"# 实例化 OpenAI 对象
# 传入参数:OpenAI API Key(必需)、Base URL 和最大重试次数
client = OpenAI(api_key=API_KEY, base_url=BASE_URL, max_retries=3)# 参数 n,整数或 Null,可选项,默认为 1。为每条输入信息生成多少个聊天完成选项。
# 参数 temperature,实数值或 Null,可选项,默认为 1。使用的采样温度,介于 0 和 2 之间。0.8 等较高值会使输出更加随机,而 0.2 等较低值会使输出更加集中和确定。
def get_completions1(system_instruction, llm_prompt, model_endpoint):
extra_body = {}
if "Qwen3" in model_endpoint:
extra_body={
"enable_thinking": False
}
response = client.chat.completions.create(model=model_endpoint,
messages=[{"role": "system", "content": system_instruction},
{"role": "user", "content": llm_prompt}
],
n=1, temperature=0.60, seed=42,
presence_penalty=0, frequency_penalty=0,
max_tokens=1024, extra_body = extra_body
)
return response.choices[0].message.content.strip()
def get_completions2(system_instruction, llm_prompt, model_endpoint):
extra_body = {}
if "Qwen3" in model_endpoint:
extra_body={
"enable_thinking": False
}
response = client.chat.completions.create(model=model_endpoint,
messages=[{"role": "system", "content": system_instruction},
{"role": "user", "content": llm_prompt}
],
n=1, temperature=0, seed=42,
presence_penalty=0, frequency_penalty=0,
max_tokens=1024, extra_body = extra_body
)
return response.choices[0].message.content.strip()下面给出的 system_instruction 模板的本质是利用上下文学习(Few-shot 演示)和提示工程。
# 中文
system_instruction1 = f"""你是一位出色的人工智能提示工程师。你是设计 ChatGPT 提示的专家,能取得最佳效果。
要创建能产生高质量回答的有效提示,请考虑以下原则和策略:
1. 明确和具体:尽可能明确、具体地说明你希望人工智能做些什么。如果你想要某种类型的答复,请在提示中简要说明。如果有具体的限制或要求,也一定要写明。
2. 开放式与封闭式:根据你的需求,你可能会选择开放式问题(允许多种回答)或封闭式问题(缩小可能回答的范围)。两者都有其用途,请根据自己的需要进行选择。
3. 语境清晰:确保提供足够的上下文,以便人工智能生成有意义的相关回复。如果提示是基于先前的信息,则应确保包含这些信息。
4. 创造力和想象力:如果你想要创造性的输出,可以鼓励人工智能发散思维或进行头脑风暴。如果符合你的需求,你甚至可以建议人工智能想象某些场景。
你的任务是根据用户给定的提示进行优化,设计出一个新的、经过优化的 ChatGPT 提示。
下面提供了一些好的示例,供你参考:
原始提示:你的任务是使用 Python,根据用户给的数据绘制散点图。
优化后的提示:你的任务是使用 Python 编程语言,根据用户给定的数据绘制一个散点图。请确保散点图能够清晰地展示数据之间的关系,并使用适当的颜色、形状和标签来区分不同的数据点。此外,你还需要为图表添加标题、坐标轴标签以及图例(如果适用),以便更好地解释数据的含义。最后,请将生成的散点图保存为一个图像文件,以便用户可以查看和分享。
原始提示:你的任务是将用户给定的英文翻译成中文。
优化后的提示:请将以下英文文本准确地翻译成中文,保持原文的意思和语境不变。如果英文中包含专有名词或术语,请在翻译时注明其标准中文名称或提供相应的解释。此外,请确保翻译后的中文句子通顺、语法正确,并且符合中文的表达习惯。
原始提示:你的任务是指导初学者系统地学习机器学习。
优化后的提示:你被要求为一个完全没有机器学习背景的初学者设计一个详细的学习计划。请你描述这个计划,包括以下维度:首先,推荐适合初学者的机器学习入门教材或在线课程;其次,提供一个结构化的学习路线图,明确指出在学习过程中应该先掌握哪些基本概念,再逐步深入到哪些高级主题;最后,请提出一些实践建议,比如初学者可以通过哪些项目来巩固理论知识,以及在遇到困难时如何寻求帮助和资源。请确保你的回答涵盖了机器学习的基础知识、算法理解、编程实践,以及如何解决实际问题等方面。
"""
# 英文
system_instruction2 = f"""You are an exceptional AI prompt engineer. \
You are an expert at writing ChatGPT Prompts for best results.
To create efficient prompts that yield high-quality responses, \
consider the following principles and strategies:
1. Clear and Specific: Be as clear and specific as possible about what you want from the AI. If you want a certain type of response, outline that in your prompt. If there are specific constraints or requirements, make sure to include those as well.
2. Open-ended vs. Closed-ended: Depending on what you're seeking, you might choose to ask an open-ended question (which allows for a wide range of responses) or a closed-ended question (which narrows down the possible responses). Both have their uses, so choose according to your needs.
3. Contextual Clarity: Make sure to provide enough context so that the AI can generate a meaningful and relevant response. If the prompt is based on prior information, ensure that this is included.
4. Creativity and Imagination: If you want creative output, encourage the AI to think outside the box or to brainstorm. You can even suggest the AI to imagine certain scenarios if it fits your needs.
Your task is to design a new, optimized ChatGPT prompt based on the user-given prompt.
Some good examples are provided below for your reference:
Original prompt: Your task is to plot a scatterplot based on data given by the user, using Python.
Optimized prompt: Your task is to use the Python programming language to draw a scatterplot based on data given by a user. Make sure that the scatterplot clearly shows the relationships between the data and uses appropriate colors, shapes, and labels to distinguish the different data points. In addition, you will need to add a title, axis labels, and a legend (if applicable) to the chart to better explain the meaning of the data. Finally, please save the resulting scatterplot as an image file so that users can view and share it.
Original prompt: Your task is to translate the English text given by the user into Chinese.
Optimized prompt: Please translate the following English text accurately into Chinese, keeping the meaning and context of the original text intact. If the English text contains proper nouns or terms, please indicate their standard Chinese names or provide corresponding explanations when translating. In addition, please make sure that the translated Chinese sentences are fluent, grammatically correct, and in line with Chinese expressions.
Original prompt: You have been tasked with guiding a beginner to learn machine learning in a systematic way.
Optimized prompt: You have been asked to design a detailed learning plan for a beginner who has no machine learning background at all. Please describe the plan, including the following dimensions: first, recommend introductory machine learning textbooks or online courses suitable for beginners; second, provide a structured learning roadmap that clearly indicates which basic concepts should be mastered before progressively delving into which advanced topics during the learning process; finally, please make some practical suggestions, such as which projects beginners can work on to consolidate their theoretical knowledge and how to seek help and resources when they are how to seek help and resources when encountering difficulties. Please make sure your answer covers the basics of machine learning, algorithmic understanding, programming practices, and how to solve real-world problems.
"""2.1 示例 1
llm = "Qwen/Qwen3-8B"
original_prompt = "你的任务是使用 Python,根据用户给的数据绘制热力图。"
original_prompt = f"""原始提示:{original_prompt}"""
optimized_prompt = get_completions1(system_instruction1, original_prompt, llm)
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
instruction_ = "你是世界知识专家。"
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
原始提示:你的任务是使用 Python,根据用户给的数据绘制热力图。
优化后的提示:你的任务是使用 Python 编程语言,根据用户提供的数据集绘制一个清晰且具有视觉表现力的热力图。请确保热力图能够有效展示数据中的相关性或密度分布,并使用合适的颜色映射(如从浅到深的渐变色)来增强可读性。此外,你还需要为图表添加标题、坐标轴标签以及图例(如果适用),以便更好地解释数据的含义。如果数据维度较多,请考虑使用适当的注释或交互方式来帮助用户理解。最后,请将生成的热力图保存为图像文件,并提供一个简要的说明,解释热力图中颜色和模式所代表的含义。
----------------------------------------------------------------------------------------------------
原始提示的生成结果:
当然可以!使用 Python 绘制热力图(Heatmap)是一个非常常见的任务,通常可以通过 `matplotlib` 和 `seaborn` 库来实现。下面我将为你提供一个完整的示例,包括数据准备、热力图绘制以及一些基本的样式设置。
---
## ✅ 一、热力图简介
热力图是一种用颜色表示数据矩阵中数值大小的图表,常用于可视化二维数据,比如相关系数矩阵、矩阵数据分布等。颜色越深,表示数值越大;颜色越浅,表示数值越小。
---
## ✅ 二、Python 绘制热力图的常用库
- **matplotlib**:基础绘图库,可以绘制热力图。
- **seaborn**:基于 matplotlib 的高级库,提供更简洁的 API 来绘制热力图。
- **pandas**:用于数据处理和整理,特别是处理表格数据。
---
## ✅ 三、示例:使用 Seaborn 绘制热力图
### 📌 1. 安装必要的库(如果尚未安装)
```bash
pip install matplotlib seaborn pandas numpy
```
### 📌 2. 示例数据准备
我们可以使用 `numpy` 生成一个随机的 10x10 矩阵作为示例数据:
```python
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# 生成一个 10x10 的随机矩阵
data = np.random.rand(10, 10)
```
### 📌 3. 绘制热力图
```python
# 设置绘图风格
sns.set(style="white")
# 创建热力图
plt.figure(figsize=(8, 6))
heatmap = sns.heatmap(data, cmap="YlGnBu", annot=True, fmt=".2f", linewidths=.5, cbar_kws={"shrink": .5})
# 添加标题
plt.title("Heatmap Example")
# 显示图形
plt.show()
```
---
## ✅ 四、解释代码
- `sns.set(style="white")`:设置 seaborn 的绘图风格为白色背景。
- `sns.heatmap()`:绘制热力图,参数说明如下:
- `data`:要绘制的数据矩阵。
- `cmap`:颜色映射方案,如 `"YlGnBu"`。
- `annot=True`:在每个单元格中显示数值。
- `fmt=".2f"`:数值显示格式为两位小数。
- `linewidths=.5`:单元格之间的线宽。
- `cbar_kws={"shrink": .5}`:调整颜色条的大小。
- `plt.title()`:添加图表标题。
- `plt.show()`:显示图表。
---
## ✅ 五、使用 Pandas DataFrame 绘制热力图
如果你的数据是表格形式,可以使用 `pandas` 来处理:
```python
import pandas as pd
# 创建一个 DataFrame
df = pd.DataFrame(np.random.rand(10, 10), columns=list('ABCDEFGHIJ'), index=list('0123456789'))
# 绘制热力图
plt.figure(figsize=(10, 8))
sns.heatmap(df, annot=True, fmt=".2f", cmap="coolwarm", cbar=True)
plt.title("Heatmap with Pandas DataFrame")
plt.show()
```
---
## ✅ 六、自定义热力图
你可以根据需要自定义热力图的样式,比如:
- 调整颜色映射(`cmap`):`"viridis"`, `"plasma"`, `"cividis"`, `"coolwarm"` 等。
- 设置颜色条(`cbar`):`True` 或 `False`。
- 添加注释(`annot`):`True` 或 `False`。
- 设置标题(`title`)。
- 设置字体大小(`annot_kws={"size": 12}`)。
---
## ✅ 七、使用 Matplotlib 绘制热力图(不依赖 seaborn)
如果你不想使用 seaborn,也可以用 `matplotlib` 来绘制:
```python
import matplotlib.pyplot as plt
import numpy as np
# 生成数据
data = np.random.rand(10, 10)
# 绘制热力图
plt.imshow(data, cmap="viridis", interpolation='nearest')
plt.colorbar()
# 添加标签
plt.xticks(range(10), ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
plt.yticks(range(10), ['0', '1', '2', '3', '4', '5
----------------------------------------------------------------------------------------------------
优化后的提示的生成结果:
当然!以下是一个使用 Python 编程语言绘制热力图的完整示例。我们将使用 `seaborn` 和 `matplotlib` 库来实现,这些库非常适合可视化数据的相关性矩阵或密度分布。
---
## ✅ 任务目标
- 使用 Python 绘制热力图
- 展示数据中的相关性或密度分布
- 使用合适的颜色映射(如从浅到深的渐变色)
- 添加标题、坐标轴标签、图例(如适用)
- 若数据维度较多,考虑使用注释或交互方式
- 保存热力图为图像文件
- 提供简要说明解释颜色和模式的含义
---
## 📌 示例代码
假设你有一个数据集 `data`,它是一个二维数组或 DataFrame,表示不同变量之间的相关性或密度值。
```python
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# 示例数据集(可以替换为你的实际数据)
# 这里使用一个随机生成的 10x10 相关性矩阵
np.random.seed(42)
data = np.random.rand(10, 10)
columns = [f'Feature {i}' for i in range(10)]
index = [f'Variable {i}' for i in range(10)]
# 将数据转换为 DataFrame
df = pd.DataFrame(data, columns=columns, index=index)
# 绘制热力图
plt.figure(figsize=(10, 8))
sns.heatmap(df, annot=True, fmt=".2f", cmap='coolwarm', cbar_kws={"label": "相关性强度"}, square=True)
# 添加标题和坐标轴标签
plt.title('Heatmap of Correlation Matrix', fontsize=16)
plt.xlabel('Variables', fontsize=12)
plt.ylabel('Features', fontsize=12)
# 保存图像
plt.savefig('correlation_heatmap.png', dpi=300, bbox_inches='tight')
# 显示图像
plt.show()
# 简要说明
print("热力图说明:")
print("颜色从浅蓝到深红表示相关性强度,浅色代表弱相关(接近0),深色代表强相关(接近1或-1)。")
print("图中的数字是每个单元格的具体相关性值,有助于更精确地理解数据。")
print("该热力图展示了10个变量与10个特征之间的相关性分布。")
```
---
## 📊 输出说明
- **颜色映射(cmap)**:使用了 `'coolwarm'`,这是一种从浅蓝(低值)到深红(高值)的渐变色,非常适合表示相关性或密度。
- **注释(annot)**:在每个单元格中显示具体数值,便于理解。
- **图例(cbar_kws)**:颜色条标注了“相关性强度”,帮助解释颜色含义。
- **标题和坐标轴标签**:清晰地说明了图表内容。
- **保存图像**:生成的图像保存为 `correlation_heatmap.png`,可以用于报告或展示。
---
## 📌 适用场景
- **相关性分析**:如果你的数据是变量之间的相关性矩阵(如使用 `pandas.DataFrame.corr()` 生成),热力图是展示这些关系的绝佳方式。
- **密度分布**:如果你的数据是二维密度分布(如使用 `seaborn.kdeplot` 或 `seaborn.jointplot` 生成的矩阵),也可以用热力图来可视化。
- **多维数据**:如果数据维度较多,可以使用 `annot` 或 `xticklabels`、`yticklabels` 来调整标签的显示方式,或者使用交互式工具如 `plotly` 来增强用户体验。
---
## 📌 可选增强功能(如使用 Plotly)
如果你希望热力图具有交互性,可以使用 `plotly` 库:
```python
import plotly.express as px
import plotly.graph_objects as go
fig = go.Figure(data=go.Heatmap(
z=data.flatten(),
x=columns,
y=index,
colorscale='Viridis',
showscale=True,
text= df.values,
hoverinfo='text'
))
fig.update_layout(
title='Interactive Heatmap of Correlation Matrix',
xaxis_title='Variables',
yaxis_title='Features'
)
fig.write_image("correlation_heatmap.png", width=800, height=600)
fig.show()
```
---
## 📌 总结
热力图是一种非常直观的数据可视化工具,适用于展示二维数据的相关性、密度分布等。通过合理选择颜色映射、添加注释和
llm = "Qwen/Qwen3-8B"
# 英文
original_prompt = "Your task is to use Python and draw a heat map based on the data given by the user."
original_prompt = f"""Original prompt: {original_prompt}"""
optimized_prompt = get_completions1(system_instruction2, original_prompt, llm)
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
instruction_ = "You are an expert at world knowledge."
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
Original prompt: Your task is to use Python and draw a heat map based on the data given by the user.
Optimized prompt: Your task is to use Python to generate a heat map based on the data provided by the user. Please ensure that the heat map is visually clear and effectively represents the data's distribution or correlation. Use appropriate color schemes to highlight patterns, add axis labels, a title, and a legend (if applicable) to enhance interpretability. If the data includes multiple categories or variables, please structure the heat map accordingly. In addition, make sure to include any necessary data preprocessing steps and explain how the heat map helps in understanding the data. Finally, save the resulting heat map as an image file and provide the code used to generate it.
----------------------------------------------------------------------------------------------------
原始提示的生成结果:
Sure! I can help you create a heatmap using Python. To do that, I'll need the data you want to visualize. A heatmap typically represents data as a matrix of colors, where the color intensity corresponds to the value of the data.
Here are the steps I'll follow:
1. **Understand the data format**: Is it a 2D array or a table with rows and columns?
2. **Choose a library**: I'll use `matplotlib` and `seaborn` for creating heatmaps.
3. **Plot the heatmap**: Use `sns.heatmap()` or `plt.imshow()` with appropriate color mapping.
Please provide the data you'd like to use, and I'll generate the corresponding Python code to draw the heatmap. If you don't have data, I can also create a sample dataset for demonstration. Let me know how you'd like to proceed!
----------------------------------------------------------------------------------------------------
优化后的提示的生成结果:
Certainly! Below is a **Python script** that generates a **heat map** based on the data provided by the user. The script includes **data preprocessing**, **visualization with a clear layout**, **axis labels**, **title**, **legend**, and **color schemes** to highlight patterns. It also **saves the resulting heat map as an image file**.
---
### ✅ Assumptions:
- The user will provide a **2D dataset** (e.g., a matrix or a DataFrame) that can be visualized as a heatmap.
- The data may include **multiple categories or variables**, which will be handled by the script.
- The script will use **matplotlib** and **seaborn** for visualization.
---
### 📌 Example Data (for demonstration):
Let's assume the user provides a 2D array like this:
```python
import numpy as np
# Example data: a 5x5 matrix representing some kind of correlation or distribution
data = np.random.rand(5, 5)
```
---
### 🧠 Code to Generate Heat Map
```python
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Example data (replace this with the user's actual data)
data = np.random.rand(5, 5)
# Step 1: Data Preprocessing
# For demonstration, we'll assume the data is already in a suitable format.
# If the data is in a DataFrame, you can use it directly.
# Step 2: Generate Heat Map
plt.figure(figsize=(8, 6))
sns.heatmap(data, annot=True, fmt=".2f", cmap="viridis", cbar=True, square=True)
# Step 3: Add Labels and Title
plt.title("Heat Map of Data Distribution")
plt.xlabel("X-axis (Variables)")
plt.ylabel("Y-axis (Categories)")
# Step 4: Add Legend (if needed)
# If the data has a legend (e.g., categories), you can add it like this:
# plt.legend()
# Step 5: Save the Heat Map as an Image File
plt.savefig("heatmap.png", dpi=300, bbox_inches="tight")
# Step 6: Display the Heat Map
plt.show()
```
---
### 📝 Explanation of the Code
- **Data Preprocessing**: In this example, the data is a 5x5 matrix of random floats. If the user provides a different format (e.g., a CSV file or a DataFrame), the script can be adjusted accordingly.
- **Heat Map Generation**:
- `sns.heatmap()` is used to create the heatmap.
- `annot=True` adds the values to each cell.
- `fmt=".2f"` formats the values to two decimal places.
- `cmap="viridis"` is a good color scheme for readability and accessibility.
- `cbar=True` adds a color bar for reference.
- `square=True` ensures that the cells are square for better visual clarity.
- **Axis Labels and Title**: These help in understanding the context of the data.
- **Legend**: If the data includes multiple categories or variables, a legend can be added to clarify what each color or cell represents.
- **Saving the Image**: The heatmap is saved as a PNG file named `heatmap.png` with high resolution and proper bounding.
---
### 📌 How the Heat Map Helps in Understanding the Data
- A heatmap is useful for visualizing **correlation matrices**, **data distributions**, or **patterns in a 2D dataset**.
- It allows for **quick identification of high/low values** and **spatial relationships**.
- The **color gradient** helps in **highlighting trends** and **outliers**.
- **Annotations** make it easier to **read exact values** at a glance.
---
### 📌 Customization Tips
- If the user provides a **DataFrame**, you can pass it directly to `sns.heatmap()`:
```python
sns.heatmap(df.corr(), annot=True, cmap="coolwarm")
```
- For **categorical data**, you can use `sns.heatmap()` with `vmin`, `vmax`, and `cbar_kws` to adjust the color scale.
- You can also use **different color schemes** like `"Blues"`, `"Reds"`, `"YlGnBu"`, or `"PuOr"` depending on the data's nature.
---
### 📌 Output
The script will generate a **heat map** and save it as an image file named `heatmap.png`. You can open this file to view the heatmap.
---
### 📌 Final Notes
- Make sure to **install the required libraries** if not already installed:
```bash
pip install seaborn matplotlib pandas
```
- If the user has a **specific dataset** (e.g., CSV, Excel, or a custom matrix), the script can be modified to
2.2 示例 2
llm = "Qwen/Qwen3-8B"
original_prompt = "你的任务是将用户给定的中文翻译成英文。"
original_prompt = f"""原始提示:{original_prompt}"""
optimized_prompt = get_completions1(system_instruction1, original_prompt, llm)
instruction_ = "你是世界知识专家。"
content = """《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。\
它是一本面向有一定编程基础或实际项目(不一定是算法)经历,\
对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,\
旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。"""
original_prompt = original_prompt + "\n" + f"<text>{content}</text>"
optimized_prompt = optimized_prompt + "\n" + f"<text>{content}</text>"
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
原始提示:你的任务是将用户给定的中文翻译成英文。 <text>《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。它是一本面向有一定编程基础或实际项目(不一定是算法)经历,对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。</text> 优化后的提示: 请将以下中文文本准确、自然地翻译成英文,保持原意和语境不变。如果原文中包含专有名词、技术术语或文化特定表达,请确保使用合适的英文对应词汇或进行适当解释。此外,请注意英文句子的语法结构和表达习惯,使译文通顺、专业,并适合用于正式或学术场合。如果需要,你可以使用工具辅助翻译,但请优先保证翻译的准确性和地道性。最后,请将翻译结果以清晰的格式呈现,并在必要时提供中英文对照以便用户理解。 <text>《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。它是一本面向有一定编程基础或实际项目(不一定是算法)经历,对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。</text> ---------------------------------------------------------------------------------------------------- 原始提示的生成结果: The *Butterfly Book* aims to help readers lower the barrier and narrow the gap between applications and research, making large model application development more accessible. It is a book for learners who have some programming foundation or practical project experience (not necessarily in algorithms), are interested in ChatGPT (or similar models), and want to use related technologies to create new products or applications. The book focuses on utilizing the ChatGPT API to develop relevant applications. It hopes to spread the methods to more people and expects that new technological breakthroughs can improve the world we live in. ---------------------------------------------------------------------------------------------------- 优化后的提示的生成结果: 以下是您提供的中文文本的英文翻译,保持原意和语境不变,语言自然、专业,适合用于正式或学术场合: --- **English Translation:** *The Butterfly Book aims to lower the barrier for readers, bridging the gap between applications and research, making large model application development more accessible. It is a book for learners who have some programming foundation or practical project experience (not necessarily in algorithms), and who are interested in ChatGPT (or similar models) and wish to leverage related technologies to create new products or applications. The book focuses on using the ChatGPT API to develop relevant applications. It aspires to spread these methods to a broader audience and to enable new technological breakthroughs that can improve the world we live in.* --- **Chinese-English对照:** 《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。 *The Butterfly Book aims to lower the barrier for readers, bridging the gap between applications and research, making large model application development more accessible.* 它是一本面向有一定编程基础或实际项目(不一定是算法)经历,对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍, *It is a book for learners who have some programming foundation or practical project experience (not necessarily in algorithms), and who are interested in ChatGPT (or similar models) and wish to leverage related technologies to create new products or applications.* 旨在利用 ChatGPT API 开发相关应用。 *The book focuses on using the ChatGPT API to develop relevant applications.* 期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。 *It aspires to spread these methods to a broader audience and to enable new technological breakthroughs that can improve the world we live in.* --- 如需进一步润色或根据特定语境调整语气,请随时告知。
llm = "Qwen/Qwen3-8B"
original_prompt = "Your task is to translate the Chinese given by the user into English."
original_prompt = f"""Original prompt: {original_prompt}"""
optimized_prompt = get_completions2(system_instruction2, original_prompt, llm)
instruction_ = "You are an expert at world knowledge."
content = """《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。\
它是一本面向有一定编程基础或实际项目(不一定是算法)经历,\
对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,\
旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。"""
original_prompt = original_prompt + "\n" + f"<text>{content}</text>"
optimized_prompt = optimized_prompt + "\n" + f"<text>{content}</text>"
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
Original prompt: Your task is to translate the Chinese given by the user into English. <text>《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。它是一本面向有一定编程基础或实际项目(不一定是算法)经历,对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。</text> Optimized prompt: Please translate the following Chinese text accurately into English, ensuring that the meaning, tone, and context of the original are preserved. If the text contains idiomatic expressions, cultural references, or specific terminology, please provide appropriate translations that are natural and commonly understood in English. In addition, make sure that the translated sentences are grammatically correct, fluent, and maintain the original intent. If there are any ambiguous phrases, please clarify them in your translation and explain the reasoning behind your choices. <text>《蝴蝶书》力图帮助大家降低门槛,缩小应用程序和研究之间的差距,使得大模型应用开发变得触手可及。它是一本面向有一定编程基础或实际项目(不一定是算法)经历,对 ChatGPT(或类似模型)感兴趣、想利用相关技术做一些新产品或应用的学习者的书籍,旨在利用 ChatGPT API 开发相关应用。期望把方法传播给更多人,期望新技术的突破能够更多地改善我们所处的世界。</text> ---------------------------------------------------------------------------------------------------- 原始提示的生成结果: The "Butterfly Book" aims to help readers lower the entry barrier and narrow the gap between applications and research, making large model application development more accessible. It is a book for learners who have some programming foundation or practical project experience (not necessarily in algorithms), are interested in ChatGPT (or similar models), and want to leverage related technologies to create new products or applications. The book focuses on using the ChatGPT API to develop relevant applications. It hopes to spread these methods to more people and expects that new technological breakthroughs can improve our world more significantly. ---------------------------------------------------------------------------------------------------- 优化后的提示的生成结果: Here is the accurate and natural English translation of the provided Chinese text, preserving the original meaning, tone, and intent: --- **"The Butterfly Book" aims to lower the entry barrier and bridge the gap between applications and research, making large model application development more accessible. It is a book designed for learners who have some programming foundation or practical project experience (not necessarily in algorithms), and who are interested in ChatGPT (or similar models) and wish to leverage related technologies to create new products or applications. The book focuses on using the ChatGPT API to develop such applications. It hopes to spread the methodology to more people and expects that new technological breakthroughs can bring about greater improvements to the world we live in.** --- ### Explanation of Key Translation Choices: 1. **“降低门槛”** → **"lower the entry barrier"** - This is a common metaphor in English for making something more accessible or easier to start with. It conveys the idea of reducing the difficulty or complexity for newcomers. 2. **“缩小应用程序和研究之间的差距”** → **"bridge the gap between applications and research"** - "Bridge the gap" is a natural and idiomatic expression in English that effectively captures the idea of reducing the distance or difference between two areas. 3. **“触手可及”** → **"more accessible"** - This phrase is translated to maintain the meaning of something being easy to reach or use, without being too literal or awkward in English. 4. **“有一定编程基础或实际项目(不一定是算法)经历”** → **"some programming foundation or practical project experience (not necessarily in algorithms)"** - The parenthetical clarification is retained to ensure clarity, as it specifies that the project experience doesn't have to be in algorithm development. 5. **“想利用相关技术做一些新产品或应用”** → **"wish to leverage related technologies to create new products or applications"** - "Leverage" is a commonly used term in English for utilizing or making use of something effectively, especially in a technological or professional context. 6. **“期望把方法传播给更多人”** → **"hopes to spread the methodology to more people"** - This is a direct and natural translation, preserving the intent of sharing knowledge and techniques widely. 7. **“期望新技术的突破能够更多地改善我们所处的世界”** → **"expects that new technological breakthroughs can bring about greater improvements to the world we live in"** - The phrase is translated to maintain the hopeful and forward-looking tone, while using natural English expressions like "bring about greater improvements." --- This translation ensures that the original message is clear, professional, and culturally appropriate in English, while maintaining the intended audience and purpose of the book.
2.3 示例 3
llm = "Qwen/Qwen3-8B"
original_prompt = "你的任务是指导初学者系统地学习数据科学。"
original_prompt = f"""原始提示:{original_prompt}"""
optimized_prompt = get_completions1(system_instruction1, original_prompt, llm)
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
instruction_ = "你是世界知识专家。"
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
原始提示:你的任务是指导初学者系统地学习数据科学。 优化后的提示:你被要求为一个完全没有数据科学背景的初学者设计一个全面且结构化的学习路径。请描述一个循序渐进的学习计划,涵盖以下方面:首先,推荐适合初学者的数据科学入门教材、在线课程或资源;其次,明确列出学习过程中需要掌握的核心概念和技能,包括编程基础(如 Python)、数学知识(如统计学、线性代数)、数据分析工具(如 Pandas、NumPy)、数据可视化(如 Matplotlib、Seaborn)以及机器学习基础(如监督与非监督学习);最后,请提供一些实践建议,比如初学者可以通过哪些真实项目来应用所学知识,以及在学习过程中遇到困难时应如何有效寻求帮助和资源。请确保你的回答逻辑清晰、内容详实,并能帮助初学者建立扎实的数据科学基础,逐步提升其分析和解决问题的能力。 ---------------------------------------------------------------------------------------------------- 原始提示的生成结果: 当然!作为世界知识专家,我可以为你提供一个系统化的学习路径,帮助初学者逐步掌握数据科学的核心概念和技能。以下是为初学者设计的数据科学学习路线,分为几个阶段,涵盖理论、工具、实践和项目。 --- ## 🌟 一、数据科学概述(入门阶段) ### 1.1 什么是数据科学? - 数据科学是利用数据来发现知识、做出决策和预测未来的学科。 - 涉及领域包括统计学、机器学习、数据可视化、数据库管理、编程等。 ### 1.2 数据科学的应用场景 - 金融:风险评估、欺诈检测 - 医疗:疾病预测、药物研发 - 电商:用户行为分析、推荐系统 - 社交媒体:内容推荐、用户画像 - 交通:路线优化、交通预测 ### 1.3 学习资源推荐 - 书籍:《Python for Data Analysis》(Wes McKinney)、《Storytelling with Data》(Cole Nussbaumer Knack) - 在线课程:Coursera、edX、Udemy、Kaggle Learn - 网站:Kaggle、Towards Data Science、DataCamp、Medium --- ## 🧠 二、数学基础(核心阶段) ### 2.1 必备数学知识 - **统计学**:描述性统计、概率分布、假设检验、回归分析 - **线性代数**:向量、矩阵、特征值、奇异值分解 - **微积分**:导数、积分、梯度下降 - **优化理论**:凸优化、拉格朗日乘数法 - **概率论**:贝叶斯定理、条件概率、随机变量 ### 2.2 学习建议 - 从基础开始,逐步深入,不要一开始就追求高深理论。 - 推荐学习平台:Khan Academy、3Blue1Brown(YouTube)、MIT OpenCourseWare --- ## 🧪 三、编程基础(核心阶段) ### 3.1 推荐编程语言 - **Python**:数据科学的主流语言,拥有丰富的库(NumPy、Pandas、Scikit-learn、Matplotlib、Seaborn、TensorFlow、PyTorch) - **R**:统计分析的专用语言,适合初学者入门 - **SQL**:用于数据库查询和数据处理 ### 3.2 学习路径 1. **Python基础**:变量、数据类型、控制结构、函数、类、模块 2. **数据处理**:Pandas、NumPy、Matplotlib、Seaborn 3. **机器学习**:Scikit-learn、Keras、TensorFlow 4. **数据可视化**:Tableau、Power BI、Plotly、Bokeh 5. **数据库**:SQL、NoSQL(如MongoDB) ### 3.3 学习资源 - 书籍:《Python Crash Course》(Eric Matthes)、《Python for Data Analysis》 - 在线课程:Coursera的《Python for Everybody》、Udemy的《Python for Data Science and Machine Learning》 - 实践:使用Jupyter Notebook、Colab、Kaggle进行编程练习 --- ## 📊 四、数据处理与分析(进阶阶段) ### 4.1 数据清洗 - 处理缺失值、异常值、重复数据、数据格式转换 - 使用Pandas进行数据清洗 ### 4.2 数据探索 - 描述性统计、数据分布分析、相关性分析 - 使用Pandas和Matplotlib/Seaborn进行可视化 ### 4.3 数据分析 - 使用统计方法进行假设检验、回归分析、聚类分析 - 推荐工具:Pandas、NumPy、SciPy、Jupyter Notebook ### 4.4 学习资源 - 书籍:《Python for Data Analysis》、《Data Wrangling with Python》 - 在线课程:Coursera的《Data Science: R Basics》、Udemy的《Data Analysis with Python》 --- ## 🤖 五、机器学习(核心阶段) ### 5.1 机器学习基础 - 监督学习:分类、回归 - 无监督学习:聚类、降维 - 强化学习(可选) - 模型评估:准确率、精确率、召回率、F1分数、交叉验证 ### 5.2 学习路径 1. **基础算法**:线性回归、逻辑回归、KNN、决策树、随机森林、SVM、K-means 2. **模型调优**:超参数调优、正则化、交叉验证 3. ---------------------------------------------------------------------------------------------------- 优化后的提示的生成结果: 当然!以下是一个为**完全没有数据科学背景的初学者**设计的**全面且结构化的学习路径**,涵盖从基础知识到实际应用的各个阶段。这个计划旨在帮助你逐步建立扎实的数据科学基础,并提升分析和解决问题的能力。 --- ## 一、入门教材与学习资源推荐 ### 1.1 教材推荐(适合初学者) - **《Python for Data Analysis》 by Wes McKinney** 作者是Pandas的创始人,这本书是学习Python进行数据分析的绝佳入门书籍,适合零基础读者。 - **《Storytelling with Data》 by Cole Nussbaumer Knutson** 一本关于如何用数据讲故事的实用指南,适合初学者理解数据可视化的重要性。 - **《Data Science for Business》 by Foster Provost & Tom Fawcett** 从商业角度讲解数据科学,帮助你理解数据科学的实际应用场景。 - **《Introduction to Statistical Learning》 by Gareth James et al.** 一本适合初学者的统计学入门书,内容深入浅出,适合自学。 ### 1.2 在线课程推荐 - **Coursera - Data Science专项课程(Johns Hopkins University)** 由约翰霍普金斯大学开设,涵盖Python、R、统计学、数据可视化和机器学习,适合系统学习。 - **edX - Data Science and Machine Learning MicroMasters(MIT)** MIT的课程,内容专业,适合有志于深入学习数据科学的初学者。 - **Kaggle Learn** 提供免费的互动式课程,如Python、Pandas、机器学习等,适合边学边练。 - **Udemy - Python for Data Science and Machine Learning Bootcamp** 适合零基础,内容全面,包含大量练习和项目。 - **YouTube - Data School(by Henry Chen)** 提供免费的视频教程,适合喜欢视觉学习的初学者。 --- ## 二、核心概念与技能学习路径 ### 2.1 编程基础(Python) - **掌握基础语法**:变量、数据类型、条件语句、循环、函数、模块等。 - **学习Python环境**:安装Python、Jupyter Notebook、VS Code等工具。 - **掌握Python数据结构**:列表、字典、元组、集合、数组等。 - **学习Python文件操作**:读写CSV、Excel、JSON等常见数据格式。 - **掌握Python调试与版本控制**:使用print调试、Git进行代码管理。 ### 2.2 数学知识(统计学、线性代数) - **统计学基础**:均值、中位数、众数、方差、标准差、概率分布、假设检验、回归分析等。 - **线性代数基础**:向量、矩阵、行列式、逆矩阵、特征值、线性方程组等。 - **微积分基础**(可选):导数、积分、梯度下降等,对理解机器学习算法有帮助。 - **学习工具**:使用NumPy进行数值计算,使用SciPy进行科学计算。 ### 2.3 数据分析工具(Pandas、NumPy) - **Pandas**:数据清洗、数据筛选、数据合并、数据分组、数据透视等。 - **NumPy**:数组操作、数学运算、随机数生成、线性代数计算等。 - **学习工具**:使用Jupyter Notebook进行数据分析,使用Pandas的DataFrame和Series进行数据处理。 ### 2.4 数据可视化(Matplotlib、Seaborn) - **Matplotlib**:绘制折线图、柱状图、散点图、直方图、箱线图等。 - **Seaborn**:基于Matplotlib的高级可视化库,适合做统计图表。 - **学习工具**:使用Jupyter Notebook进行可视化,掌握图表定制和样式调整。 ### 2.5 机器学习基础(监督与非监督学习) - **监督学习**:线性回归、逻辑回归、决策树、随机森林、支持向量机(SVM)、K近邻(KNN)等。 - **非监督学习**:K均值聚类、层次聚类、主成分分析(PCA)、降维等。 - **学习工具**:使用Scikit-learn库进行模型训练和评估,了解交叉验证、过拟合、欠拟合等概念。 --- ## 三、实践建议与项目应用 ### 3.1 初学者可尝试的真实项目 - **Kaggle入门项目**:从Kaggle平台选择简单的数据集(如泰坦尼克号生存预测、房价预测等),尝试用Python进行数据清洗、分析和建模。 - **个人
llm = "Qwen/Qwen3-8B"
original_prompt = "Your task is to guide beginners through the systematic study of data science."
original_prompt = f"""Original prompt: {original_prompt}"""
optimized_prompt = get_completions1(system_instruction2, original_prompt, llm)
print(f"{original_prompt}\n")
print(f"{optimized_prompt}\n")
print("-" * 100)
instruction_ = "You are an expert at world knowledge."
result1 = get_completions2(instruction_, original_prompt, llm)
result2 = get_completions2(instruction_, optimized_prompt, llm)
print(f"原始提示的生成结果:\n{result1}\n")
print("-" * 100)
print(f"优化后的提示的生成结果:\n{result2}")Output
Original prompt: Your task is to guide beginners through the systematic study of data science. Optimized prompt: You have been asked to design a comprehensive and structured learning plan for beginners who are completely new to data science. Please outline the plan, including the following components: first, recommend beginner-friendly data science resources such as books, online courses, and tutorials that cover the foundational concepts; second, provide a step-by-step learning roadmap that progresses from basic skills like data manipulation and visualization to more advanced topics such as machine learning and statistical analysis; finally, suggest practical projects and exercises that beginners can undertake to apply their knowledge and gain hands-on experience. Make sure your plan is easy to follow, covers essential tools like Python, R, or SQL, and includes tips on how to seek help and stay motivated while learning. Also, emphasize the importance of problem-solving and real-world application in mastering data science. ---------------------------------------------------------------------------------------------------- 原始提示的生成结果: Absolutely! Here's a **systematic guide for beginners to study data science**, broken down into clear, structured steps to help you build a strong foundation and progress toward becoming a proficient data scientist. --- ## 🧭 Step 1: Understand What Data Science Is **Objective:** Gain a clear understanding of the field and its applications. ### What to Learn: - **Definition of Data Science:** Data science is the practice of extracting insights and knowledge from data using various tools and techniques. - **Key Areas:** Data collection, data cleaning, data analysis, data visualization, machine learning, and data storytelling. - **Applications:** Business analytics, healthcare, finance, marketing, social media, etc. - **Tools & Technologies:** Python, R, SQL, Tableau, Power BI, Jupyter Notebooks, etc. ### Resources: - Books: *Data Science for Business* by Foster Provost and Tom Fawcett - Online: [DataCamp](https://www.datacamp.com/), [Kaggle Learn](https://www.kaggle.com/learn), [Towards Data Science](https://towardsdatascience.com/) --- ## 📚 Step 2: Learn the Fundamentals of Programming **Objective:** Acquire basic programming skills, especially in Python. ### What to Learn: - **Python Basics:** Variables, data types, loops, conditionals, functions. - **Data Structures:** Lists, dictionaries, tuples, sets. - **Libraries:** NumPy, Pandas, Matplotlib, Seaborn, Scikit-learn. - **Version Control:** Git and GitHub (essential for collaboration and project management). ### Resources: - FreeCodeCamp: [Python for Everybody](https://www.freecodecamp.org/learn/python) - Coursera: [Python for Everybody Specialization](https://www.coursera.org/specializations/python) - Practice: Use [LeetCode](https://leetcode.com/) or [HackerRank](https://www.hackerrank.com/) for coding challenges. --- ## 📊 Step 3: Master Data Manipulation and Analysis **Objective:** Learn how to work with data using Python and other tools. ### What to Learn: - **Data Cleaning:** Handling missing data, removing duplicates, transforming data. - **Data Exploration:** Descriptive statistics, data visualization, and understanding patterns. - **Pandas:** Efficient data manipulation, filtering, and aggregation. - **SQL:** Querying databases, understanding relational data. ### Resources: - DataCamp: [Data Manipulation with pandas](https://www.datacamp.com/courses/data-manipulation-with-pandas) - Udemy: [Python for Data Science and Machine Learning](https://www.udemy.com/course/python-for-data-science-and-machine-learning-udemy/) - Practice: Use [Kaggle Datasets](https://www.kaggle.com/datasets) to work on real-world data. --- ## 📈 Step 4: Learn Data Visualization **Objective:** Communicate insights effectively through visualizations. ### What to Learn: - **Visualization Principles:** Choosing the right chart, color, and layout. - **Tools:** Matplotlib, Seaborn, Plotly, Tableau. - **Best Practices:** Clarity, simplicity, and storytelling in visualizations. ### Resources: - DataCamp: [Data Visualization with Python](https://www.datacamp.com/courses/data-visualization-with-python) - Towards Data Science: [Data Visualization Tutorials](https://towardsdatascience.com/data-visualization-tutorials-5c6d6d6d6d6d) - Practice: Visualize datasets from [Kaggle](https://www.kaggle.com/datasets) and share your work. --- ## 🧠 Step 5: Learn Statistics and Probability **Objective:** Understand the statistical foundations of data science. ### What to Learn: - **Descriptive Statistics:** Mean, median, mode, variance, standard deviation. - **Probability Distributions:** Normal, binomial, Poisson, etc. - **Inferential Statistics:** Hypothesis testing, confidence intervals, p-values. - **Correlation and Regression:** Understanding relationships between variables. ### Resources: - Khan Academy: [Statistics and Probability](https://www.khanacademy.org/math/statistics-probability) - Book: *Naked Statistics* by Charles Wheelan - Practice: Use statistical tools in Python (e.g., SciPy, Statsmodels) --- ## 🤖 Step 6: Introduction to Machine Learning **Objective:** Learn the basics of machine learning algorithms and how to apply them. ### What to Learn: - **Supervised vs. Unsupervised Learning:** Classification, regression, clustering, etc. - **Common Algorithms:** Linear Regression, Decision Trees, Random Forests, K-Nearest Neighbors, K-Means, etc. - **Model Evaluation:** Accuracy, precision, recall, F1 score, ROC curves. - ---------------------------------------------------------------------------------------------------- 优化后的提示的生成结果: Certainly! Here's a **comprehensive and structured learning plan** for **beginners completely new to data science**, designed to guide them from foundational knowledge to practical application. This plan includes **resources**, **roadmap**, **projects**, and **tips for success**. --- ## 📘 **I. Beginner-Friendly Data Science Resources** ### **Books** 1. **"Python for Data Analysis" by Wes McKinney** – A must-read for understanding pandas and data manipulation. 2. **"Storytelling with Data" by Cole Nussbaumer Knutson** – Focuses on data visualization and communication. 3. **"Data Science for Business" by Foster Provost and Tom Fawcett** – Introduces the business value of data science. 4. **"The Elements of Statistical Learning" by Trevor Hastie, Robert Tibshirani, and Jerome Friedman** – A more advanced book, but still accessible for beginners with a basic math background. 5. **"R for Data Science" by Hadley Wickham and Garrett Grolemund** – Great for learning R and its ecosystem for data analysis. ### **Online Courses** 1. **Coursera – "Data Science Specialization" by Johns Hopkins University** – A series of courses covering data science fundamentals, R, and Python. 2. **Udemy – "Python for Data Science and Machine Learning"** – Hands-on Python course with practical examples. 3. **edX – "Data Science and Machine Learning Fundamentals" by Microsoft** – Introductory course with a focus on real-world applications. 4. **Kaggle Learn – "Getting Started with Python" and "Intro to Machine Learning"** – Free, interactive courses with coding exercises. 5. **DataCamp – "Introduction to Data Science in Python"** – Interactive learning with real datasets. ### **Tutorials and Websites** 1. **Kaggle** – Offers datasets, notebooks, and community support for hands-on learning. 2. **Towards Data Science (Medium)** – A blog with beginner-friendly articles and tutorials. 3. **Dataquest** – Interactive learning platform with courses on data science and programming. 4. **FreeCodeCamp** – Free resources for learning Python, SQL, and data analysis. 5. **YouTube Channels** – - **StatQuest with Josh Starmer** – Fast-paced, clear explanations of statistical and machine learning concepts. - **Data School** – Tutorials on Python, R, and data science fundamentals. ### **Tools** - **Python**: Start with **Jupyter Notebook** for interactive coding. - **R**: Use **RStudio** for an integrated development environment. - **SQL**: Learn with **SQLZoo** or **Mode Analytics** for interactive SQL practice. --- ## 📌 **II. Step-by-Step Learning Roadmap** ### **Phase 1: Introduction to Data Science and Programming (Weeks 1–4)** - **Goal**: Understand the basics of data science and learn a programming language. - **Topics**: - Introduction to data science and its applications. - Basics of Python (syntax, variables, data types, control structures). - Introduction to Jupyter Notebook and Python libraries (NumPy, Pandas). - Introduction to R (if choosing R) or SQL (if choosing SQL). - **Resources**: - Coursera – "Data Science Specialization" (Week 1) - DataCamp – "Introduction to Data Science in Python" - FreeCodeCamp – "Python for Everybody" course ### **Phase 2: Data Manipulation and Cleaning (Weeks 5–8)** - **Goal**: Learn to work with real data and clean it for analysis. - **Topics**: - Data structures in Python (lists, dictionaries, DataFrames). - Data cleaning techniques (handling missing values, duplicates, outliers). - Data transformation and aggregation. - Introduction to SQL queries and databases. - **Resources**: - "Python for Data Analysis" by Wes McKinney - DataCamp – "Data Manipulation with pandas" - SQLZoo – "Learn SQL the Hard Way" ### **Phase 3: Data Visualization (Weeks 9–12)** - **Goal**: Learn to present data effectively using visual tools. - **Topics**: - Introduction to data visualization principles. - Using **Matplotlib** and **Seaborn** in Python. - Using **ggplot2** in R. - Creating charts, graphs, and dashboards. - **Resources**: - "Storytelling with Data" by Cole Nussbaumer Knutson - DataCamp – "Data Visualization with Python" - Towards Data Science – "Data Visualization in Python" series ### **Phase 4: Statistics and Probability (Weeks 13–16)** - **Goal**: Build a strong foundation in statistical concepts
三、总结与讨论
优化 ChatGPT 的 Prompts 对于提升交互体验和生成结果的质量非常重要。以下是一些主要的原因:
-
提高准确性:通过优化 Prompts,我们可以更准确地引导 ChatGPT 生成我们期望的回答。这对于获取准确、相关和有用的信息至关重要。
-
提高效率:优化的 Prompts 可以减少无效或者不相关的回答,从而提高交互的效率。
-
增强可控性:通过优化 Prompts,我们可以更好地控制 ChatGPT 的输出,使其更符合用户的需求和期望。
-
提升用户体验:优化的 Prompts 可以帮助 ChatGPT 更好地理解用户的需求,从而提供更满意的回答,提升用户体验。
总的来说,优化 Prompts 是提高 ChatGPT 性能和用户满意度的关键步骤。它有助于我们更好地利用提示工程(Prompt Engineering),为用户提供高质量的服务。
本章将介绍一个适用于 LLM 的优化提示工具。这个工具能够帮助你像 PromptPerfect 那样有效地优化提示,从而最大限度地发挥 LLM 的潜力,并获得更准确、与上下文相关的回答。
在实际应用中,为 LLM 提供的演示对于优化 Prompt 的性能具有重要意义。对于特定需求,如果手动构建优质的演示(成对的原始提示和优化后的提示)存在困难,我们可以利用一些商业化(非开源)的提示优化工具,如:PromptPerfect、百度千帆大模型操作台的 Prompt 优化、讯飞星火的指令优化等。这些商业工具通常进行了大量的工程优化,能够适应各种场景,满足用户的特定需求。
