diff --git a/README.md b/README.md index 6434464..aaf0bd9 100644 --- a/README.md +++ b/README.md @@ -170,268 +170,44 @@ MiniCPM 模型权重对学术研究完全开放。如需将模型用于商业用 #### 代码生成 Case 1: -``` - <用户>: 给这段代码逐行加上注释\n#include \nint rabbit(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n} else {\nreturn rabbit(n - 1) + rabbit(n - 2);\n}\n}\nint main() {\nint n;\nfor(n=1;n<41;n++){\n printf(\"第%d个月时有%d对兔子\\n\", n, rabbit(n));\n}\nreturn 0;\n} - : - 以下是包含详细注释的代码: - - ```c - // 引入标准输入输出库 - #include - - // 定义一个递归函数,计算第n个月有多少对兔子 - int rabbit(int n) { - // 如果n等于1或2,说明是第一个月或第二个月,此时有1对兔子 - if (n == 1 || n == 2) { - return 1; - } - // 否则,递归调用自身,计算前一个月和上个月兔子数量之和 - else { - return rabbit(n - 1) + rabbit(n - 2); - } - } - - // 主函数 - int main() { - int n; - - // 从1开始循环到第40个月 - for(n=1; n<41; n++) { - // 输出当前月的编号和对应的兔子对数 - printf("第%d个月时有%d对兔子\n", n, rabbit(n)); - } - - return 0; - } - ``` - - 这段代码首先定义了一个名为`rabbit`的递归函数,用于计算第n个月有多少对兔子。在主函数中,我们使用一个for循环从1遍历到第40个月,并调用`rabbit`函数来计算每个月的兔子对数,并使用`printf`函数输出结果。 -``` +![代码生成-case1](./assets/code.case1.gif) + Case 2: -``` - <用户>: 编写一个Python程序来实现一个MiniCPM模型(Transformer结构, 40层,每层维度为2304, 词表大小为122753)。 - : - Mini-CPM(Mini-Contrastive Pretraining)模型是一种基于Transformer结构的自然语言处理模型。它使用自注意力机制和多层编码器-解码器结构来学习序列到序列的转换任务。在实现Mini-CPM模型时,我们需要遵循以下步骤: - - 1. 导入所需库 - 2. 定义模型结构 - 3. 训练模型 - 4. 测试模型 - - 以下是实现Mini-CPM模型的Python代码: - - ```python - import torch - import torch.nn as nn - from torch.autograd import Variable - - class MiniCpmModel(nn.Module): - def __init__(self, vocab_size, d_model, num_layers, dropout=0.1): - super(MiniCpmModel, self).__init__() - self.vocab_size = vocab_size - self.d_model = d_model - self.num_layers = num_layers - self.dropout = dropout - - # 自注意力层 - self.self_attn = nn.SelfAttention(d_model, dropout=dropout) - self.attn_layer = nn.TransformerEncoderLayer(d_model, num_layers, dropout=dropout) - self.transformer_encoder = nn.TransformerEncoder(self.attn_layer, num_layers) - - # 全连接层 - self.fc = nn.Linear(d_model * 8, vocab_size) - - def forward(self, x): - x = self.self_attn(x) - x = x.view(x.size(0), -1) - x = self.transformer_encoder(x) - x = self.fc(x) - return x - - def train_mini_cpm(model, device, train_loader, optimizer, epochs): - model.train() - for epoch in range(epochs): - for i, (text, target) in enumerate(train_loader): - text = text.to(device) - target = target.to(device) - - optimizer.zero_grad() - output = model(text) - loss = nn.CrossEntropyLoss()(output, target) - loss.backward() - optimizer.step() - - def test_mini_cpm(model, device, test_loader): - model.eval() - correct = 0 - total = 0 - with torch.no_grad(): - for text, target in test_loader: - text = text.to(device) - target = target.to(device) - output = model(text) - _, predicted = torch.max(output, 1) - total += target.size(0) - correct += (predicted == target).sum().item() - - print(f'Test Accuracy: {100 * correct / total}%') - - if __name__ == "__main__": - # 参数设置 - vocab_size = 122753 - d_model = 2304 - num_layers = 40 - dropout = 0.1 - - # 初始化模型 - device = torch.device("cuda" if torch.cuda.is_available() else "cpu") - model = MiniCpmModel(vocab_size, d_model, num_layers, dropout).to(device) - - # 训练模型 - optimizer = torch.optim.Adam(model.parameters(), lr=1e-5) - epochs = 10 - train_mini_cpm(model, device, train_data, optimizer, epochs) - - # 测试模型 - test_mini_cpm(model, device, test_data) - ``` - - 请注意,您需要将`train_data`和`test_data`替换为您的训练和测试数据。同时,您需要准备包含文本和目标标签的数据集。 -``` +![代码生成-case2](./assets/code.case2.gif) #### 数理逻辑 Case 1: -``` - <用户>: 直接给出以下算式的计算结果15 + 25 + 33 + 22 + 9= - : - 15 + 25 + 33 + 22 + 9 = 104 - - 结果是104。 -``` +![数理逻辑-case1](./assets/math.case1.png) + Case 2: -``` - <用户>: 如果以下算式中减号均表示加号,而加号实际上是减号,给出算式的计算结果15 - 25 - 12 + 34= - : - 如果在算式中将减号表示为加号,并且加号实际上表示减号,那么算式将变为: - 15 + 25 + 12 - 34 - - 按照数学运算的优先级(先乘除后加减),我们首先计算括号内的加法: - 15 + 25 = 40 - 40 + 12 = 52 - - 然后,我们进行减法操作: - 52 - 34 = 18 - - 所以,原算式的计算结果仍然是 18。 -``` +![数理逻辑-case1](./assets/math.case2.png) + #### 知识推理 Case 1: -``` - <用户>: 山东省最高的山是哪座山, 它比黄山高还是矮?差距多少? - : - 山东省最高的山是泰山,海拔1545米。黄山位于中国安徽省,海拔1864米。从海拔上来看,黄山比泰山高。两者之间的差距为: - - 黄山 - 泰山 = 319米 - - 请注意,这个数据可能随着气候变化和测量方法的变化而有所变化。 -``` -Case 2: +![知识推理-case1](./assets/knowledge.case1.png) #### 内容创作 Case 1: -``` - <用户>: 晚上睡不着,可以写哪些简短高级的朋友圈文案? - : - 1. "夜深人静,思绪万千。愿此刻的宁静,能驱散心中的纷扰。" - 2. "夜幕降临,星光闪烁。在这宁静的时刻,愿我的心灵得到片刻的慰藉。" - 3. "月光如水,洒满窗台。此刻的我,只想静静聆听内心的声音。" - 4. "繁星点点,照亮了黑暗。今晚的星空,让我感受到无尽的希望与力量。" - 5. "夜深人静,独享这宁静的时光。愿所有的烦恼都能随风而逝,留下美好的回忆。" - 6. "夜色渐浓,思念渐深。愿这份思念,能温暖我孤独的心房。" - 7. "月光如水,洒满心间。在这宁静的夜晚,愿我能找到内心的安宁与平静。" - 8. "夜深人静,独自品味生活的酸甜苦辣。愿每一个经历,都能成为成长的养分。" - 9. "月光如诗,诗意如画。在这宁静的夜晚,愿我能感受到生活的美好与温馨。" - 10. "夜深人静,倾听内心的呼唤。愿我能在这宁静的时刻,找到心灵的归宿。" -``` -Case 2: -``` - -``` +![内容创作-case1](./assets/creation.case1.png) #### 文本翻译 Case 1: -``` - <用户>: Translate this sentence into Russian: '如何用Python创建一个简单的网页爬虫?'. - : - 'Как создать простый скрипт для собирания страниц в скрипте Python?' -``` +![文本翻译-case1](./assets/translation.case1.png) + Case 2: -``` - <用户>: Translate this sentence into French: "I am a fresh man on Chinese, do you know how this sentence is translated: 如何用Python创建一个简单的网页爬虫?" - : - Je suis un nouveau-né en chinois, sais-tu comment on crée un simple web scraper en Python ? - - Note : Voici la traduction en français de la phrase originale : "How to create a simple web crawler in Python". -``` +![文本翻译-case1](./assets/translation.case2.png) #### 指令跟随 Case 1: -``` - <用户>: 请帮小明写一份东京旅游的游记,要求每一句话以“哇太好玩了!”开头。 - : - 哇太好玩了!第一天,我们抵达了东京的成田国际机场。哇太壮观了!机场内的设施和服务都让我惊叹不已。 - - 哇太兴奋了!我们搭乘高速列车前往东京站,准备开始我们的旅程。哇太刺激了!列车穿行在城市的上空,让我们感受到了日本的现代科技。 - - 哇太兴奋了!我们抵达了东京塔,这座标志性的建筑给我们留下了深刻的印象。哇太壮观了!从塔顶俯瞰整个城市,景色美不胜收。 - - 哇太好玩了!我们在浅草寺参观,感受到了日本传统文化的魅力。哇太神奇了!寺庙内的神像和佛像让我们感受到了宗教的力量。 - - 哇太好玩了!我们去了东京迪士尼乐园,这里充满了欢声笑语和快乐。哇太梦幻了!我们乘坐了各种游乐设施,体验了不同的游戏和表演。 - - 哇太好玩了!我们还去了东京迪士尼海洋,这里有更多的海洋主题景点和表演。哇太精彩了!我们欣赏了精彩的烟花表演,结束了这个美好的夜晚。 - - 哇太好玩了!我们的东京之旅结束了,但留下了许多美好的回忆。我们学到了很多关于日本文化和历史的知识,也体验了日本的美食和娱乐。这次旅行真是太棒了! -``` +![指令跟随-case1](./assets/instruction_following.case1.png) + Case 2: - ``` - <用户>: 给我一个藏头(“雪碧”)的春联, 分别按顺序给出上联(七个字),下联(七个字),横批。 - : - 以下是符合要求的藏头春联: - - 上联:雪消冰释瑞气来 - 下联:碧海青天春意浓 - 横批:瑞雪兆丰年 -``` +![指令跟随-case1](./assets/instruction_following.case2.png) #### 特殊字符 Case 1: -``` - <用户>: 请给以下句子加上emoji让它更生动: 亲爱的妻子:今天是你的生日,请收下我的蛋糕和玫瑰。 - : - 亲爱的妻子:🎉今天是你的生日,💖请收下我的蛋糕🎂和玫瑰花🌹。 - - (注:emoji需要根据具体语言环境进行替换,以下仅作示例展示) -``` -Case 2: -``` - <用户>: 请给我一个json, 每个key是一个emoji,每个value是这个emoji对应的意思,给出10个左右 - : - 以下是一个包含10个emoji及其对应意义的JSON对象: - ```json - { - "😊": "表示满意和喜悦", - "😡": "表示愤怒或不满", - "🤣": "表示搞笑的跌倒动作,代表轻松和幽默", - "🚀": "表示兴奋和期待,通常与太空探索相关", - "💡": "表示光亮和智慧,代表新想法或创意", - "💤": "表示休息和放松,通常用于结束对话", - "🌟": "表示成就和优秀,代表成功和激励", - "🌱": "表示成长和发展,代表进步和积极变化", - "🦋": "表示自然和生命的循环,代表希望和重生", - "👥": "表示人与人之间的联系和团结,代表友谊和支持" - } - ``` -``` +![指令跟随-case1](./assets/instruction_following.case3.png) +Case 2: +![指令跟随-case1](./assets/instruction_following.case4.png) diff --git a/assets/code.case1.gif b/assets/code.case1.gif new file mode 100644 index 0000000..2218ed6 Binary files /dev/null and b/assets/code.case1.gif differ diff --git a/assets/code.case2.gif b/assets/code.case2.gif new file mode 100644 index 0000000..f0a036c Binary files /dev/null and b/assets/code.case2.gif differ diff --git a/assets/creation.case1.png b/assets/creation.case1.png new file mode 100644 index 0000000..e4a7b1c Binary files /dev/null and b/assets/creation.case1.png differ diff --git a/assets/instruction_following.case1.png b/assets/instruction_following.case1.png new file mode 100644 index 0000000..43229e9 Binary files /dev/null and b/assets/instruction_following.case1.png differ diff --git a/assets/instruction_following.case2.png b/assets/instruction_following.case2.png new file mode 100644 index 0000000..8f3c146 Binary files /dev/null and b/assets/instruction_following.case2.png differ diff --git a/assets/instruction_following.case3.png b/assets/instruction_following.case3.png new file mode 100644 index 0000000..e8ddd65 Binary files /dev/null and b/assets/instruction_following.case3.png differ diff --git a/assets/instruction_following.case4.png b/assets/instruction_following.case4.png new file mode 100644 index 0000000..91495ca Binary files /dev/null and b/assets/instruction_following.case4.png differ diff --git a/assets/knowledge.case1.png b/assets/knowledge.case1.png new file mode 100644 index 0000000..bbe6f7b Binary files /dev/null and b/assets/knowledge.case1.png differ diff --git a/assets/math.case1.png b/assets/math.case1.png new file mode 100644 index 0000000..61bb4e9 Binary files /dev/null and b/assets/math.case1.png differ diff --git a/assets/math.case2.png b/assets/math.case2.png new file mode 100644 index 0000000..4b4c219 Binary files /dev/null and b/assets/math.case2.png differ diff --git a/assets/translation.case1.png b/assets/translation.case1.png new file mode 100644 index 0000000..abfe181 Binary files /dev/null and b/assets/translation.case1.png differ diff --git a/assets/translation.case2.png b/assets/translation.case2.png new file mode 100644 index 0000000..b81d414 Binary files /dev/null and b/assets/translation.case2.png differ