MonteXiaofeng
commited on
Commit
•
a240c49
1
Parent(s):
0b7b08d
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- BAAI/IndustryInstruction
|
5 |
+
- BAAI/IndustryInstruction_Law-Justice
|
6 |
+
base_model:
|
7 |
+
- meta-llama/Meta-Llama-3.1-8B-Instruct
|
8 |
+
---
|
9 |
+
|
10 |
+
This model is finetuned on the model llama3.1-8b-instruct using the dataset [BAAI/IndustryInstruction_Law-Justice](https://huggingface.co/datasets/BAAI/IndustryInstruction_Law-Justice) dataset, the dataset details can jump to the repo: [BAAI/IndustryInstruction](https://huggingface.co/datasets/BAAI/IndustryInstruction)
|
11 |
+
|
12 |
+
## training params
|
13 |
+
|
14 |
+
The training framework is llama-factory, template=llama3
|
15 |
+
|
16 |
+
```
|
17 |
+
learning_rate=1e-5
|
18 |
+
lr_scheduler_type=cosine
|
19 |
+
max_length=2048
|
20 |
+
warmup_ratio=0.05
|
21 |
+
batch_size=64
|
22 |
+
epoch=10
|
23 |
+
```
|
24 |
+
|
25 |
+
select best ckpt by the evaluation loss
|
26 |
+
## evaluation
|
27 |
+
|
28 |
+
Duto to there is no evaluation benchmark, we can not eval the model
|
29 |
+
|
30 |
+
## How to use
|
31 |
+
|
32 |
+
```python
|
33 |
+
# !/usr/bin/env python
|
34 |
+
# -*- coding:utf-8 -*-
|
35 |
+
# ==================================================================
|
36 |
+
# [Author] : xiaofeng
|
37 |
+
# [Descriptions] :
|
38 |
+
# ==================================================================
|
39 |
+
|
40 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
41 |
+
import transformers
|
42 |
+
import torch
|
43 |
+
|
44 |
+
|
45 |
+
llama3_jinja = """{% if messages[0]['role'] == 'system' %}
|
46 |
+
{% set offset = 1 %}
|
47 |
+
{% else %}
|
48 |
+
{% set offset = 0 %}
|
49 |
+
{% endif %}
|
50 |
+
|
51 |
+
{{ bos_token }}
|
52 |
+
{% for message in messages %}
|
53 |
+
{% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %}
|
54 |
+
{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
|
55 |
+
{% endif %}
|
56 |
+
|
57 |
+
{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}
|
58 |
+
{% endfor %}
|
59 |
+
|
60 |
+
{% if add_generation_prompt %}
|
61 |
+
{{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }}
|
62 |
+
{% endif %}"""
|
63 |
+
|
64 |
+
|
65 |
+
dtype = torch.bfloat16
|
66 |
+
|
67 |
+
model_dir = "MonteXiaofeng/Hospitality-llama3_1_8B_instruct"
|
68 |
+
model = AutoModelForCausalLM.from_pretrained(
|
69 |
+
model_dir,
|
70 |
+
device_map="cuda",
|
71 |
+
torch_dtype=dtype,
|
72 |
+
)
|
73 |
+
|
74 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
75 |
+
tokenizer.chat_template = llama3_jinja # update template
|
76 |
+
|
77 |
+
message = [
|
78 |
+
{"role": "system", "content": "You are a helpful assistant"},
|
79 |
+
{
|
80 |
+
"role": "user",
|
81 |
+
"content": "在处理合同纠纷时,有哪些常见的法律原则和规定需要遵守?",
|
82 |
+
},
|
83 |
+
]
|
84 |
+
prompt = tokenizer.apply_chat_template(
|
85 |
+
message, tokenize=False, add_generation_prompt=True
|
86 |
+
)
|
87 |
+
print(prompt)
|
88 |
+
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
89 |
+
prompt_length = len(inputs[0])
|
90 |
+
print(f"prompt_length:{prompt_length}")
|
91 |
+
|
92 |
+
generating_args = {
|
93 |
+
"do_sample": True,
|
94 |
+
"temperature": 1.0,
|
95 |
+
"top_p": 0.5,
|
96 |
+
"top_k": 15,
|
97 |
+
"max_new_tokens": 512,
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args)
|
102 |
+
|
103 |
+
response_ids = generate_output[:, prompt_length:]
|
104 |
+
response = tokenizer.batch_decode(
|
105 |
+
response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
|
106 |
+
)[0]
|
107 |
+
|
108 |
+
|
109 |
+
"""
|
110 |
+
在处理合同纠纷时,有几个常见的法律原则和规定需要遵守。首先,合同的有效性是非常重要的。根据法律,合同必须是合法、真实、自愿、平等、公平、诚实信用和有约束力的。因此,在处理合同纠纷时,需要确定合同是否符合这些原则。
|
111 |
+
|
112 |
+
其次,合同的解释也是一个关键问题。在合同纠纷中,法院或仲裁机构会根据合同条款的明确性和合理性来解释合同的含义。如果合同条款不明确或存在歧义,法院或仲裁机构可能会根据相关法律和合同的目的来进行解释。
|
113 |
+
|
114 |
+
此外,合同的履行也是一个重要的方面。在处理合同纠纷时,需要确定各方是否履行了合同中的义务。根据法律,合同的履行应当遵守合同约定的时间、方式和质量等要求。如果一方未能履行合同义务,另一方有权要求违约方承担相应的责任。
|
115 |
+
|
116 |
+
最后,解决合同纠纷的方式也是需要考虑的因素。在处理合同纠纷时,可以通过协商、调解、仲裁或诉讼等方式解决。根据具体情况,可以选择最适合的解决方式来解决纠纷。
|
117 |
+
|
118 |
+
总之,在处理合同纠纷时,需要遵守合同的有效性原则、合同的解释原则和合同的履行原则,并根据具体情况选择合适的解决方式。
|
119 |
+
"""
|
120 |
+
print(f"response:{response}")
|
121 |
+
|
122 |
+
|
123 |
+
```
|