File size: 2,069 Bytes
0302dc1
 
 
7af3cba
3b07e88
7af3cba
0302dc1
3b07e88
7af3cba
0302dc1
3b07e88
 
 
 
e691084
3b07e88
 
92027f3
3b07e88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92027f3
7b67d5f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
license: apache-2.0
---
## 藏文心理健康支持对话数据集(Tibetan_Mental)与大模型(Tibetan_Mental_Chat)
### 一、本文的训练流程主要包含:
- 对Llama 2 进行藏文词表扩充,词表由32000 扩展至56724,提高模型在藏文的编解码效率。在TibetanGeneralCorpus 上使用Sentencepiece 工具训练基于Unigram 策略的藏文分词器。生成的词表与原版Llama 2 的32K 词表进行合并,排除重复的词 元后,得到扩充后词表规模为56724。用15G 的TibetanGeneralCorpus 和20G 的英、中混合文本进行CPT,采用自回归任务。

### 二、通过心理健康领域的藏文指令数据集进行了QLoRA微调:
- 通过4-bit的nf4量化,且加入更多adapter,在大幅减少显存消耗的同时,尽可能逼近全量参数微调的效果。 该方法可以在一张V100上对33B的模型进行微调,并且性能逼近全量参数微调。

### 三、推理Demo示例:
```Python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

# 设置设备
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# 加载模型和分词器
model_name = "meta-llama/Llama-2-7b-chat-hf"  # 模型名称,可以根据需要调整
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
model.to(device)

def generate_response(prompt, max_length=100, temperature=0.7, top_p=0.9):
    inputs = tokenizer(prompt, return_tensors="pt").to(device)
    outputs = model.generate(
        **inputs,
        max_length=max_length,
        temperature=temperature,
        top_p=top_p,
        do_sample=True
    )
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response

if __name__ == "__main__":
    prompt = "Hello, how are you today?"
    response = generate_response(prompt)
    print(response)
```

- GitHub:[藏文心理健康支持对话数据集(Tibetan_Mental)与大模型(Tibetan_Mental_Chat)](https://github.com/Shajiu/Tibetan_Mental_Health_Chat "可选标题")