Update README.md
Browse files
README.md
CHANGED
@@ -9,5 +9,67 @@ datasets:
|
|
9 |
- Kedreamix/psychology-10k-Deepseek-R1-zh
|
10 |
---
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
- Kedreamix/psychology-10k-Deepseek-R1-zh
|
10 |
---
|
11 |
|
12 |
+
# Model Card for DeepSeek-R1-Psychology-COT
|
13 |
+
|
14 |
+
## Model Description
|
15 |
+
This model is a fine-tuned version of the DeepSeek-R1-Psychology-COT model, designed for specific tasks in the psychology domain using Chain-of-Thought (CoT) reasoning.
|
16 |
+
|
17 |
+
## Usage
|
18 |
+
|
19 |
+
### Fine-tuning Code Example
|
20 |
+
|
21 |
+
Below is the code to fine-tune the model using the `unsloth` and `trl` libraries:
|
22 |
+
|
23 |
+
```python
|
24 |
+
# Modules for inference
|
25 |
+
import unsloth
|
26 |
+
from unsloth import FastLanguageModel
|
27 |
+
import torch # Import PyTorch
|
28 |
+
from trl import SFTTrainer # Trainer for supervised fine-tuning (SFT)
|
29 |
+
from unsloth import is_bfloat16_supported # Checks if the hardware supports bfloat16 precision
|
30 |
+
# Hugging Face modules
|
31 |
+
from transformers import TrainingArguments # Defines training hyperparameters
|
32 |
+
from datasets import load_dataset # Lets you load fine-tuning datasets
|
33 |
+
|
34 |
+
model_id = "cvGod/DeepSeek-R1-Psychology-COT"
|
35 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
36 |
+
model_name=model_id,
|
37 |
+
max_seq_length=2048,
|
38 |
+
dtype=None,
|
39 |
+
load_in_4bit=True,
|
40 |
+
|
41 |
+
)
|
42 |
+
|
43 |
+
prompt_style = """以下是一项任务说明,并附带了更详细的背景信息。
|
44 |
+
请撰写一个满足完成请求的回复。
|
45 |
+
在回答之前,请仔细考虑问题,并创建一个逐步的思考链,以确保逻辑和准确的回答。
|
46 |
+
|
47 |
+
### Instruction:
|
48 |
+
你是一个专业的心里专家专家,请你根据以下问题回答。
|
49 |
+
### Question:
|
50 |
+
{}
|
51 |
+
### Response:
|
52 |
+
{}"""
|
53 |
+
EOS_TOKEN = tokenizer.eos_token
|
54 |
+
|
55 |
+
question = """我晚上难以入睡,我认为这是因为我对工作感到压力"""
|
56 |
+
|
57 |
+
# Load the inference model using FastLanguageModel (Unsloth optimizes for speed)
|
58 |
+
FastLanguageModel.for_inference(model) # Unsloth has 2x faster inference!
|
59 |
+
|
60 |
+
# Tokenize the input question with a specific prompt format and move it to the GPU
|
61 |
+
inputs = tokenizer([prompt_style.format(question, "")], return_tensors="pt").to("cuda")
|
62 |
+
|
63 |
+
# Generate a response using LoRA fine-tuned model with specific parameters
|
64 |
+
outputs = model.generate(
|
65 |
+
input_ids=inputs.input_ids, # Tokenized input IDs
|
66 |
+
attention_mask=inputs.attention_mask, # Attention mask for padding handling
|
67 |
+
max_new_tokens=1024, # Maximum length for generated response
|
68 |
+
use_cache=True, # Enable cache for efficient generation
|
69 |
+
)
|
70 |
+
|
71 |
+
# Decode the generated response from tokenized format to readable text
|
72 |
+
response = tokenizer.batch_decode(outputs)
|
73 |
+
|
74 |
+
# Extract and print only the model's response part after "### Response:"
|
75 |
+
print(response[0].split("### Response:")[1])
|