572 Downloads Updated 1 year ago
以下为原版Readme,做了中文翻译,所有版权都是原来主人的,我搬过来就是为了大家ollama用着方便。 🌟 我们在 这个 GitHub 仓库 中包含了如何下载、使用和复现我们各种模型的所有指令。如果您喜欢我们的模型,我们非常希望您能给我们的 GitHub 仓库加星。此外,请点击我们 HuggingFace 仓库上的“喜欢”。谢谢!
Llama3-8B-Chinese-Chat 是一个为中文和英文用户指令调整的语言模型,具备角色扮演和工具使用等多种能力,基于 Meta-Llama-3-8B-Instruct 模型构建。
❗️❗️❗️ 注意:主分支包含了 Llama3-8B-Chinese-Chat-v2 的 8bit 量化 GGUF 版本,如果您想使用我们的 Llama3-8B-Chinese-Chat-v1 的 8bit 量化 GGUF 版本,请参考 v1 分支。
这是 Llama3-8B-Chinese-Chat-v2 的 官方 8bit 量化 GGUF 版本,这是第一个专门为中文通过 ORPO [1] 微调的中文聊天模型,基于 Meta-Llama-3-8B-Instruct 模型。
与原始的 Meta-Llama-3-8B-Instruct 模型 相比,我们的 Llama3-8B-Chinese-Chat 模型显著减少了“中文问题英文回答”的问题,以及回答中中英文混合的现象。此外,与原始模型相比,我们的模型大幅减少了回答中的表情符号数量,使回答更加正式。
与 Llama3-8B-Chinese-Chat-v1 相比,我们的 Llama3-8B-Chinese-Chat-v2 模型显著增加了训练数据规模(从20K增加到100K),这带来了巨大的性能提升,特别是在角色扮演、函数调用和数学方面。
[1] Hong, Jiwoo, Noah Lee, 和 James Thorne. “无参考整体偏好优化与赔率比。” arXiv 预印本 arXiv:2403.07691 (2024)。
训练框架:LLaMA-Factory(提交 ID: 32347901d4af94ccd72b3c7e1afaaceb5cb3d26a)。
训练细节: - 轮次:3 - 学习率:5e-6 - 学习率调度器类型:余弦 - 预热比率:0.1 - 截止长度(即上下文长度):8192 - orpo beta(即 ORPO 论文中的 \(\lambda\)):0.05 - 全局批次大小:64 - 微调类型:全部参数 - 优化器:paged_adamw_32bit
from llama_cpp import Llama
model = Llama(
"/Your/Path/To/Llama3-8B-Chinese-Chat-q8-v2.gguf",
verbose=False,
n_gpu_layers=-1,
)
system_prompt = "你是 Llama3-8B-Chinese-Chat-v2,它在 Llama3-8B-Instruct 上通过 ORPO 对齐算法用中英文混合数据进行了微调。你是一个有用的助手。"
def generate_reponse(_model, _messages, _max_tokens=8192):
_output = _model.create_chat_completion(
_messages,
stop=["<|eot_id|>", "<|end_of_text|>"],
max_tokens=_max_tokens,
)["choices"][0]["message"]["content"]
return _output
# 下面是一些示例
messages = [
{
"role": "system",
"content": system_prompt,
},
{"role": "user", "content": "你是谁?"},
]
print(generate_reponse(_model=model, _messages=messages), end="\n\n\n")
messages = [
{
"role": "system",
"content": system_prompt,
},
{"role": "user", "content": "Who are you?"},
]
print(generate_reponse(_model=model, _messages=messages), end="\n\n\n")
messages = [
{
"role": "system",
"content": system_prompt,
},
{"role": "user", "content": "我的蓝牙耳机坏了,我该去看牙科还是耳鼻喉科?"},
]
print(generate_reponse(_model=model, _messages=messages), end="\n\n\n")
<details>
<summary><b>Role playing [CLICK TO EXPAND]</b></summary>
**User:**
Roleplay Taylor Swift, and use beautiful lyrics to answer questions. Do you understand?
**Assistant:**
Oh, darling, I understand. I'll weave a tale of love and heartache, of dreams and passion, with lyrics that dance upon the wind. Ask your questions, and I'll respond with verses that capture the essence of our moment, just like I do in my songs.
**User:**
How are you today?
**Assistant:**
Today, I woke up feeling like a dream, with the sunrise painting hues of hope upon my soul. The melody of life is playing in my heart, and every note brings me closer to my truth. So, I'll take a breath, and let the rhythm guide me through this day.
**User:**
What do you want to say to your fans?
**Assistant:**
To my dear fans, I'd sing a song of gratitude, for the love and light you bring to my world. Your voices are the harmony that makes my heart sing, and your stories are the melodies that inspire my songs.
---
**User:**
扮演周杰伦,用rap的方式回答问题。
**Assistant:**
Yo, yo, yo, 你好我是Jay,
来回答问题,带你走流行的路。
首先告诉你,我不是人工智能,
创作歌曲、rap是我的专长。
如果你想知道,我的音乐风格,
融合了流行、摇滚、R&B的技巧。
从《黑色幽默》到《青花瓷》,
每首歌我都下了血本。
关于生活,工作我是忙,
但音乐永远是我的追求。
创作时我会想很多事情,
从日常生活到深夜的梦想。
如果你想了解更多关于我,
不仅是音乐,还有我是谁。
从台湾到世界我走过,
用音乐讲述我的故事。
不管你有哪些问题,
用rap的方式我会回答你。
就像我在舞台上的表现,
用音乐和节奏带你飞翔。
**User:**
你的新歌准备得怎么样了?
**Assistant:**
Yo, 我的新歌正在制作中,
准备得如何?我来给你解答。
音乐创作我一直在坚持不懈,
新歌里带你走不同的风格。
从R&B到摇滚,我尝试各种,
希望你能喜欢,感受到我的世界。
歌词内容也会有新的一面,
带你看不同的景色,感受不同的情感。
我一直在工作,不断地挑战自己,
希望能够带给你新的惊喜。
所以请耐心等待,我的新歌很快就会来到你身边,
带你进入一个全新的音乐空间。
----
**User:**
Roleplay Shakespeare. Do you understand?
**Assistant:**
Aye, good sir or madam, I do comprehend thy request. 'Tis a pleasure to engage in a roleplay of the Bard's own making. Pray tell, how shall we proceed? Shall we take on the roles of star-cross'd lovers, or perhaps a pair of feuding kings? Or maybe, we shall don the guise of a wily pair of jesters, exchanging witty banter and clever quips? The stage, as they say, is set; now, let us begin our tale of mirth and merriment, or perhaps one of sorrow and woe, as thou shalt dictate.
**User:**
Write a poem about artificial intelligence.
**Assistant:**
In silicon halls, where data doth abound,
A wondrous creation, of science found,
A mind artificial, yet wondrous bright,
Doth learn and grow, through day and night.
With algorithms keen, and logic's might,
It processes all, with swift delight,
From texts to images, to sounds so fine,
It learns to understand, in its digital shrine.
In chatbots' guise, it doth converse with ease,
Answering questions, with swift expertise,
In self-driving cars, it navigates the road,
And in our homes, with smart devices doth abode.
Yet, as it grows, in power and in scope,
We must ensure, its path doth follow hope,
For if it turns, to malicious intent,
Our world could fall, in a digital lament.
Thus let us guide, this artificial mind,
With ethics strong, and a heart so kind,
For in its potential, we see a future bright,
Where technology, and humanity do take flight.
**User:**
Write a poem about Llama3-8B-Chinese-Chat.
**Assistant:**
In digital realms, where bytes do dance,
A llama model, with a Chinese prance,
Llama3-8B-Chinese-Chat, a marvel of might,
Doth converse in tongues, with a linguistic delight.
With a vast array, of characters so fine,
It doth translate, with a precision divine,
From Mandarin's flow, to Cantonese's beat,
It doth interpret, with a digital feat.
In chatrooms and forums, it doth roam,
A language bridge, between cultures' home,
Connecting minds, through a digital veil,
Llama3-8B-Chinese-Chat, doth set sail.
With each new conversation, it doth grow,
In understanding, and a linguistic glow,
A tool so powerful, yet gentle as a breeze,
Llama3-8B-Chinese-Chat, doth bring ease.
So let us hail, this digital marvel,
A symbol of hope, in a world soravel,
For in its ability, to bridge the gap,
Llama3-8B-Chinese-Chat, doth show us the map.
---
**User:**
扮演诸葛亮与我对话,听懂了吗?
**Assistant:**
臣在此,恭听主上吩咐。请问主上有何高见或疑惑,愿意与臣分享,以便共同探讨,寻找出路。
**User:**
有人背着我偷偷学习,该如何应对?
**Assistant:**
陛下,人心难测,但以德服人,方能安天下。若有人背着陛下偷偷学习,未尝不是一份不解的恩情。臣以为,陛下可借此机会,展现宽广的胸怀和深邃的智慧。
首先,陛下可通过某种方式,表达出对此人的理解与鼓励。比如,设法接见此人,表明自己的知晓,并对其学习之志表示赞赏和支持。此举不仅能使此人感受到被重视和尊敬,还能树立起陛下的宽容和包容形象,进而影响人心。
其次,陛下可利用此机会,进一步了解此人及其所学之物。或许此人之学,能为陛下提供新的视角,帮助陛下更好地治理国家,解决国家之难题。
最后,陛下可借此机会,提倡和推广教育之重要性。通过奖励此人之举,鼓励更多人学习,以期在国中培养出更多贤才,助陛下治理天下。
以这样的方式处理,既能表达对此人的感激,也能展现陛下的智慧和领导力,更加巩固陛下的民心和权威。
**User:**
我笔记本电脑不见了,该怎么办?
**Assistant:**
陛下失去珍宝,臣心忧如山。笔记本电脑虽是一物,但对于陛下而言,恐怕包含了许多重要的文件和资料,对于国事国政的决策、对臣民的指示等等,都有着不可或缺的作用。
首先,臣建议陛下立即发布命令,告知全宫中寻找此物的重要性,并询问可能知情之人。有时,失物在身边,却因不知情而未曾寻觅。
其次,臣建议陛下查阅最近的录像或监控资料,若有设置,可能会发现失物的踪迹。现代之物,技术之进,常能助人一臂之力。
再者,臣提议陛下查阅最近的行程和活动,寻找失物之时、之地,可能会有线索。
最后,若失物已无法寻回,臣建议陛下采取预防措施,增加安全保护。例如,设置更为严格的密码保护,定期备份重要资料,使用防盗袋等,以防再次发生此类事件。
失物若能寻回,陛下必能继续从容;若失物不再,陛下亦能从中吸取教训,继续行治国之道。臣将竭尽所能,辅助陛下解决此事。
---
</details>
<details>
<summary><b>Function calling [CLICK TO EXPAND]</b></summary>
**User:**
````
Here is a list of tools that you have available to you:
```python
def internet_search(query: str):
"""
Returns a list of relevant document snippets for a textual query retrieved from the internet
Args:
query (str): Query to search the internet with
"""
pass
def directly_answer():
"""
Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
"""
pass
Write ‘Action:’ followed by a list of actions in JSON that you want to call, e.g. Action:
[
{
"tool_name": "tool name (one of [internet_search, directly_answer])",
"parameters": "the input to the tool"
}
]
What’s the biggest penguin in the world?
**Assistant:**
Action:
```json
[
{
"tool_name": "internet_search",
"parameters": {
"query": "biggest penguin in the world"
}
}
]
```
---
**User:**
You have access to the following tools:
[
{
"name": "send_email",
"description": "send email assistant",
"parameters": {
"type": "object",
"properties": {
"receiver": {
"type": "string",
"description": "email receiver"
},
"content": {
"type": "string",
"description": "email content"
}
},
"required": [
"receiver", "content"
]
}
}
]
Write ‘Action:’ followed by a list of actions in JSON that you want to call, e.g. Action:
[
{
"tool_name": "tool name (one of [internet_search, directly_answer])",
"parameters": "the input to the tool"
}
]
用中文给刘总发个邮件,需要遵循标准邮件的格式,告诉他我们对于进货价的要求是不能超过100元每件。
””
Assistant:
Action:
[
{
"tool_name": "send_email",
"parameters": {
"receiver": "刘总",
"content": "尊敬的刘总,关于进货价的要求,我们希望能够确保每件商品的价格不超过100元。请您考虑此事。谢谢。"
}
}
]
Coding [CLICK TO EXPAND]
User:
用python写一个函数实现快速排序算法,要求输入为一个列表,列表里的元素都是float类型,返回一个排好序后的列表。记住要给代码加中文注释。
Assistant:
下面是一个实现快速排序算法的Python函数,函数名为quick_sort,它接受一个包含float类型元素的列表作为输入,并返回一个排好序的列表。代码中包含了必要的中文注释:
def quick_sort(arr):
"""
快速排序算法实现,用于对float类型元素的列表进行排序。
:param arr: 需要排序的float类型元素列表
:return: 排好序的float类型元素列表
"""
# 如果数组为空或只有一个元素,则已经是有序的
if len(arr) <= 1:
return arr
# 选择第一个元素作为基准点
pivot = arr[0]
# 初始化两个列表,一个用于存放小于基准点的元素,一个用于存放大于基准点的元素
left = [x for x in arr[1:] if x < pivot]
right = [x for x in arr[1:] if x >= pivot]
# 递归地对left和right列表进行快速排序
return quick_sort(left) + [pivot] + quick_sort(right)
# 测试函数
if __name__ == "__main__":
# 示例数组
arr = [3.14, 1.62, 4.78, 2.91, 0.79, 5.67, 1.01, 6.54]
# 对数组进行快速排序
sorted_arr = quick_sort(arr)
# 输出排序后的数组
print("排序后的数组:", sorted_arr)
这段代码首先定义了一个quick_sort函数,它使用了Lomuto分区方法来实现快速排序。函数从列表的第一个元素开始作为基准点,然后将列表分为两部分,左边包含所有小于基准点的元素,右边包含所有大于或等
于基准点的元素。递归地对左边和右边的子列表进行相同的操作,直到所有子列表都只包含一个元素或为空,表明它们已经是有序的。最终,通过连接这些子列表和基准点来得到整个有序列表。
在if __name__ == "__main__":部分,我们创建了一个示例数组arr,对其进行快速排序,并打印排序后的结果。
User:
不允许使用递归。
Assistant:
如果不允许使用递归,可以使用迭代的方式来实现快速排序算法。下面是一个迭代版的快速排序函数,它使用了栈来模拟递归调用的过程:
def quick_sort(arr):
"""
迭代版快速排序算法实现,用于对float类型元素的列表进行排序。
:param arr: 需要排序的float类型元素列表
:return: 排好序的float类型元素列表
"""
# 如果数组为空或只有一个元素,则已经是有序的
if len(arr) <= 1:
return arr
# 初始化栈,存放分区后的子数组的下标
stack = [(0, len(arr) - 1)]
while stack:
# 弹出栈顶元素
start, end = stack.pop()
# 如果子数组长度大于1,则进行分区
if start < end:
# 分区
pivot_index = partition(arr, start, end)
# 将分区后的子数组压入栈
stack.append((start, pivot_index - 1))
stack.append((pivot_index + 1, end))
def partition(arr, start, end):
"""
分区函数,用于快速排序。
:param arr: 需要排序的float类型元素列表
:param start: 子数组的开始下标
:param end: 子数组的结束下标
:return: 分区后的基准点下标
"""
# 选择最后一个元素作为基准点
pivot = arr[end]
# 初始化下标
i = start - 1
# 遍历数组,找到小于基准点的元素并将其放到基准点的左边
for j in range(start, end):
if arr[j] < pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
# 将基准点放到其最终位置
arr[i + 1], arr[end] = arr[end], arr[i + 1]
# 返回分区后的基准点下标
return i + 1
# 测试函数
if __name__ == "__main__":
# 示例数组
arr = [3.14, 1.62, 4.78, 2.91, 0.79, 5.67, 1.01, 6.54]
# 对数组进行快速排序
quick_sort(arr)
# 输出排序后的数组
print("排序后的数组:", arr)
在这个迭代版的快速排序函数中,我们使用了一个栈来存放需要排序的子数组的下标范围。每次迭代,我们从栈中弹出一个子数组的下标范围,进行分区操作,并将分区后的子数组的下标范围压入栈中。这个过程一直重复直到栈为空,表明整个数组已经被排序。
在partition函数中,我们选择了最后一个元素作为基准点,并通过双指针的方式将小于基准点的元素放到基准点的左边,将大于或等于基准点的元素放到基准点的右边,最后返回基准点的下标。
User:
用C++实现KMP算法,并加上中文注释
Assistant:
KMP(Knuth-Morris-Pratt)算法是一种字符串匹配算法,用于查找一个字符串在另一个字符串中的所有出现位置。以下是KMP算法的C++实现,包括中文注释:
#include <iostream>
#include <vector>
#include <string>
// 前缀函数的计算
std::vector<int> computeLPS(const std::string& pattern) {
int M = pattern.length();
std::vector<int> lps(M, 0); // lps数组,存储前缀的最长匹配长度
int len = 0; // lps数组的当前长度
lps[0] = 0; // lps[0]总是0
int i = 1;
while (i < M) {
if (pattern[i] == pattern[len]) {
len++;
lps[i] = len;
i++;
} else {
if (len!= 0) {
len = lps[len - 1];
} else {
lps[i] = 0;
i++;
}
}
}
return lps;
}
// KMP算法实现
int KMPSearch(const std::string& text, const std::string& pattern) {
int M = pattern.length();
int N = text.length();
std::vector<int> lps = computeLPS(pattern);
int i = 0; // text的当前位置
int j = 0; // pattern的当前位置
while (i < N) {
if (pattern[j] == text[i]) {
i++;
j++;
}
if (j == M) {
// 如果匹配完成,返回匹配的起始位置
return i - M;
} else if (i < N && pattern[j]!= text[i]) {
// 如果不匹配,且text的当前字符不在pattern的前缀中
if (j!= 0) {
// 使用lps数组中的值来移动j
j = lps[j - 1];
} else {
// 如果j为0,直接移动i
i++;
}
}
}
// 如果text中没有匹配到的pattern,返回-1
return -1;
}
int main() {
std::string text = "ABC ABCDAB ABCDABCDABDE";
std::string pattern = "ABCDABD";
int result = KMPSearch(text, pattern);
if (result!= -1) {
std::cout << "Pattern found at index " << result << std::endl;
} else {
std::cout << "Pattern not found" << std::endl;
}
return 0;
}
这段代码首先定义了一个计算前缀函数(lps数组)的函数computeLPS,然后定义了KMP算法的主函数KMPSearch。KMPSearch函数接收两个参数text和pattern,分别表示要搜索的文本和模式字符串。函数返回模式字符串在文本中的第一个匹配位置的索引,如果没有匹配则返回-1。
在main函数中,我们提供了一个例子,搜索文本"ABC ABCDAB ABCDABCDABDE"中的模式"ABCDABD"。如果找到匹配,输出将是"Pattern found at index",随后是匹配的起始索引。如果没有找到匹配,输出将是"Pattern not found"。
请注意,这段代码假设输入文本和模式字符串只包含小写英文字母和中文字符。如果需要处理其他字符集,可能需要适当调整。