Views
No views yet
learning_rate=1e-5
lr_scheduler_type=cosine
max_length=2048
warmup_ratio=0.05
batch_size=64
epoch=101# !/usr/bin/env python
2# -*- coding:utf-8 -*-
3# ==================================================================
4# [Author] : xiaofeng
5# [Descriptions] :
6# ==================================================================
7
8from transformers import AutoTokenizer, AutoModelForCausalLM
9import transformers
10import torch
11
12
13llama3_jinja = """{% if messages[0]['role'] == 'system' %}
14 {% set offset = 1 %}
15{% else %}
16 {% set offset = 0 %}
17{% endif %}
18
19{{ bos_token }}
20{% for message in messages %}
21 {% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %}
22 {{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
23 {% endif %}
24
25 {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}
26{% endfor %}
27
28{% if add_generation_prompt %}
29 {{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }}
30{% endif %}"""
31
32
33dtype = torch.bfloat16
34
35model_dir = "XiaofengAlg/Law_Justice-llama3_1_8B_instruct"
36model = AutoModelForCausalLM.from_pretrained(
37 model_dir,
38 device_map="cuda",
39 torch_dtype=dtype,
40)
41
42tokenizer = AutoTokenizer.from_pretrained(model_dir)
43tokenizer.chat_template = llama3_jinja # update template
44
45message = [
46 {"role": "system", "content": "You are a helpful assistant"},
47 {
48 "role": "user",
49 "content": "在处理合同纠纷时,有哪些常见的法律原则和规定需要遵守?",
50 },
51]
52prompt = tokenizer.apply_chat_template(
53 message, tokenize=False, add_generation_prompt=True
54)
55print(prompt)
56inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
57prompt_length = len(inputs[0])
58print(f"prompt_length:{prompt_length}")
59
60generating_args = {
61 "do_sample": True,
62 "temperature": 1.0,
63 "top_p": 0.5,
64 "top_k": 15,
65 "max_new_tokens": 512,
66}
67
68
69generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args)
70
71response_ids = generate_output[:, prompt_length:]
72response = tokenizer.batch_decode(
73 response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
74)[0]
75
76
77"""
78在处理合同纠纷时,有几个常见的法律原则和规定需要遵守。首先,合同的有效性是非常重要的。根据法律,合同必须是合法、真实、自愿、平等、公平、诚实信用和有约束力的。因此,在处理合同纠纷时,需要确定合同是否符合这些原则。
79
80其次,合同的解释也是一个关键问题。在合同纠纷中,法院或仲裁机构会根据合同条款的明确性和合理性来解释合同的含义。如果合同条款不明确或存在歧义,法院或仲裁机构可能会根据相关法律和合同的目的来进行解释。
81
82此外,合同的履行也是一个重要的方面。在处理合同纠纷时,需要确定各方是否履行了合同中的义务。根据法律,合同的履行应当遵守合同约定的时间、方式和质量等要求。如果一方未能履行合同义务,另一方有权要求违约方承担相应的责任。
83
84最后,解决合同纠纷的方式也是需要考虑的因素。在处理合同纠纷时,可以通过协商、调解、仲裁或诉讼等方式解决。根据具体情况,可以选择最适合的解决方式来解决纠纷。
85
86总之,在处理合同纠纷时,需要遵守合同的有效性原则、合同的解释原则和合同的履行原则,并根据具体情况选择合适的解决方式。
87"""
88print(f"response:{response}")
89
901@misc{shi2024industryinstruction,
2 title = {IndustryInstruction},
3 author = {Xiaofeng Shi and Lulu Zhao and Hua Zhou and Donglin Hao and Yonghua Lin},
4 year = {2024},
5 publisher = {Hugging Face},
6 doi = {10.57967/hf/3487},
7 url = {https://huggingface.co/datasets/BAAI/IndustryInstruction}
8}