|
--- |
|
license: apache-2.0 |
|
datasets: |
|
- BAAI/IndustryInstruction |
|
- BAAI/IndustryInstruction_Law-Justice |
|
base_model: |
|
- meta-llama/Meta-Llama-3.1-8B-Instruct |
|
tags: |
|
- chatmodel |
|
- 法律领域语言模型 |
|
- 对话模型 |
|
--- |
|
|
|
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) |
|
|
|
## training params |
|
|
|
The training framework is llama-factory, template=llama3 |
|
|
|
``` |
|
learning_rate=1e-5 |
|
lr_scheduler_type=cosine |
|
max_length=2048 |
|
warmup_ratio=0.05 |
|
batch_size=64 |
|
epoch=10 |
|
``` |
|
|
|
select best ckpt by the evaluation loss |
|
## evaluation |
|
|
|
Duto to there is no evaluation benchmark, we can not eval the model |
|
|
|
## How to use |
|
|
|
```python |
|
# !/usr/bin/env python |
|
# -*- coding:utf-8 -*- |
|
# ================================================================== |
|
# [Author] : xiaofeng |
|
# [Descriptions] : |
|
# ================================================================== |
|
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
import transformers |
|
import torch |
|
|
|
|
|
llama3_jinja = """{% if messages[0]['role'] == 'system' %} |
|
{% set offset = 1 %} |
|
{% else %} |
|
{% set offset = 0 %} |
|
{% endif %} |
|
|
|
{{ bos_token }} |
|
{% for message in messages %} |
|
{% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %} |
|
{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }} |
|
{% endif %} |
|
|
|
{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }} |
|
{% endfor %} |
|
|
|
{% if add_generation_prompt %} |
|
{{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }} |
|
{% endif %}""" |
|
|
|
|
|
dtype = torch.bfloat16 |
|
|
|
model_dir = "MonteXiaofeng/Law_Justice-llama3_1_8B_instruct" |
|
model = AutoModelForCausalLM.from_pretrained( |
|
model_dir, |
|
device_map="cuda", |
|
torch_dtype=dtype, |
|
) |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_dir) |
|
tokenizer.chat_template = llama3_jinja # update template |
|
|
|
message = [ |
|
{"role": "system", "content": "You are a helpful assistant"}, |
|
{ |
|
"role": "user", |
|
"content": "在处理合同纠纷时,有哪些常见的法律原则和规定需要遵守?", |
|
}, |
|
] |
|
prompt = tokenizer.apply_chat_template( |
|
message, tokenize=False, add_generation_prompt=True |
|
) |
|
print(prompt) |
|
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt") |
|
prompt_length = len(inputs[0]) |
|
print(f"prompt_length:{prompt_length}") |
|
|
|
generating_args = { |
|
"do_sample": True, |
|
"temperature": 1.0, |
|
"top_p": 0.5, |
|
"top_k": 15, |
|
"max_new_tokens": 512, |
|
} |
|
|
|
|
|
generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args) |
|
|
|
response_ids = generate_output[:, prompt_length:] |
|
response = tokenizer.batch_decode( |
|
response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True |
|
)[0] |
|
|
|
|
|
""" |
|
在处理合同纠纷时,有几个常见的法律原则和规定需要遵守。首先,合同的有效性是非常重要的。根据法律,合同必须是合法、真实、自愿、平等、公平、诚实信用和有约束力的。因此,在处理合同纠纷时,需要确定合同是否符合这些原则。 |
|
|
|
其次,合同的解释也是一个关键问题。在合同纠纷中,法院或仲裁机构会根据合同条款的明确性和合理性来解释合同的含义。如果合同条款不明确或存在歧义,法院或仲裁机构可能会根据相关法律和合同的目的来进行解释。 |
|
|
|
此外,合同的履行也是一个重要的方面。在处理合同纠纷时,需要确定各方是否履行了合同中的义务。根据法律,合同的履行应当遵守合同约定的时间、方式和质量等要求。如果一方未能履行合同义务,另一方有权要求违约方承担相应的责任。 |
|
|
|
最后,解决合同纠纷的方式也是需要考虑的因素。在处理合同纠纷时,可以通过协商、调解、仲裁或诉讼等方式解决。根据具体情况,可以选择最适合的解决方式来解决纠纷。 |
|
|
|
总之,在处理合同纠纷时,需要遵守合同的有效性原则、合同的解释原则和合同的履行原则,并根据具体情况选择合适的解决方式。 |
|
""" |
|
print(f"response:{response}") |
|
|
|
|
|
``` |