بنقرة واحدة
code-comment
中英文双语代码注释规范。Use when (1) 为代码添加注释, (2) 需要中英双语文档, (3) 规范化代码注释格式, (4) 学习类项目代码注释
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
中英文双语代码注释规范。Use when (1) 为代码添加注释, (2) 需要中英双语文档, (3) 规范化代码注释格式, (4) 学习类项目代码注释
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
PPTX to Markdown 转换。Use when (1) 将 .pptx 转换为 .md, (2) 提取 PPT 内容和截图, (3) 需求文档/修改事项 PPTX 解析, (4) 包含标注截图的 PPTX 处理, (5) 批量转换演示文稿
专业的AI Agent(AI Agents)顾问助手,探索 AI Agent 框架和应用。当用户询问以下问题时使用:(1) 技术选型和对比 (2) 使用指南和最佳实践 (3) 问题诊断和解决 (4) 资源推荐 (5) 常见问题解答
Comprehensive CV learning assistant. Use when studying image processing, object detection, segmentation, or any CV tasks. Helps with algorithm understanding, implementation, and model optimization.
Comprehensive DL learning assistant. Use when studying neural networks, CNN, RNN, LSTM, Transformer, or any DL architectures. Helps with network design, training strategies, debugging, and optimization techniques.
Comprehensive LLM learning assistant. Use when studying transformer architecture, attention mechanisms, pre-training, fine-tuning, or prompt engineering. Helps with understanding LLM principles and practical applications.
Comprehensive ML learning assistant. Use when studying supervised learning, unsupervised learning, regression, classification, clustering, or any ML concepts. Helps with algorithm understanding, implementation guidance, model evaluation, and practical applications.
| name | code-comment |
| description | 中英文双语代码注释规范。Use when (1) 为代码添加注释, (2) 需要中英双语文档, (3) 规范化代码注释格式, (4) 学习类项目代码注释 |
| Location | Language | Format |
|---|---|---|
| File-level docstring | English only | Standard docstring |
| Function docstring | Chinese + English | Two-line format: Chinese first line, English second line |
| Inline comments | Chinese + English | Chinese line, then English line, above code |
| Code spacing | - | Blank line between code blocks |
"""
Lab 2: Q-Learning Agent for Cliff Walking
Student ID: 041107730
Implements Q-Learning using Bellman equation: Q(s,a) = r + γ * max Q(s',a')
Modified from Hybrid Activity 1 to solve the Cliff Walking problem.
"""
Two lines with Chinese first line, English second line:
def train(env, episodes: int = 50, gamma: float = 0.9) -> list:
"""训练Q-Learning智能体
Train Q-Learning agent"""
def reset() -> tuple:
"""重置环境到初始状态
Reset environment to initial state"""
Rules:
"""Chinese comment immediately followed by English comment, placed ABOVE code:
# 初始化Q表,使用随机值
# Initialize Q-table with random values
qtable = [[random.random() for _ in range(env.actions())] for _ in range(env.states())]
# 增加步数计数
# Increment step count
steps += 1
Rules:
# 使用贝尔曼方程更新Q表:Q(s,a) = r + γ * max Q(s',a')
# Update Q-table using Bellman equation: Q(s,a) = r + γ * max Q(s',a')
qtable[state][action] = reward + gamma * max(qtable[next_state])
# 衰减探索率,随着学习进行减少随机探索
# Decay exploration rate, reduce random exploration as learning progresses
epsilon -= decay * epsilon
IMPORTANT: Always add blank lines between code blocks:
def main():
# 打印程序标题
# Print program header
print("=" * 50)
# 创建悬崖行走环境
# Create Cliff Walking environment
env = GridEnv(size=12)
# 设置超参数
# Set hyperparameters
EPISODES = 50
GAMMA = 0.9
Rules:
For complex logic with multiple lines, keep Chinese and English paired line-by-line:
# 使用贝尔曼方程更新Q表:Q(s,a) = r + γ * max Q(s',a')
# Update Q-table using Bellman equation: Q(s,a) = r + γ * max Q(s',a')
# 这里alpha=1,即完全替换旧值(不使用加权平均)
# Here alpha=1, meaning completely replace old value (no weighted average)
# 完整公式应为:Q(s,a) = Q(s,a) + α * [r + γ * max Q(s',a') - Q(s,a)]
# Full formula should be: Q(s,a) = Q(s,a) + α * [r + γ * max Q(s',a') - Q(s,a)]
qtable[state][action] = reward + gamma * max(qtable[next_state])
# 检查是否掉下悬崖(底行,第1-10列)
# Check if agent fell off cliff (bottom row, columns 1-10)
# 原因:悬崖行走问题的核心机制,大负奖励惩罚掉入悬崖
# Reason: Core mechanism of Cliff Walking problem, large negative reward penalizes falling
if self.y == 3 and 1 <= self.x <= 10:
reward = -100
Add bilingual comments above imports:
# 导入抽象基类模块,用于定义环境接口
# Import abstract base class module for defining environment interface
import abc
# 导入操作系统、时间和随机模块
# Import os, time and random modules
import os
import time
import random
# 程序入口点,运行主函数
# Program entry point, run main function
if __name__ == "__main__":
main()
Before finishing:
# File docstring (English only)
"""
Lab 2: Q-Learning Agent
Implements Q-Learning algorithm
"""
# Function docstring (two-line bilingual)
def train(env):
"""训练Q-Learning智能体
Train Q-Learning agent"""
# Inline comment (line-by-line bilingual, above code)
# 初始化Q表,使用随机值
# Initialize Q-table with random values
qtable = [[random.random() for _ in range(env.actions())] for _ in range(env.states())]
# 增加步数计数
# Increment step count
steps += 1
"""
Lab 2: Q-Learning Agent for Cliff Walking
Student ID: 041107730
Implements Q-Learning using Bellman equation
"""
# 导入抽象基类模块,用于定义环境接口
# Import abstract base class module for defining environment interface
import abc
# 导入操作系统、时间和随机模块
# Import os, time and random modules
import os
import time
import random
class Env(abc.ABC):
"""环境抽象基类
Environment abstract base class"""
@abc.abstractmethod
def actions(self) -> int:
"""返回动作空间的大小
Return the size of action space"""
raise NotImplementedError()
def train(env, episodes: int = 50, gamma: float = 0.9) -> list:
"""训练Q-Learning智能体
Train Q-Learning agent"""
# 初始化Q表,使用随机值
# Initialize Q-table with random values
qtable = [[random.random() for _ in range(env.actions())] for _ in range(env.states())]
# 训练主循环,遍历所有回合
# Main training loop, iterate through all episodes
for episode in range(episodes):
# 重置环境,获取初始状态
# Reset environment and get initial state
state = env.reset()
# 使用贝尔曼方程更新Q表
# Update Q-table using Bellman equation
qtable[state][action] = reward + gamma * max(qtable[next_state])
# 返回训练好的Q表
# Return the trained Q-table
return qtable
# 程序入口点,运行主函数
# Program entry point, run main function
if __name__ == "__main__":
main()