├── .gitignore ├── LICENSE ├── README.md ├── README_en.md ├── README_old.md ├── data ├── fakao_gpt4.json ├── judical_examination.json ├── judical_examination_v2.json ├── legal_advice.json ├── legal_counsel_multi_turn_with_article_v2.json ├── legal_counsel_v2.json ├── legal_counsel_with_article_v2.json └── zixun_gpt4.json ├── demo ├── decrypt.py ├── demo_cmd.py ├── demo_web.py ├── run_inference_v1.md └── run_inference_v2.md ├── lawyer_llama_report.pdf └── scripts ├── convert_hf-7b_to_llama-pth.py └── model_delta.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | .idea 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | db.sqlite3-journal 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | .python-version 87 | 88 | # pipenv 89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 92 | # install all needed dependencies. 93 | #Pipfile.lock 94 | 95 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 96 | __pypackages__/ 97 | 98 | # Celery stuff 99 | celerybeat-schedule 100 | celerybeat.pid 101 | 102 | # SageMath parsed files 103 | *.sage.py 104 | 105 | # Environments 106 | .env 107 | .venv 108 | env/ 109 | venv/ 110 | ENV/ 111 | env.bak/ 112 | venv.bak/ 113 | 114 | # Spyder project settings 115 | .spyderproject 116 | .spyproject 117 | 118 | # Rope project settings 119 | .ropeproject 120 | 121 | # mkdocs documentation 122 | /site 123 | 124 | # mypy 125 | .mypy_cache/ 126 | .dmypy.json 127 | dmypy.json 128 | 129 | # Pyre type checker 130 | .pyre/ 131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [ZH] [[EN]](README_en.md) 2 | 3 | # Lawyer LLaMA 4 | 5 | 通过指令微调,LLaMA 模型在通用领域展现出了非常好的表现。但由于缺少合适的数据,少有人探究LLaMA在法律领域的能力。为了弥补这一空白,我们提出了Lawyer LLaMA,一个在法律领域数据上进行了额外训练的模型。 6 | 7 | Lawyer LLaMA 首先在大规模法律语料上进行了continual pretraining,让它系统的学习中国的法律知识体系。 8 | 在此基础上,我们借助ChatGPT收集了一批对中国国家统一法律职业资格考试客观题(以下简称法考)的分析和对法律咨询的回答,利用收集到的数据对模型进行指令微调,让模型习得将法律知识应用到具体场景中的能力。 9 | 10 | 我们的模型能够: 11 | 12 | 1. **掌握中国法律知识:** 能够正确的理解民法、刑法、行政法、诉讼法等常见领域的法律概念。例如,掌握了刑法中的犯罪构成理论,能够从刑事案件的事实描述中识别犯罪主体、犯罪客体、犯罪行为、主观心理状态等犯罪构成要件。模型利用学到的法律概念与理论,能够较好回答法考中的大部分题目。 13 | 14 | 2. **应用于中国法律实务**:能够以通俗易懂的语言解释法律概念,并且进行基础的法律咨询,涵盖婚姻、借贷、海商、刑事等法律领域。 15 | 16 | 为了给中文法律大模型的开放研究添砖加瓦,本项目将开源一系列**法律领域的指令微调数据**和**基于LLaMA训练的中文法律大模型的参数** 。 17 | 18 | ## 新闻 19 | [2024/4/25] 🆕 发布了新版[**Lawyer LLaMA 2 (`lawyer-llama-13b-v2`)**](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v2.md)模型参数,以及**更高质量的法律指令微调数据**。 20 | 21 | [2023/10/14] 更新了Lawyer LLaMA技术报告[**Lawyer LLaMA: Enhancing LLMs with Legal Knowledge**](https://arxiv.org/abs/2305.15062),提供了更多的技术细节和研究发现。 22 | 23 | [2023/6/8] 开源了[`lawyer-llama-13b-beta1.0`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v1.md)模型参数。 24 | 25 | [2023/5/25] 开源了更大规模的指令微调数据,发布了包含和用户问题相关法条的对话数据。 26 | 27 | [2023/5/25] 发布了[Lawyer LLaMA技术报告](https://arxiv.org/abs/2305.15062)。 28 | 29 | [2023/4/13] 开源了由ChatGPT生成的指令微调数据,包含2k条法考题目的解答及5k条法律咨询回复。 30 | 31 | 32 | ## 训练数据 33 | 34 | ### 法律领域纯文本语料 35 | 36 | 我们收集了部分公开的法律数据用于模型的continual training,包括法律条文、裁判文书等。 37 | 38 | ### 通用指令微调数据 39 | 40 | [Alpaca-GPT4](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM) 52k 中文,52k 英文。 41 | 42 | ### 法律指令微调数据 43 | 44 | #### 开源数据概览 45 | | 文件名 | 规模 | 描述 | 46 | | -- | -- | -- | 47 | | 🆕 **fakao_gpt4.json** | 1,000 | **GPT-4生成的法考题解答** | 48 | | 🆕 **zixun_gpt4.json** | 1,000 | **GPT-4基于法条生成的法律咨询回复** | 49 | | judical_examination.json | 2,000 | GPT-3.5生成的法考题解答 | 50 | | judical_examination_v2.json | 5,000 | GPT-3.5生成的法考题解答(第二批) | 51 | | legal_advice.json | 5,000 | GPT-3.5生成的法律咨询回复 | 52 | | legal_counsel_v2.json | 8,000 | GPT-3.5生成的法律咨询回复(第二批) | 53 | | legal_counsel_with_article_v2.json | 1,000 | GPT-3.5基于法条生成的法律咨询回复 | 54 | | legal_counsel_multi_turn_with_article_v2.json | 476 | GPT-3.5基于法条生成的多轮法律咨询对话 | 55 | 56 | **在Lawyer LLaMA 2 (`lawyer-llama-13b-v2`)的训练中我们使用了新版的法律微调数据,以下是一些新旧数据的对比。** 57 | 58 | #### 法考数据 59 | 我们将[JEC-QA中国法考数据集](https://jecqa.thunlp.org/)中的试题输入ChatGPT,让其生成对每个答案的解析。 60 | 61 | 以下对比了新旧版本Lawyer LLaMA使用的数据: 62 | 63 | 64 | | **GPT-3.5生成** | **🆕 GPT-4生成** | 65 | | -- | -- | 66 | | **问题:** 根据《物权法》,下列关于物权变动的特别规定,表述正确吗?
因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力
请给出详细的推理过程之后再给出答案。
**回复:** 这个表述是正确的。
根据《物权法》第X条规定:“因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力。”这意味着,当一个人通过继承或受遗赠获得物权时,这个物权的效力是从继承或受遗赠开始时就生效的,而不是从物权转移的时间开始生效。这是因为,继承或受遗赠是一种法定的方式来获得物权,因此,物权的效力应该从这个法定的时间点开始生效。 | **问题:** 情景分析:张某欠李某2万元,张某有一辆出租车价值4万元,现张某将该车赠与其友王五;李某发现张某无其他值钱的东西,这一赠与会影响张某偿还债务,于是向法院起诉请求撤销张某的赠与行为。法院对该赠与行为的效力应认定。
**回复:** 张某欠李某2万元,而张某将其价值4万元的出租车赠与给王五,这一行为在法律上可能构成恶意转移财产,目的在于逃避债务。李某因此向法院提起诉讼,请求撤销张某的赠与行为,以保护自己的债权不受损害。
首先,根据《中华人民共和国民法典》第二百五十四条规定,债务人恶意转移财产,损害债权人利益的,债权人有权请求人民法院撤销债务人的行为。在本案中,张某的赠与行为可能被视为恶意转移财产,因为这一行为发生在张某欠债的情况下,且张某无其他值钱的东西,这一赠与行为很可能导致李某的债权无法实现。
其次,根据《中华人民共和国民法典》第二百五十五条规定,请求撤销权的行使,不得损害善意第三人的权益。然而,在本案中,王五作为接受赠与的一方,是否具有善意以及是否知道张某的赠与行为会损害债权人(李某)的利益,对于判断赠与行为是否有效是关键。如果王五知道张某的赠与行为是为了逃避偿还债务而进行的,则王五不能被视为善意第三人。
因此,结合上述分析,张某的赠与行为损害了债权人李某的利益,且在债务人恶意转移财产的情况下进行,根据《中华人民共和国民法典》相关规定,法院应当认定该赠与行为无效。这样的判决旨在保护债权人的利益,防止债务人通过转移财产逃避债务的行为。因此,法院对该赠与行为的效力应认定为无效。 | 67 | 68 | 69 | 70 | #### 法律咨询 71 | 我们从[开放数据集](https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8)中收集了一些咨询问题,输入ChatGPT,让ChatGPT扮演律师解答问题。将相关法条一同输入,可以提升ChatGPT生成的质量。 72 | 73 | 以下对比了新旧版本Lawyer LLaMA使用的数据: 74 | 75 | | **GPT-3.5生成** | **🆕 GPT-4生成** | 76 | | -- | -- | 77 | | **问题:** 你好,离婚后夫妻的财产是怎么分配的
**回复:** 您好,根据《民法典》的相关规定,离婚后夫妻的财产分配可以通过夫妻双方协商处理,如果没有协商一致,则需要由法院根据财产的具体情况,按照照顾子女、女方和无过错方权益的原则进行判决。对于夫妻在婚姻关系存续期间所得的共同财产,包括工资、奖金、劳务报酬、生产、经营、投资的收益、知识产权的收益、继承或者受赠的财产以及其他应当归共同所有的财产,应当平分。而夫妻在婚姻关系存续期间所获得的个人财产,包括婚前财产、因受到人身损害获得的赔偿或者补偿、遗嘱或者赠与合同中确定只归一方的财产、一方专用的生活用品,应当归该方所有。请问你们在婚姻关系存续期间所得的财产情况如何呢? | **问题:** 我老公经常不回家,我知道他在外面有人,同时干了许多坏事,一年365天,这个情况怎么办呢?
**回复:** 根据您提供的情况,您老公长期不回家且外面有其他人,这可能触及到《民法典》第一千零四十二条中关于“禁止有配偶者与他人同居”的规定。若您的老公确实与他人同居,这在法律上构成违法行为,您作为受害一方,有权采取相应的法律行动。
首先,您需要收集证据。这包括但不限于您老公与他人同居的证据、他不回家的时间以及他所做的“许多坏事”的相关证据。证据可以是照片、视频、通讯记录、目击者的证词等,这对于您后续的法律行动至关重要。
其次,若您老公的行为给您造成了精神伤害或经济损失,根据《民法典》的相关规定,您可以要求赔偿。婚姻法内还规定了夫妻之间忠诚的义务,一旦违反,受损害一方有权要求精神损害赔偿。
第三,考虑到您提到的您老公“干了许多坏事”,具体情况需要进一步明确。这些行为是涉及违法犯罪还是道德层面的“坏事”?如果涉及违法犯罪,您可以考虑向相关部门举报。这不仅是维护自己权益的行为,也是对社会责任的履行。
最后,关于是否结束婚姻,这是一个需要认真考虑的问题。不忠是许多人选择离婚的重要原因之一,根据您收集的证据,如果决定采取此步骤,可以向人民法院提起离婚诉讼,请求分割夫妻共同财产、争取子女抚养权(如果有)等。
在这个过程中,考虑到法律问题的复杂性,您可能需要寻求专业律师的帮助,他们可以为您提供更专业的法律意见,并代表您进行诉讼活动。
总而言之,您面临的情况较为复杂,但您完全有权利采取行动保护自己的合法权益。关键在于搜集证据、评估情况,并在必要时寻求专业法律帮助。 | 78 | 79 | 80 | 81 | ## 模型参数 82 | 83 | 目前公开了以下版本的Lawyer LLaMA: 84 | * 🆕 `lawyer-llama-13b-v2`: 以[quzhe/llama_chinese_13B](https://huggingface.co/quzhe/llama_chinese_13B)(对LLaMA-2进行了中文持续预训练)为基础,使用通用instruction和GPT-4生成的法律instruction进行SFT,配有婚姻相关法律检索模块。下载地址和使用方法见[`demo/run_inference_v2.md`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v2.md)。 85 | * `lawyer-llama-13b-beta1.0`: 以[Chinese-LLaMA-13B](https://github.com/ymcui/Chinese-LLaMA-Alpaca)为基础,使用通用instruction和GPT-3.5生成的法律instruction进行SFT,配有婚姻相关法律检索模块。下载地址和使用方法见[`demo/run_inference_v1.md`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v1.md)。 86 | 87 | 88 | 89 | ## 系统效果 90 | 91 | ### 自动评测 92 | 我们使用[Chain-of-Discussion](https://arxiv.org/abs/2402.16313)中的200条婚姻家事相关的咨询问题,对以下模型进行测试: 93 | * 🆕 Lawyer LLaMA 2 (`lawyer-llama-13b-v2`) 94 | * Lawyer LLaMA 1 (`lawyer-llama-13b-beta1.0`) 95 | * [DISC-LawLLM](https://github.com/FudanDISC/DISC-LawLLM) 96 | * GPT-3.5-Turbo 97 | * Gemini-1.0-Pro 98 | 99 | 100 | 使用GPT-4对咨询回复质量打分(满分10分)。在评分的过程中,我们要求GPT-4模型围绕着文本的流畅性、逻辑性、是否引用了无关法条、是否与律师撰写的金标准回复在语义上一致等角度进行评分。各模型表现如下: 101 | | 模型 | 得分 | 102 | | -- | -- | 103 | | 🆕 Lawyer LLaMA 2 | 6.71 | 104 | | Lawyer LLaMA 1 | 5.61 | 105 | | DISC-LawLLM | 5.70 | 106 | | GPT-3.5-Turbo | 6.90 | 107 | | Gemini-1.0-Pro | 6.94 | 108 | 109 | *关于旧版模型`lawyer-llama-13b-beta1.0`的表现,请参考旧版[README](README_old.md).* 110 | 111 | 112 | ### 输出样例 113 | 下面展示了Lawyer LLaMA 2、Lawyer LLaMA 1和DISC-LawLLM对于同一问题的输出。 114 | 115 | **问题:** 没有赡养老人就无法继承财产吗? 116 | 117 | **相关法条:** 118 | 1. 《民法典》第一千一百三十条:同一顺序继承人继承遗产的份额,一般应当均等。对生活有特殊困难又缺乏劳动能力的继承人,分配遗产时,应当予以照顾。对被继承人尽了主要扶养义务或者与被继承人共同生活的继承人,分配遗产时,可以多分。有扶养能力和有扶养条件的继承人,不尽扶养义务的,分配遗产时,应当不分或者少分。继承人协商同意的,也可以不均等。 119 | 2. 《民法典》第一千一百二十五条:继承人有下列行为之一的,丧失继承权:(一)故意杀害被继承人;(二)为争夺遗产而杀害其他继承人;(三)遗弃被继承人,或者虐待被继承人情节严重;(四)伪造、篡改、隐匿或者销毁遗嘱,情节严重;(五)以欺诈、胁迫手段迫使或者妨碍被继承人设立、变更或者撤回遗嘱,情节严重。继承人有前款第三项至第五项行为,确有悔改表现,被继承人表示宽恕或者事后在遗嘱中将其列为继承人的,该继承人不丧失继承权。受遗赠人有本条第一款规定行为的,丧失受遗赠权。 120 | 3. 《民法典》第一千一百二十七条:遗产按照下列顺序继承:(一)第一顺序:配偶、子女、父母;(二)第二顺序:兄弟姐妹、祖父母、外祖父母。继承开始后,由第一顺序继承人继承,第二顺序继承人不继承;没有第一顺序继承人继承的,由第二顺序继承人继承。本编所称子女,包括婚生子女、非婚生子女、养子女和有扶养关系的继子女。本编所称父母,包括生父母、养父母和有扶养关系的继父母。本编所称兄弟姐妹,包括同父母的兄弟姐妹、同父异母或者同母异父的兄弟姐妹、养兄弟姐妹、有扶养关系的继兄弟姐妹。 121 | 122 | **模型输出:** 123 | | **DISC-LawLLM** | **Lawyer LLaMA 1** | **🆕 Lawyer LLaMA 2** | 124 | | -- | -- | -- | 125 | | **GPT-4评分:4分**
根据《民法典》规定,子女对父母有赡养扶助的义务。如果成年子女不履行赡养义务的话,缺乏劳动能力或者生活困难的父母,有要求成年子女给付赡养费的权利。所以,在法律上,未尽到赡养老人的义务是会丧失继承权的。
但是需要注意的是,是否存在“丧失继承权”的情况应当由法院根据具体案件情况来进行认定,而不能直接将所有未赡养老人的行为一概而论。 | **GPT-4评分:3分**
您好,根据中国的法律规定,没有赡养老人就不能成为继承人,但是如果被继承人已经去世,其财产将按照法定继承顺序分配给合法的继承人。同时,如果被继承人在生前曾经给予过抚养或扶养,则在分配遗产时,可以给予一定的照顾。此外,如果被继承人遗嘱中有关于财产分配的规定,则应按照遗嘱执行。请问您的具体情况是什么呢? | **GPT-4评分:8分**
依据您的咨询,关于是否因为没有赡养老就不能继承财产的问题,我们可以从《民法典》的相关规定进行分析。
首先,根据《民法典》第一千一百三十条的规定,继承人在继承遗产时,如果对被继承人尽了主要扶养义务或者与被继承人共同生活的继承人,可以多分遗产。这意味着,如果继承人在被继承人生前对其进行了经济上的支持或生活上的照料,那么在继承遗产时可能会得到更多的份额。
其次,《民法典》第一千一百二十五条明确指出,继承人有遗弃被继承人,或者虐待被继承人情节严重的,将丧失继承权。这表明,如果继承人在被继承人生前对其进行了遗弃或虐待,导致其生活处于困境,那么在继承遗产时可能会受到限制。
然而,《民法典》并没有直接规定说没有赡养老就不能继承财产。继承权的获取主要基于血缘关系和法律规定的继承人范围,而不是直接取决于赡养老的行为。因此,即使在没有履行赡养老义务的情况下,继承人仍然有权继承遗产。
综上所述,虽然赡养老行为可能会影响继承权的行使,但不赡养老并不直接剥夺继承权。继承权的获得主要取决于血缘关系和法律规定的继承人资格。如果您有继承权的疑问,建议详细了解自己的继承权情况,并考虑是否有遗弃或虐待行为,以免影响继承权利的行使。 | 126 | 127 | 128 | ## 致谢 129 | 130 | 本项目的开放过程中,获得了以下项目的帮助,在此表示感谢。 131 | 132 | https://jecqa.thunlp.org/ 133 | 134 | https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8 135 | 136 | https://github.com/tatsu-lab/stanford_alpaca 137 | 138 | https://github.com/LianjiaTech/BELLE 139 | 140 | https://github.com/ymcui/Chinese-LLaMA-Alpaca 141 | 142 | https://github.com/pointnetwork/point-alpaca 143 | 144 | 本项目主要贡献人员: 145 | 146 | [黄曲哲](https://andrewzhe.github.io/)\*,[陶铭绪](https://kobayashikanna01.github.io/)\*,[张晨](https://luciusssss.github.io/)\*,[安震威](https://scholar.google.com/citations?user=PPJ9MA0AAAAJ)\*,[姜聪](https://scholar.google.com/citations?user=7lLPJuoAAAAJ),[陈智斌](https://zacharychenpk.github.io/),[伍子睿](https://williamzr.github.io/),[冯岩松](https://yansongfeng.github.io/) 147 | 148 | \* Equal Contribution 149 | 150 | 本项目是在冯岩松教授的指导下进行的。 151 | 152 | ## 社区贡献 153 | 154 | 不少开发者对Lawyer LLaMA的部署使用进行了分享,在此表示感谢。相关社区贡献列举如下: 155 | 156 | * 在通过命令行部署模型时,使用nginx反向代理访问此服务,可参考https://github.com/LeetJoe/lawyer-llama/blob/main/demo/nginx_proxy.md (Credit to @LeetJoe) 157 | * 对`lawyer-llama-13b-v2`进行Q4量化并通过ollama部署,可参考https://github.com/AndrewZhe/lawyer-llama/issues/66 (Credit to @yangxiaoshuai2333) 158 | 159 | ## **局限性和使用限制** 160 | 161 | 本项目内容仅供用于学术研究,不得用于商业以及其他会对社会带来危害的用途。使用涉及第三方代码的部分时,请严格遵循相应的开源协议。 162 | 163 | 本项目中使用的数据由ChatGPT生成,未经严格验证,可能会存在错误内容,在使用时请注意甄别。 164 | 165 | 本项目中的模型输出并非专业法律咨询结果,可能会包含错误内容。如需法律援助,请从专业人士处获得帮助。 166 | 167 | ## 引用 168 | 169 | 如果您使用了本项目的内容,或者认为本项目对您的研究有帮助,请引用本项目。 170 | 171 | ```Plaintext 172 | @misc{huang2023lawyer, 173 | title={Lawyer LLaMA Technical Report}, 174 | author={Quzhe Huang and Mingxu Tao and Chen Zhang and Zhenwei An and Cong Jiang and Zhibin Chen and Zirui Wu and Yansong Feng}, 175 | year={2023}, 176 | eprint={2305.15062}, 177 | archivePrefix={arXiv}, 178 | primaryClass={cs.CL} 179 | } 180 | 181 | @misc{Lawyer-LLama, 182 | title={Lawyer Llama}, 183 | author={Quzhe Huang and Mingxu Tao and Chen Zhang and Zhenwei An and Cong Jiang and Zhibin Chen and Zirui Wu and Yansong Feng}, 184 | year={2023}, 185 | publisher={GitHub}, 186 | journal={GitHub repository}, 187 | howpublished={\url{https://github.com/AndrewZhe/lawyer-llama}}, 188 | } 189 | ``` 190 | -------------------------------------------------------------------------------- /README_en.md: -------------------------------------------------------------------------------- 1 | [[ZH]](README.md) [EN] 2 | 3 | # Lawyer LLaMA 4 | 5 | Through fine-tuning via instructions, the LLaMA model has demonstrated very good performance in the general domain. However, due to a lack of appropriate data, few have explored LLaMA's capabilities in the field of law. To fill this gap, we have introduced Lawyer LLaMA, a model that has undergone additional training on legal domain data. 6 | 7 | Lawyer LLaMA first underwent continual pretraining on a large-scale legal corpus, enabling it to systematically learn about the legal knowledge system in China. Based on this, we have collected a batch of analyses for the Chinese National Judicial Examination objective questions and answers to legal consultations using ChatGPT, using the collected data to fine-tune the model via instructions, allowing the model to acquire the ability to apply legal knowledge to specific scenarios. 8 | 9 | Our model is capable of: 10 | 11 | 1. **Mastering Chinese Legal Knowledge**: It can correctly understand legal concepts in common areas such as civil law, criminal law, administrative law, procedural law, etc. For instance, it has grasped the theory of crime formation in criminal law and can identify the perpetrator, victim, criminal act, subjective mental state, and other components of crime from the factual descriptions of criminal cases. The model, using the legal concepts and theories it has learned, can answer most questions in the legal exam fairly well. 12 | 13 | 2. **Application in Chinese Legal Practice**: It can explain legal concepts in easy-to-understand language and provide basic legal consultation, covering areas such as marriage, lending, maritime, criminal, etc. 14 | 15 | To contribute to the open research of the Chinese legal large-scale model, this project will open-source a series of **legal domain instruction tuning data** and **parameters of the Chinese legal large-scale model trained based on LLaMA**. 16 | 17 | ## News 18 | [2024/4/25] 🆕 Released a new version of [**Lawyer LLaMA 2 (lawyer-llama-13b-v2)**](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v2.md) model parameters, as well as higher quality legal instruction fine-tuning data. 19 | 20 | [2023/10/14] Updated the report [**Lawyer LLaMA: Enhancing LLMs with Legal Knowledge**](https://arxiv.org/abs/2305.15062), providing more technical details and findings. 21 | 22 | [2023/6/8] Open-sourced the [`lawyer-llama-13b-beta1.0`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference.md) model parameters. 23 | 24 | [2023/5/25] Open-sourced larger-scale instruction fine-tuning data, released dialogue data related to legal articles and user questions. 25 | 26 | [2023/5/25] Published [Lawyer LLaMA Technical Report](https://arxiv.org/abs/2305.15062). 27 | 28 | [2023/4/13] Open-sourced instruction fine-tuning data generated by ChatGPT, including 2k legal exam question answers and 5k legal consultation replies. 29 | 30 | 31 | ## Training Data 32 | 33 | ### Legal-domain corpus 34 | 35 | We collected some public legal data for the continual training of the model, including legal provisions, judgment documents, etc. 36 | 37 | ### General instruction tunining data 38 | 39 | [Alpaca-GPT4](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM) 52k in Chinese,52k in English。 40 | 41 | ### Legal instruction tuning data 42 | 43 | #### Overview of open-source data 44 | | File | Size | Description | 45 | | -- | -- | -- | 46 | | 🆕 **fakao_gpt4.json** | 1,000 | **Answers to law exam questions generated by GPT-4** | 47 | | 🆕 **zixun_gpt4.json** | 1,000 | **Legal counsel responses generated by GPT-4 based on legal articles** | 48 | | judical_examination.json | 2,000 | Answers to law exam questions generated by GPT-3.5 | 49 | | judical_examination_v2.json | 5,000 | Answers to law exam questions generated by GPT-3.5 (the second batch) | 50 | | legal_advice.json | 5,000 | Legal counsel responses generated by GPT-3.5 | 51 | | legal_counsel_v2.json | 8,000 | Legal counsel responses generated by GPT-3.5 (the second batch)| 52 | | legal_counsel_with_article_v2.json | 1,000 | Legal counsel responses generated by GPT-3.5 based on legal articles | 53 | | legal_counsel_multi_turn_with_article_v2.json | 476 | GPT-3.5 generates multi-turn legal consultation dialogues based on legal articles | 54 | 55 | #### National Judicial Examination 56 | We input the test questions in the [JEC-QA Chinsese National Judicial Examination](https://jecqa.thunlp.org/) into ChatGPT and let it generate an analysis of each answer. 57 | 58 | Human: 59 | 60 | 根据《物权法》,下列关于物权变动的特别规定,表述正确吗? 61 | 因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力 62 | 请给出详细的推理过程之后再给出答案。 63 | 64 | Assistant: 65 | 66 | 这个表述是正确的。 67 | 根据《物权法》第X条规定:“因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力。”这意味着,当一个人通过继承或受遗赠获得物权时,这个物权的效力是从继承或受遗赠开始时就生效的,而不是从物权转移的时间开始生效。这是因为,继承或受遗赠是一种法定的方式来获得物权,因此,物权的效力应该从这个法定的时间点开始生效。 68 | 69 | #### Legal Consultation 70 | We collected some consulting questions from [a open-source dataset](https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8), input ChatGPT, let ChatGPT act as a lawyer to answer questions . 71 | 72 | Human: 73 | 74 | 是这么个回事,关于我儿子今年2月27日背着我们大人买了一台轻便女式摩托车麻烦你帮忙看怎么解决? 75 | 76 | Assistant: 77 | 78 | 首先,根据法律规定,未满18岁的未成年人是无法独立签订合同的,因此你的儿子在未经你的同意的情况下购买摩托车是无效的。 79 | 其次,根据《中华人民共和国道路交通安全法》的规定,未满18周岁的人不得驾驶摩托车,因此你的儿子也无权驾驶这辆摩托车。 80 | 建议你尽快联系卖家,说明情况并要求退货。如果卖家不同意,你可以向消费者协会或相关部门投诉,寻求法律帮助。同时,你也需要对你的儿子进行教育,让他了解道路交通安全法规,避免再次发生类似的情况。 81 | 82 | We try to input relevant laws and regulations together, which can improve the quality of ChatGPT generation. 83 | 84 | Related Legal Articles: 85 | 86 | 《民法典》第一千零八十七条:离婚时,夫妻的共同财产由双方协议处理;协议不成的,由人民法院根据财产的具体情况,按照照顾子女、女方和无过错方权益的原则判决。对夫或者妻在家庭土地承包经营中享有的权益等,应当依法予以保护。 87 | 《民法典》第一千零六十三条:下列财产为夫妻一方的个人财产:(一)一方的婚前财产;(二)一方因受到人身损害获得的赔偿或者补偿;(三)遗嘱或者赠与合同中确定只归一方的财产;(四)一方专用的生活用品;(五)其他应当归一方的财产。 88 | 《民法典》第一千零六十二条:夫妻在婚姻关系存续期间所得的下列财产,为夫妻的共同财产,归夫妻共同所有:(一)工资、奖金、劳务报酬;(二)生产、经营、投资的收益;(三)知识产权的收益;(四)继承或者受赠的财产,但是本法第一千零六十三条第三项规定的除外;(五)其他应当归共同所有的财产。夫妻对共同财产,有平等的处理权。 89 | 90 | Human: 91 | 92 | 你好,离婚后夫妻的财产是怎么分配的 93 | 94 | Assistant: 95 | 96 | 您好,根据《民法典》的相关规定,离婚后夫妻的财产分配可以通过夫妻双方协商处理,如果没有协商一致,则需要由法院根据财产的具体情况,按照照顾子女、女方和无过错方权益的原则进行判决。对于夫妻在婚姻关系存续期间所得的共同财产,包括工资、奖金、劳务报酬、生产、经营、投资的收益、知识产权的收益、继承或者受赠的财产以及其他应当归共同所有的财产,应当平分。而夫妻在婚姻关系存续期间所获得的个人财产,包括婚前财产、因受到人身损害获得的赔偿或者补偿、遗嘱或者赠与合同中确定只归一方的财产、一方专用的生活用品,应当归该方所有。请问你们在婚姻关系存续期间所得的财产情况如何呢? 97 | 98 | ## Model Parameters 99 | 100 | The following versions of Lawyer LLaMA are currently publicly available: 101 | * 🆕 `lawyer-llama-13b-v2`: 以[quzhe/llama_chinese_13B](https://huggingface.co/quzhe/llama_chinese_13B), without legal corpus continual training, using general instruction and legal instruction for SFT, equipped with a marriage-related legal article retrieval module.[`demo/run_inference_v2.md`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference_v2.md)。 102 | * `lawyer-llama-13b-beta1.0`: Based on [Chinese-LLaMA-13B](https://github.com/ymcui/Chinese-LLaMA-Alpaca), without legal corpus continual training, using general instruction and legal instruction for SFT, equipped with a marriage-related legal article retrieval module. 103 | 104 | For the download address and usage method, see [`demo/run_inference.md`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference.md). 105 | 106 | ## **Case Study** 107 | 108 | We selected LLaMA 13B as the base model, used the legal domain corpus for further pre-training, and fine-tuned in the general domain and legal domain instructions. 109 | 110 | The following compares the model and ChatGPT's responses to some input samples: 111 | 112 |
113 | Understanding of legal concepts 114 | 115 | **Input:** 什么是夫妻共同财产 116 | 117 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 118 | | -- | -- | -- | 119 | | 夫妻共同财产是指夫妻在婚姻关系中取得的任何财产,包括但不限于工资、奖金、股票、房产等。 | 夫妻共同财产是指夫妻双方在婚姻期间共同积累的财产,包括夫妻共同居住的房屋、共同拥有的财产、共同支付的工资、奖金等收入,以及共同承担的债务等。
根据中国法律,夫妻共同财产是夫妻双方在婚姻期间共同积累的财产,除非有特别约定,否则属于夫妻共同财产。在离婚时,夫妻共同财产应当平等分割。
夫妻共同财产的分割比例由夫妻双方协商确定,如果无法协商,则按照下列比例分割:
(一)妻子获得财产的比例应当低于丈夫;
(二)妻子获得财产的比例应当低于丈夫获得财产的比例;
(三)妻子获得财产的比例应当低于丈夫获得财产的比例,但妻子获得的财产超过丈夫获得的财产的部分不在此限制。
在分割夫妻共同财产时,应当尊重妻子的权利,保护妻子的利益,不得虐待、家庭暴力等。 | 夫妻共同财产是指夫妻在婚姻关系存续期间所得的工资、奖金、劳务报酬、生产、经营、投资的收益、知识产权的收益、继承或者受赠的财产等,以及其他应当归共同所有的财产。根据《民法典》第一千零六十二条规定,夫妻共同财产归夫妻共同所有,夫妻对共同财产有平等的处理权。因此,夫妻共同财产是夫妻共同所有,夫妻双方都有权享有和管理。| 120 | 121 | --- 122 | 123 | **Input:** 离婚和无效婚姻的区别 124 | 125 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 126 | | -- | -- | -- | 127 | | 离婚和无效婚姻的区别在于,离婚是指夫妻关系已经结束,而无效婚姻是指夫妻关系从未存在过。 | 离婚和无效婚姻是指在婚姻制度中的两种不同状态。
离婚是指婚姻关系已经无效或被撤销,双方可以通过法律程序结束婚姻关系。离婚的效力取决于婚姻无效的原因,如果婚姻无效是因为双方没有感情或没有按照法律规定结婚,那么离婚就是有效的。如果婚姻无效是因为婚姻本身存在问题,例如违反了法律规定或没有感情,那么离婚就无效。
无效婚姻是指婚姻关系没有依法成立,或者依法成立的婚姻关系本身存在缺陷。无效婚姻的效力取决于婚姻无效的原因。如果婚姻无效是因为双方没有感情或没有按照法律规定结婚,那么婚姻就是无效的。如果婚姻无效是因为婚姻本身存在问题,例如违反了法律规定或没有感情,那么婚姻就是无效的。
因此,离婚和无效婚姻之间的区别在于婚姻的无效原因和婚姻的效力。离婚是婚姻关系已经无效或被撤销,而无效婚姻是指婚姻关系没有依法成立或依法成立的婚姻关系本身存在缺陷。| 离婚和无效婚姻是两种不同的情况。离婚是指夫妻双方自愿解除婚姻关系,而无效婚姻是指在一定情况下,婚姻关系从一开始就没有成立或被认定无效。
根据《民法典》第一千零五十一条规定,如果存在以下情形之一,婚姻将被视为无效:重婚、有禁止结婚的亲属关系、未到法定婚龄。如果婚姻被认定为无效,那么夫妻双方并不具备夫妻的权利和义务,也就不存在离婚的问题。
而对于无效婚姻的财产处理,根据《民法典》第一千零五十四条规定,无效的或者被撤销的婚姻自始没有法律约束力,同居期间所得的财产,由当事人协议处理;协议不成的,由人民法院根据照顾无过错方的原则判决。同时,对于重婚导致的无效婚姻的财产处理,不得侵害合法婚姻当事人的财产权益。
此外,《民法典》第一千零六十三条规定了夫妻共同财产和个人财产的范围,其中一方的婚前财产属于个人财产。因此,如果婚姻被认定为无效,夫妻双方的婚前财产仍属于各自所有。
综上所述,离婚和无效婚姻是两种不同的情况,需要根据具体情况进行判断。如果您需要进一步了解相关法律问题,建议您咨询专业律师。| 128 | 129 |
130 | 131 | 132 |
133 | Legal Consultation 134 | 135 | **Input:** 分析案例:徐某(男)与李某(女)婚后育有一子(1岁半)、一女(8岁),两人准备离婚,都想争取孩子抚养权。徐某经济状况较好,工资收入是李某的数倍,认为自己胜券在握。李某虽收入不高,但女儿更愿意随其生活。 136 | 137 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 138 | | -- | -- | -- | 139 | | 好的,根据你提供的信息,徐某和李某准备离婚,并且两人都想争取孩子抚养权。徐某的经济状况较好,工资收入是李某的数倍,他认为自己胜券在握。而李某虽然收入不高,但女儿更愿意随其生活。
首先,我们需要了解在中国离婚案件中,孩子的抚养权通常是由法院决定的。法院会根据孩子的年龄、性别、父母的经济状况、父母的行为、父母之间的矛盾等因素来做出决定。在这个案例中,徐某的经济状况较好,但女儿更愿意随其生活。这意味着,如果徐某能够证明他能够提供更好的生活条件,法院可能会给他孩子的抚养权。
然而,如果李某能够证明她能够提供更好的家庭环境,法院也可能会给她孩子的抚养权。 因此,在这个案例中,法院可能会考虑多种因素来做出决定,而孩子的意愿只是其中之一。| 这个案例涉及到孩子抚养权的问题,需要考虑多个因素来做出决定。以下是一些分析和建议:
1. 孩子的年龄和需求:孩子在不同的年龄段有不同的需求和特点。1岁半的孩子通常需要关注他们的日常生活,如饮食、睡眠、安全等。8岁的孩子已经进入了青春期,需要更多的关 注和支持,以帮助他们发展社交技能和情感健康。因此,抚养权的归属需要考虑孩子的需求和年龄。
2. 孩子的抚养权归属需要考虑父母之间的差异:徐某和李某的收入和职业背景差异可能会 对抚养权的归属产生影响。但更重要的是,孩子应该由最适合他们的人抚养。因此,需要比较双方的性格、习惯、教育方式、家庭环境等因素,以确定谁更适合抚养孩子。
3. 孩子的意愿:尽管李某的女儿更愿意随其生活,但这并不代表孩子本人会同意跟徐某生 活。因此,抚养权的归属需要考虑孩子的意愿和意愿。如果孩子愿意跟李某生活,那么这可能会更有利于孩子的健康成长。
4. 法律因素:根据中国的法律,孩子的抚养权应该根据有利于孩子成长的原则进行裁决。 这意味着,徐某的经济状况可能会对抚养权的归属产生影响。但是,最终裁决的应该是法律程序,而不是个人意见。
综合以上因素,如果徐某的经济状况更好,并且孩子更愿意跟李某生活,那么李某可能会获得孩子的抚养权。但最终结果还需要根据法律程序来裁决,因此,建议双方在法律框架内进行沟通和协商,以达成一个最好的解决方案。| 根据《中华人民共和国婚姻法》的规定,子女抚养权的判决应当以未成年子女的利益为出发点,综合考虑父母的经济条件、身体情况、家庭环境等情况,最终确定抚养人。因此,在本案中,法院会综合考虑双方的经济能力、工作时间、居住环境等因素来判断抚养权归属问题。
首先,徐某的经济条件好,收入水平较高,可以为孩子的成长提供更好的物质条件。但是,如果李某能够证明自己有更好的照顾孩子的能力,或者孩子的身心健康需要由她来照顾,那么她也有可能获得抚养权。
其次,女儿年龄较大,已经八岁,对于她的意愿也应该有所考虑。如果女儿表示愿意随母亲生活,法院也会考虑到这一因素。
综上所述,在本案中,法院会综合考虑双方的经济能力、照顾孩子的能力、女儿的意愿等因素来判决抚养权归属问题。建议双方积极沟通协商,尽量达成一致意见,并在法律程序中维护自己的合法权益。| 140 | 141 | --- 142 | 143 | **Input:** 21 岁女子甲与25 岁男子乙在网上聊天后产生好感,乙将甲发给其的私密照片保存。后乙要求与甲结婚,甲不同意。乙威胁要公布其照片,甲只好同意结婚并办理了登记。甲是否可以自婚姻登记之日起 1年内请求撤销该婚姻? 144 | 145 | 146 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 147 | | -- | -- | -- | 148 | | 根据《中华人民共和国婚姻法》规定,婚姻登记满一年后,双方可以提出离婚,但需要满足一定的条件。因此,甲可以在婚姻登记一年后申请离婚。| 根据中国《婚姻法》的规定,婚姻关系是自婚姻开始时即存在的,非经法定程序而不能消灭。婚姻无效的原因有:(一)重婚的;(二)有禁止结婚的疾病而结婚无效的;(三)因胁迫而结婚无效的;(四)自始没有感情而结婚无效的;(五)因欺诈而结婚无效的。婚姻无效、可依法撤销。甲可以自婚姻登记之日起 1 年内向当地人民法院提起撤销婚姻的诉讼。| 依据《民法典》第一千零五十二条规定,因胁迫结婚的,受胁迫的一方可以向人民法院请求撤销婚姻。因此,如果甲是在受到胁迫的情况下同意结婚的,那么甲可以在自婚姻登记之日起一年内向人民法院请求撤销婚姻。但是,需要进一步了解的是,是否存在胁迫的情况,以及胁迫的方式和手段等。
另外,根据《民法典》第一千零四十六条规定,结婚应当男女双方完全自愿,禁止任何一方对另一方加以强迫,禁止任何组织或者个人加以干涉。如果甲是在完全自愿的情况下同意结婚的,那么甲无法请求撤销婚姻。
综上所述,需要进一步了解甲同意结婚的具体情况,以及是否存在胁迫的情况。建议甲咨询专业律师,寻求专业的法律帮助。| 149 | 150 |
151 | 152 | ## Acknowledgement 153 | 154 | Our project have received help from the following projects, and we would like to express our gratitude. 155 | 156 | https://jecqa.thunlp.org/ 157 | 158 | https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8 159 | 160 | https://github.com/tatsu-lab/stanford_alpaca 161 | 162 | https://github.com/LianjiaTech/BELLE 163 | 164 | https://github.com/ymcui/Chinese-LLaMA-Alpaca 165 | 166 | https://github.com/pointnetwork/point-alpaca 167 | 168 | Constributors of Lawyer LLaMA: 169 | 170 | [Quzhe Huang](https://andrewzhe.github.io/)\*, Mingxu Tao\*, Zhenwei An*, [Chen Zhang](https://luciusssss.github.io/)\*, Cong Jiang, [Zhibin Chen](https://zacharychenpk.github.io/), [Zirui Wu](https://williamzr.github.io/), [Yansong Feng](https://sites.google.com/site/ysfeng/home) 171 | 172 | \* Equal Contribution 173 | 174 | This project is carried out under the guidance of Prof. Yansong Feng. 175 | 176 | ## **Limitations and Usage Restrictions** 177 | 178 | The content of this project is only for academic research and should not be used for commercial purposes or any other uses that could harm society. When using parts involving third-party code, please strictly follow the corresponding open-source agreements. 179 | 180 | The data used in this project is generated by ChatGPT, has not been rigorously validated, and may contain errors. Please be cautious and discerning when using it. 181 | 182 | The model outputs in this project are not professional legal consultation results and may contain errors. If you need legal assistance, please seek help from professionals. 183 | 184 | ## Citation 185 | 186 | If you use the contents of this project, or believe that this project has been helpful for your research, please cite this project. 187 | 188 | ```Plaintext 189 | @misc{huang2023lawyer, 190 | title={Lawyer LLaMA Technical Report}, 191 | author={Quzhe Huang and Mingxu Tao and Chen Zhang and Zhenwei An and Cong Jiang and Zhibin Chen and Zirui Wu and Yansong Feng}, 192 | year={2023}, 193 | eprint={2305.15062}, 194 | archivePrefix={arXiv}, 195 | primaryClass={cs.CL} 196 | } 197 | 198 | @misc{Lawyer-LLama, 199 | title={Lawyer Llama}, 200 | author={Quzhe Huang and Mingxu Tao and Chen Zhang and Zhenwei An and Cong Jiang and Zhibin Chen and Zirui Wu and Yansong Feng}, 201 | year={2023}, 202 | publisher={GitHub}, 203 | journal={GitHub repository}, 204 | howpublished={\url{https://github.com/AndrewZhe/lawyer-llama}}, 205 | } 206 | ``` 207 | -------------------------------------------------------------------------------- /README_old.md: -------------------------------------------------------------------------------- 1 | [ZH] [[EN]](README_en.md) 2 | 3 | # Lawyer LLaMA 4 | 5 | 通过指令微调,LLaMA 模型在通用领域展现出了非常好的表现。但由于缺少合适的数据,少有人探究LLaMA在法律领域的能力。为了弥补这一空白,我们提出了Lawyer LLaMA,一个在法律领域数据上进行了额外训练的模型。 6 | 7 | Lawyer LLaMA 首先在大规模法律语料上进行了continual pretraining,让它系统的学习中国的法律知识体系。 8 | 在此基础上,我们借助ChatGPT收集了一批对中国国家统一法律职业资格考试客观题(以下简称法考)的分析和对法律咨询的回答,利用收集到的数据对模型进行指令微调,让模型习得将法律知识应用到具体场景中的能力。 9 | 10 | 我们的模型能够: 11 | 12 | 1. **掌握中国法律知识:** 能够正确的理解民法、刑法、行政法、诉讼法等常见领域的法律概念。例如,掌握了刑法中的犯罪构成理论,能够从刑事案件的事实描述中识别犯罪主体、犯罪客体、犯罪行为、主观心理状态等犯罪构成要件。模型利用学到的法律概念与理论,能够较好回答法考中的大部分题目。 13 | 14 | 2. **应用于中国法律实务**:能够以通俗易懂的语言解释法律概念,并且进行基础的法律咨询,涵盖婚姻、借贷、海商、刑事等法律领域。 15 | 16 | 为了给中文法律大模型的开放研究添砖加瓦,本项目将开源一系列**法律领域的指令微调数据**和**基于LLaMA训练的中文法律大模型的参数** 。 17 | 18 | ## 新闻 19 | [2023/10/14] 更新了Lawyer LLaMA技术报告[**Lawyer LLaMA: Enhancing LLMs with Legal Knowledge**](https://github.com/AndrewZhe/lawyer-llama/blob/main/lawyer_llama_report.pdf),提供了更多的技术细节和研究发现。 20 | 21 | [2023/6/8] 开源了[`lawyer-llama-13b-beta1.0`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference.md)模型参数。 22 | 23 | [2023/5/25] 开源了更大规模的指令微调数据,发布了包含和用户问题相关法条的对话数据。 24 | 25 | [2023/5/25] 发布了[Lawyer LLaMA技术报告](https://arxiv.org/abs/2305.15062)。 26 | 27 | [2023/4/13] 开源了由ChatGPT生成的指令微调数据,包含2k条法考题目的解答及5k条法律咨询回复。 28 | 29 | ## 更新计划 30 | 31 | - [x] 开源更大规模的指令微调数据 32 | 33 | - [x] 开源法律咨询多轮对话数据 (持续增加中) 34 | 35 | - [x] 开源特定法律领域的咨询模型 36 | 37 | - [ ] 开源通用法律领域的预训练模型 38 | 39 | ## 训练数据 40 | 41 | ### 法律领域纯文本语料 42 | 43 | 我们收集了部分公开的法律数据用于模型的continual training,包括法律条文、裁判文书等。 44 | 45 | ### 通用指令微调数据 46 | 47 | [Alpaca-GPT4](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM) 52k 中文,52k 英文。 48 | 49 | ### 法律指令微调数据 50 | 51 | #### 开源数据概览 52 | | 文件名 | 规模 | 描述 | 53 | | -- | -- | -- | 54 | | judical_examination.json | 2,000 | ChatGPT生成的法考题解答 | 55 | | judical_examination_v2.json | 5,000 | ChatGPT生成的法考题解答(第二批公开) | 56 | | legal_advice.json | 5,000 | ChatGPT生成的法律咨询回复 | 57 | | legal_counsel_v2.json | 8,000 | ChatGPT生成的法律咨询回复(第二批公开) | 58 | | legal_counsel_with_article_v2.json | 1,000 | ChatGPT基于法条生成的法律咨询回复 | 59 | | legal_counsel_multi_turn_with_article_v2.json | 476 | ChatGPT基于法条生成的多轮法律咨询对话 | 60 | 61 | #### 法考数据 62 | 我们将[JEC-QA中国法考数据集](https://jecqa.thunlp.org/)中的试题输入ChatGPT,让其生成对每个答案的解析。 63 | 64 | Human: 65 | 66 | 根据《物权法》,下列关于物权变动的特别规定,表述正确吗? 67 | 因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力 68 | 请给出详细的推理过程之后再给出答案。 69 | 70 | Assistant: 71 | 72 | 这个表述是正确的。 73 | 根据《物权法》第X条规定:“因继承或者受遗赠取得物权的,自继承或者受遗赠开始时发生效力。”这意味着,当一个人通过继承或受遗赠获得物权时,这个物权的效力是从继承或受遗赠开始时就生效的,而不是从物权转移的时间开始生效。这是因为,继承或受遗赠是一种法定的方式来获得物权,因此,物权的效力应该从这个法定的时间点开始生效。 74 | 75 | #### 法律咨询 76 | 我们从[开放数据集](https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8)中收集了一些咨询问题,输入ChatGPT,让ChatGPT扮演律师解答问题。 77 | 78 | Human: 79 | 80 | 是这么个回事,关于我儿子今年2月27日背着我们大人买了一台轻便女式摩托车麻烦你帮忙看怎么解决? 81 | 82 | Assistant: 83 | 84 | 首先,根据法律规定,未满18岁的未成年人是无法独立签订合同的,因此你的儿子在未经你的同意的情况下购买摩托车是无效的。 85 | 其次,根据《中华人民共和国道路交通安全法》的规定,未满18周岁的人不得驾驶摩托车,因此你的儿子也无权驾驶这辆摩托车。 86 | 建议你尽快联系卖家,说明情况并要求退货。如果卖家不同意,你可以向消费者协会或相关部门投诉,寻求法律帮助。同时,你也需要对你的儿子进行教育,让他了解道路交通安全法规,避免再次发生类似的情况。 87 | 88 | 我们尝试将相关法条一同输入,可以提升ChatGPT生成的质量。 89 | 90 | Related Legal Articles: 91 | 92 | 《民法典》第一千零八十七条:离婚时,夫妻的共同财产由双方协议处理;协议不成的,由人民法院根据财产的具体情况,按照照顾子女、女方和无过错方权益的原则判决。对夫或者妻在家庭土地承包经营中享有的权益等,应当依法予以保护。 93 | 《民法典》第一千零六十三条:下列财产为夫妻一方的个人财产:(一)一方的婚前财产;(二)一方因受到人身损害获得的赔偿或者补偿;(三)遗嘱或者赠与合同中确定只归一方的财产;(四)一方专用的生活用品;(五)其他应当归一方的财产。 94 | 《民法典》第一千零六十二条:夫妻在婚姻关系存续期间所得的下列财产,为夫妻的共同财产,归夫妻共同所有:(一)工资、奖金、劳务报酬;(二)生产、经营、投资的收益;(三)知识产权的收益;(四)继承或者受赠的财产,但是本法第一千零六十三条第三项规定的除外;(五)其他应当归共同所有的财产。夫妻对共同财产,有平等的处理权。 95 | 96 | Human: 97 | 98 | 你好,离婚后夫妻的财产是怎么分配的 99 | 100 | Assistant: 101 | 102 | 您好,根据《民法典》的相关规定,离婚后夫妻的财产分配可以通过夫妻双方协商处理,如果没有协商一致,则需要由法院根据财产的具体情况,按照照顾子女、女方和无过错方权益的原则进行判决。对于夫妻在婚姻关系存续期间所得的共同财产,包括工资、奖金、劳务报酬、生产、经营、投资的收益、知识产权的收益、继承或者受赠的财产以及其他应当归共同所有的财产,应当平分。而夫妻在婚姻关系存续期间所获得的个人财产,包括婚前财产、因受到人身损害获得的赔偿或者补偿、遗嘱或者赠与合同中确定只归一方的财产、一方专用的生活用品,应当归该方所有。请问你们在婚姻关系存续期间所得的财产情况如何呢? 103 | 104 | ## 模型参数 105 | 106 | 目前公开了以下版本的Lawyer LLaMA: 107 | * `lawyer-llama-13b-beta1.0`: 以[Chinese-LLaMA-13B](https://github.com/ymcui/Chinese-LLaMA-Alpaca),未经过法律语料continual training,使用通用instruction和法律instruction进行SFT,配有婚姻相关法律检索模块。 108 | 109 | 下载地址和使用方法见[`demo/run_inference.md`](https://github.com/AndrewZhe/lawyer-llama/blob/main/demo/run_inference.md)。 110 | 111 | ## **系统效果** 112 | 113 | 我们选取了LLaMA 13B作为基座模型,使用法律领域语料进一步预训练,并在通用领域和法律领域指令微调。 114 | 115 | 以下对比了该模型和ChatGPT对于部分输入样例的回复: 116 | 117 |
118 | 法律概念理解 119 | 120 | **Input:** 什么是夫妻共同财产 121 | 122 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 123 | | -- | -- | -- | 124 | | 夫妻共同财产是指夫妻在婚姻关系中取得的任何财产,包括但不限于工资、奖金、股票、房产等。 | 夫妻共同财产是指夫妻双方在婚姻期间共同积累的财产,包括夫妻共同居住的房屋、共同拥有的财产、共同支付的工资、奖金等收入,以及共同承担的债务等。
根据中国法律,夫妻共同财产是夫妻双方在婚姻期间共同积累的财产,除非有特别约定,否则属于夫妻共同财产。在离婚时,夫妻共同财产应当平等分割。
夫妻共同财产的分割比例由夫妻双方协商确定,如果无法协商,则按照下列比例分割:
(一)妻子获得财产的比例应当低于丈夫;
(二)妻子获得财产的比例应当低于丈夫获得财产的比例;
(三)妻子获得财产的比例应当低于丈夫获得财产的比例,但妻子获得的财产超过丈夫获得的财产的部分不在此限制。
在分割夫妻共同财产时,应当尊重妻子的权利,保护妻子的利益,不得虐待、家庭暴力等。 | 夫妻共同财产是指夫妻在婚姻关系存续期间所得的工资、奖金、劳务报酬、生产、经营、投资的收益、知识产权的收益、继承或者受赠的财产等,以及其他应当归共同所有的财产。根据《民法典》第一千零六十二条规定,夫妻共同财产归夫妻共同所有,夫妻对共同财产有平等的处理权。因此,夫妻共同财产是夫妻共同所有,夫妻双方都有权享有和管理。| 125 | 126 | --- 127 | 128 | **Input:** 离婚和无效婚姻的区别 129 | 130 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 131 | | -- | -- | -- | 132 | | 离婚和无效婚姻的区别在于,离婚是指夫妻关系已经结束,而无效婚姻是指夫妻关系从未存在过。 | 离婚和无效婚姻是指在婚姻制度中的两种不同状态。
离婚是指婚姻关系已经无效或被撤销,双方可以通过法律程序结束婚姻关系。离婚的效力取决于婚姻无效的原因,如果婚姻无效是因为双方没有感情或没有按照法律规定结婚,那么离婚就是有效的。如果婚姻无效是因为婚姻本身存在问题,例如违反了法律规定或没有感情,那么离婚就无效。
无效婚姻是指婚姻关系没有依法成立,或者依法成立的婚姻关系本身存在缺陷。无效婚姻的效力取决于婚姻无效的原因。如果婚姻无效是因为双方没有感情或没有按照法律规定结婚,那么婚姻就是无效的。如果婚姻无效是因为婚姻本身存在问题,例如违反了法律规定或没有感情,那么婚姻就是无效的。
因此,离婚和无效婚姻之间的区别在于婚姻的无效原因和婚姻的效力。离婚是婚姻关系已经无效或被撤销,而无效婚姻是指婚姻关系没有依法成立或依法成立的婚姻关系本身存在缺陷。| 离婚和无效婚姻是两种不同的情况。离婚是指夫妻双方自愿解除婚姻关系,而无效婚姻是指在一定情况下,婚姻关系从一开始就没有成立或被认定无效。
根据《民法典》第一千零五十一条规定,如果存在以下情形之一,婚姻将被视为无效:重婚、有禁止结婚的亲属关系、未到法定婚龄。如果婚姻被认定为无效,那么夫妻双方并不具备夫妻的权利和义务,也就不存在离婚的问题。
而对于无效婚姻的财产处理,根据《民法典》第一千零五十四条规定,无效的或者被撤销的婚姻自始没有法律约束力,同居期间所得的财产,由当事人协议处理;协议不成的,由人民法院根据照顾无过错方的原则判决。同时,对于重婚导致的无效婚姻的财产处理,不得侵害合法婚姻当事人的财产权益。
此外,《民法典》第一千零六十三条规定了夫妻共同财产和个人财产的范围,其中一方的婚前财产属于个人财产。因此,如果婚姻被认定为无效,夫妻双方的婚前财产仍属于各自所有。
综上所述,离婚和无效婚姻是两种不同的情况,需要根据具体情况进行判断。如果您需要进一步了解相关法律问题,建议您咨询专业律师。| 133 | 134 |
135 | 136 | 137 |
138 | 咨询 139 | 140 | **Input:** 分析案例:徐某(男)与李某(女)婚后育有一子(1岁半)、一女(8岁),两人准备离婚,都想争取孩子抚养权。徐某经济状况较好,工资收入是李某的数倍,认为自己胜券在握。李某虽收入不高,但女儿更愿意随其生活。 141 | 142 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 143 | | -- | -- | -- | 144 | | 好的,根据你提供的信息,徐某和李某准备离婚,并且两人都想争取孩子抚养权。徐某的经济状况较好,工资收入是李某的数倍,他认为自己胜券在握。而李某虽然收入不高,但女儿更愿意随其生活。
首先,我们需要了解在中国离婚案件中,孩子的抚养权通常是由法院决定的。法院会根据孩子的年龄、性别、父母的经济状况、父母的行为、父母之间的矛盾等因素来做出决定。在这个案例中,徐某的经济状况较好,但女儿更愿意随其生活。这意味着,如果徐某能够证明他能够提供更好的生活条件,法院可能会给他孩子的抚养权。
然而,如果李某能够证明她能够提供更好的家庭环境,法院也可能会给她孩子的抚养权。 因此,在这个案例中,法院可能会考虑多种因素来做出决定,而孩子的意愿只是其中之一。| 这个案例涉及到孩子抚养权的问题,需要考虑多个因素来做出决定。以下是一些分析和建议:
1. 孩子的年龄和需求:孩子在不同的年龄段有不同的需求和特点。1岁半的孩子通常需要关注他们的日常生活,如饮食、睡眠、安全等。8岁的孩子已经进入了青春期,需要更多的关 注和支持,以帮助他们发展社交技能和情感健康。因此,抚养权的归属需要考虑孩子的需求和年龄。
2. 孩子的抚养权归属需要考虑父母之间的差异:徐某和李某的收入和职业背景差异可能会 对抚养权的归属产生影响。但更重要的是,孩子应该由最适合他们的人抚养。因此,需要比较双方的性格、习惯、教育方式、家庭环境等因素,以确定谁更适合抚养孩子。
3. 孩子的意愿:尽管李某的女儿更愿意随其生活,但这并不代表孩子本人会同意跟徐某生 活。因此,抚养权的归属需要考虑孩子的意愿和意愿。如果孩子愿意跟李某生活,那么这可能会更有利于孩子的健康成长。
4. 法律因素:根据中国的法律,孩子的抚养权应该根据有利于孩子成长的原则进行裁决。 这意味着,徐某的经济状况可能会对抚养权的归属产生影响。但是,最终裁决的应该是法律程序,而不是个人意见。
综合以上因素,如果徐某的经济状况更好,并且孩子更愿意跟李某生活,那么李某可能会获得孩子的抚养权。但最终结果还需要根据法律程序来裁决,因此,建议双方在法律框架内进行沟通和协商,以达成一个最好的解决方案。| 根据《中华人民共和国婚姻法》的规定,子女抚养权的判决应当以未成年子女的利益为出发点,综合考虑父母的经济条件、身体情况、家庭环境等情况,最终确定抚养人。因此,在本案中,法院会综合考虑双方的经济能力、工作时间、居住环境等因素来判断抚养权归属问题。
首先,徐某的经济条件好,收入水平较高,可以为孩子的成长提供更好的物质条件。但是,如果李某能够证明自己有更好的照顾孩子的能力,或者孩子的身心健康需要由她来照顾,那么她也有可能获得抚养权。
其次,女儿年龄较大,已经八岁,对于她的意愿也应该有所考虑。如果女儿表示愿意随母亲生活,法院也会考虑到这一因素。
综上所述,在本案中,法院会综合考虑双方的经济能力、照顾孩子的能力、女儿的意愿等因素来判决抚养权归属问题。建议双方积极沟通协商,尽量达成一致意见,并在法律程序中维护自己的合法权益。| 145 | 146 | --- 147 | 148 | **Input:** 21 岁女子甲与25 岁男子乙在网上聊天后产生好感,乙将甲发给其的私密照片保存。后乙要求与甲结婚,甲不同意。乙威胁要公布其照片,甲只好同意结婚并办理了登记。甲是否可以自婚姻登记之日起 1年内请求撤销该婚姻? 149 | 150 | 151 | | **BELLE (13B)** | **ChatGLM (6B)** | **Lawyer LLaMA (13B)** | 152 | | -- | -- | -- | 153 | | 根据《中华人民共和国婚姻法》规定,婚姻登记满一年后,双方可以提出离婚,但需要满足一定的条件。因此,甲可以在婚姻登记一年后申请离婚。| 根据中国《婚姻法》的规定,婚姻关系是自婚姻开始时即存在的,非经法定程序而不能消灭。婚姻无效的原因有:(一)重婚的;(二)有禁止结婚的疾病而结婚无效的;(三)因胁迫而结婚无效的;(四)自始没有感情而结婚无效的;(五)因欺诈而结婚无效的。婚姻无效、可依法撤销。甲可以自婚姻登记之日起 1 年内向当地人民法院提起撤销婚姻的诉讼。| 依据《民法典》第一千零五十二条规定,因胁迫结婚的,受胁迫的一方可以向人民法院请求撤销婚姻。因此,如果甲是在受到胁迫的情况下同意结婚的,那么甲可以在自婚姻登记之日起一年内向人民法院请求撤销婚姻。但是,需要进一步了解的是,是否存在胁迫的情况,以及胁迫的方式和手段等。
另外,根据《民法典》第一千零四十六条规定,结婚应当男女双方完全自愿,禁止任何一方对另一方加以强迫,禁止任何组织或者个人加以干涉。如果甲是在完全自愿的情况下同意结婚的,那么甲无法请求撤销婚姻。
综上所述,需要进一步了解甲同意结婚的具体情况,以及是否存在胁迫的情况。建议甲咨询专业律师,寻求专业的法律帮助。| 154 | 155 |
156 | 157 | ## 致谢 158 | 159 | 本项目的开放过程中,获得了以下项目的帮助,在此表示感谢。 160 | 161 | https://jecqa.thunlp.org/ 162 | 163 | https://opendata.pku.edu.cn/dataset.xhtml?persistentId=doi:10.18170/DVN/OLO4G8 164 | 165 | https://github.com/tatsu-lab/stanford_alpaca 166 | 167 | https://github.com/LianjiaTech/BELLE 168 | 169 | https://github.com/ymcui/Chinese-LLaMA-Alpaca 170 | 171 | https://github.com/pointnetwork/point-alpaca 172 | 173 | 本项目贡献人员: 174 | 175 | [黄曲哲](https://andrewzhe.github.io/)\*,[陶铭绪](https://kobayashikanna01.github.io/)\*,[张晨](https://luciusssss.github.io/)\*,安震威*,姜聪,[陈智斌](https://zacharychenpk.github.io/),[伍子睿](https://williamzr.github.io/),[冯岩松](https://sites.google.com/site/ysfeng/home) 176 | 177 | \* Equal Contribution 178 | 179 | 本项目是在冯岩松教授的指导下进行的。 180 | 181 | ## **局限性和使用限制** 182 | 183 | 本项目内容仅供用于学术研究,不得用于商业以及其他会对社会带来危害的用途。使用涉及第三方代码的部分时,请严格遵循相应的开源协议。 184 | 185 | 本项目中使用的数据由ChatGPT生成,未经严格验证,可能会存在错误内容,在使用时请注意甄别。 186 | 187 | 本项目中的模型输出并非专业法律咨询结果,可能会包含错误内容。如需法律援助,请从专业人士处获得帮助。 188 | 189 | ## 引用 190 | 191 | 如果您使用了本项目的内容,或者认为本项目对您的研究有帮助,请引用本项目。 192 | 193 | ```Plaintext 194 | @article{lawyer-llama-report, 195 | title={Lawyer LLaMA Technical Report}, 196 | author={Huang, Quzhe and Tao, Mingxu and Zhang, Chen and An, Zhenwei and Jiang, Cong and Chen, Zhibin and Wu, Zirui and Feng, Yansong}, 197 | journal={ArXiv}, 198 | year={2023}, 199 | volume={abs/2305.15062} 200 | } 201 | 202 | @misc{Lawyer-LLama, 203 | title={Lawyer Llama}, 204 | author={Huang, Quzhe and Tao, Mingxu and Zhang, Chen and An, Zhenwei and Jiang, Cong and Chen, Zhibin and Wu, Zirui and Feng, Yansong}, 205 | year={2023}, 206 | publisher={GitHub}, 207 | journal={GitHub repository}, 208 | howpublished={\url{https://github.com/AndrewZhe/lawyer-llama}}, 209 | } 210 | ``` 211 | -------------------------------------------------------------------------------- /demo/decrypt.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import hashlib 4 | import multiprocessing 5 | import os 6 | 7 | 8 | def xor_bytes(data, key): 9 | return bytes(a ^ b for a, b in zip(data, (key * (len(data) // len(key) + 1))[:len(data)])) 10 | 11 | def xor_worker(task_queue, result_queue): 12 | while True: 13 | chunk_idx, data, key = task_queue.get() 14 | result_queue.put((chunk_idx, xor_bytes(data, key))) 15 | task_queue.task_done() 16 | 17 | def write_result_chunk(fp, w_chunk_idx, pending, hasher): 18 | if not pending: 19 | return w_chunk_idx, pending 20 | pending.sort() 21 | for pending_idx, (chunk_idx, chunk) in enumerate(pending): 22 | if chunk_idx != w_chunk_idx: 23 | return w_chunk_idx, pending[pending_idx:] 24 | fp.write(chunk) 25 | hasher.update(chunk) 26 | w_chunk_idx += 1 27 | return w_chunk_idx, [] 28 | 29 | def main(input_file, key_file, output_dir): 30 | worker_count = max(1, os.cpu_count() - 1) 31 | print(f"Decrypting file {input_file} with {worker_count} workers") 32 | 33 | task_queue = multiprocessing.JoinableQueue(worker_count * 3) 34 | result_queue = multiprocessing.Queue() 35 | processes = [ 36 | multiprocessing.Process(target=xor_worker, args=(task_queue, result_queue)) 37 | for _ in range(worker_count) 38 | ] 39 | for p in processes: 40 | p.daemon = True 41 | p.start() 42 | 43 | chunk_size = 10 * 1024 * 1024 44 | key_chunk_size = 10 * 1024 * 1024 45 | 46 | hasher = hashlib.sha256() 47 | 48 | # Get the checksum from the input file name 49 | input_file_basename = os.path.basename(input_file) 50 | checksum_hex = input_file_basename.split(".")[-2] 51 | 52 | with open(input_file, "rb") as in_file, open(key_file, "rb") as key_file: 53 | # Get the size of the input file 54 | file_size = os.path.getsize(input_file) 55 | 56 | # Minus the checksum size 57 | file_size -= hasher.digest_size 58 | 59 | # Read the checksum from the beginning of the input file 60 | expected_hash = in_file.read(hasher.digest_size) 61 | 62 | # Create the output file path without the checksum in the filename 63 | # remove ..enc 64 | input_file_basename = input_file_basename[:-len(checksum_hex) - 5] 65 | output_file = os.path.join(output_dir, input_file_basename) 66 | 67 | with open(output_file, "wb") as out_file: 68 | r_chunk_idx = 0 # how many chunks we have read 69 | w_chunk_idx = 0 # how many chunks have been written 70 | write_pending = [] # have xor results, awaiting to be written to file 71 | 72 | bytes_read = 0 73 | while True: 74 | chunk = in_file.read(chunk_size) 75 | if not chunk: 76 | break 77 | 78 | key_chunk = key_file.read(key_chunk_size) 79 | if not key_chunk: 80 | key_file.seek(0) 81 | key_chunk = key_file.read(key_chunk_size) 82 | 83 | task_queue.put((r_chunk_idx, chunk, key_chunk)) 84 | # read available results 85 | while not result_queue.empty(): 86 | write_pending.append(result_queue.get()) 87 | 88 | w_chunk_idx_new, write_pending = write_result_chunk(out_file, w_chunk_idx, write_pending, hasher) 89 | 90 | bytes_read += (w_chunk_idx_new - w_chunk_idx) * chunk_size 91 | progress = bytes_read / file_size * 100 92 | sys.stdout.write(f"\rProgress: {progress:.2f}%") 93 | sys.stdout.flush() 94 | 95 | w_chunk_idx = w_chunk_idx_new 96 | r_chunk_idx += 1 97 | 98 | # wait for xor workers 99 | sys.stdout.write('\rWaiting for workers...') 100 | sys.stdout.flush() 101 | task_queue.join() 102 | while not result_queue.empty(): 103 | write_pending.append(result_queue.get()) 104 | sys.stdout.write('\rWriting final chunks...') 105 | sys.stdout.flush() 106 | write_result_chunk(out_file, w_chunk_idx, write_pending, hasher) 107 | 108 | computed_hash = hasher.digest() 109 | 110 | if computed_hash != expected_hash: 111 | print("\nError: Checksums do not match. The file may be corrupted.") 112 | sys.exit(1) 113 | 114 | print ("\nDecryption completed.") 115 | 116 | if __name__ == "__main__": 117 | if len(sys.argv) != 4: 118 | print("Usage: decrypt.py input_file key_file output_dir") 119 | sys.exit(1) 120 | 121 | main(sys.argv[1], sys.argv[2], sys.argv[3]) -------------------------------------------------------------------------------- /demo/demo_cmd.py: -------------------------------------------------------------------------------- 1 | import gradio as gr 2 | import requests 3 | import json 4 | from transformers import LlamaForCausalLM, LlamaTokenizer, TextIteratorStreamer 5 | import torch 6 | import argparse 7 | 8 | def json_send(url, data=None, method="POST"): 9 | headers = {"Content-type": "application/json", 10 | "Accept": "text/plain", "charset": "UTF-8"} 11 | if method == "POST": 12 | if data != None: 13 | response = requests.post(url=url, headers=headers, data=json.dumps(data)) 14 | else: 15 | response = requests.post(url=url, headers=headers) 16 | elif method == "GET": 17 | response = requests.get(url=url, headers=headers) 18 | return json.loads(response.text) 19 | 20 | if __name__ == "__main__": 21 | parser = argparse.ArgumentParser() 22 | parser.add_argument("--checkpoint", type=str, default="") 23 | parser.add_argument("--classifier_url", type=str, default="") 24 | parser.add_argument("--load_in_8bit", action="store_true") 25 | parser.add_argument("--use_chat_mode", action="store_true") 26 | args = parser.parse_args() 27 | checkpoint = args.checkpoint 28 | classifier_url = args.classifier_url 29 | 30 | print("Loading model...") 31 | tokenizer = LlamaTokenizer.from_pretrained(checkpoint) 32 | if args.load_in_8bit: 33 | model = LlamaForCausalLM.from_pretrained(checkpoint, device_map="auto", load_in_8bit=True) 34 | else: 35 | model = LlamaForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.float16) 36 | print("Model loaded.") 37 | 38 | if args.use_chat_mode: 39 | print("Chat mode enabled.") 40 | print("If you want to start a new chat, enter 'clear' please") 41 | chat_history = [] 42 | 43 | while True: 44 | current_user_input = input("[Human] >>> ") 45 | current_user_input = current_user_input.strip() 46 | if len(current_user_input) == 0: 47 | continue 48 | 49 | if args.use_chat_mode and current_user_input == "clear": 50 | chat_history = [] 51 | print("Chat history cleared.") 52 | continue 53 | 54 | if args.use_chat_mode: 55 | history_user_input = [x[0] for x in chat_history] 56 | input_to_classifier = " ".join(history_user_input) + " " + current_user_input 57 | else: 58 | input_to_classifier = current_user_input 59 | data = {"input": input_to_classifier} 60 | result = json_send(classifier_url, data, method="POST") 61 | retrieve_output = result['output'] 62 | 63 | # 构造输入 64 | if len(retrieve_output) == 0: 65 | input_text = "你是人工智能法律助手“Lawyer LLaMA”,能够回答与中国法律相关的问题。\n" 66 | for history_pair in chat_history: 67 | input_text += f"### Human: {history_pair[0]}\n### Assistant: {history_pair[1]}\n" 68 | input_text += f"### Human: {current_user_input}\n### Assistant: " 69 | else: 70 | input_text = f"你是人工智能法律助手“Lawyer LLaMA”,能够回答与中国法律相关的问题。请参考给出的\"参考法条\",回复用户的咨询问题。\"参考法条\"中可能存在与咨询无关的法条,请回复时不要引用这些无关的法条。\n" 71 | for history_pair in chat_history: 72 | input_text += f"### Human: {history_pair[0]}\n### Assistant: {history_pair[1]}\n" 73 | input_text += f"### Human: {current_user_input}\n### 参考法条: {retrieve_output[0]['text']}\n{retrieve_output[1]['text']}\n{retrieve_output[2]['text']}\n### Assistant: " 74 | 75 | input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda") 76 | outputs = model.generate(input_ids, max_new_tokens=400, do_sample=False, repetition_penalty=1.1) 77 | output_text = str(tokenizer.decode(outputs[0], skip_special_tokens=True)) 78 | # skip prompt 79 | output_text = output_text[len(input_text):] 80 | 81 | print("[AI] >>> " + output_text) 82 | 83 | if args.use_chat_mode: 84 | chat_history.append((current_user_input, output_text)) 85 | 86 | -------------------------------------------------------------------------------- /demo/demo_web.py: -------------------------------------------------------------------------------- 1 | import gradio as gr 2 | import requests 3 | import json 4 | from transformers import LlamaForCausalLM, LlamaTokenizer, TextIteratorStreamer 5 | import torch 6 | import threading 7 | import argparse 8 | 9 | class StoppableThread(threading.Thread): 10 | """Thread class with a stop() method. The thread itself has to check 11 | regularly for the stopped() condition.""" 12 | 13 | def __init__(self, *args, **kwargs): 14 | super(StoppableThread, self).__init__(*args, **kwargs) 15 | self._stop_event = threading.Event() 16 | 17 | def stop(self): 18 | self._stop_event.set() 19 | 20 | def stopped(self): 21 | return self._stop_event.is_set() 22 | 23 | def json_send(url, data=None, method="POST"): 24 | headers = {"Content-type": "application/json", 25 | "Accept": "text/plain", "charset": "UTF-8"} 26 | if method == "POST": 27 | if data != None: 28 | response = requests.post(url=url, headers=headers, data=json.dumps(data)) 29 | else: 30 | response = requests.post(url=url, headers=headers) 31 | elif method == "GET": 32 | response = requests.get(url=url, headers=headers) 33 | return json.loads(response.text) 34 | 35 | 36 | 37 | if __name__ == "__main__": 38 | parser = argparse.ArgumentParser() 39 | parser.add_argument("--port", type=int, default=7860) 40 | parser.add_argument("--checkpoint", type=str, default="") 41 | parser.add_argument("--classifier_url", type=str, default="") 42 | parser.add_argument("--load_in_8bit", action="store_true") 43 | args = parser.parse_args() 44 | checkpoint = args.checkpoint 45 | classifier_url = args.classifier_url 46 | 47 | print("Loading model...") 48 | tokenizer = LlamaTokenizer.from_pretrained(checkpoint) 49 | if args.load_in_8bit: 50 | model = LlamaForCausalLM.from_pretrained(checkpoint, device_map="auto", load_in_8bit=True) 51 | else: 52 | model = LlamaForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.float16) 53 | print("Model loaded.") 54 | 55 | with gr.Blocks() as demo: 56 | chatbot = gr.Chatbot() 57 | input_msg = gr.Textbox(label="Input") 58 | with gr.Row(): 59 | generate_button = gr.Button('Generate', elem_id='generate', variant='primary') 60 | clear_button = gr.Button('Clear', elem_id='clear', variant='secondary') 61 | 62 | def user(user_message, chat_history): 63 | 64 | user_message = user_message.strip() 65 | return "", chat_history + [[user_message, None]] 66 | 67 | 68 | def bot(chat_history): 69 | 70 | # extract user inputs from chat history and retrieve law articles 71 | current_user_input = chat_history[-1][0] 72 | 73 | if len(current_user_input) == 0: 74 | yield chat_history[:-1] 75 | return 76 | 77 | # 检索法条 78 | history_user_input = [x[0] for x in chat_history] 79 | input_to_classifier = " ".join(history_user_input) 80 | data = {"input": input_to_classifier} 81 | result = json_send(classifier_url, data, method="POST") 82 | retrieve_output = result['output'] 83 | 84 | # 构造输入 85 | if len(retrieve_output) == 0: 86 | input_text = "你是人工智能法律助手“Lawyer LLaMA”,能够回答与中国法律相关的问题。\n" 87 | for history_pair in chat_history[:-1]: 88 | input_text += f"### Human: {history_pair[0]}\n### Assistant: {history_pair[1]}\n" 89 | input_text += f"### Human: {current_user_input}\n### Assistant: " 90 | else: 91 | input_text = f"你是人工智能法律助手“Lawyer LLaMA”,能够回答与中国法律相关的问题。请参考给出的\"参考法条\",回复用户的咨询问题。\"参考法条\"中可能存在与咨询无关的法条,请回复时不要引用这些无关的法条。\n" 92 | for history_pair in chat_history[:-1]: 93 | input_text += f"### Human: {history_pair[0]}\n### Assistant: {history_pair[1]}\n" 94 | input_text += f"### Human: {current_user_input}\n### 参考法条: {retrieve_output[0]['text']}\n{retrieve_output[1]['text']}\n{retrieve_output[2]['text']}\n### Assistant: " 95 | 96 | print("=== Input ===") 97 | print("input_text: ", input_text) 98 | 99 | inputs = tokenizer(input_text, return_tensors="pt").to("cuda") 100 | streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) 101 | 102 | # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way. 103 | generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=400, do_sample=False, repetition_penalty=1.1) 104 | thread = StoppableThread(target=model.generate, kwargs=generation_kwargs) 105 | thread.start() 106 | 107 | 108 | # 开始流式生成 109 | chat_history[-1][1] = "" 110 | for new_text in streamer: 111 | chat_history[-1][1] += new_text 112 | yield chat_history 113 | 114 | streamer.end() 115 | thread.stop() 116 | print("Output: ", chat_history[-1][1]) 117 | 118 | def stop(invitation_code): 119 | global stop_everything 120 | stop_everything[invitation_code] = True 121 | 122 | 123 | input_msg.submit(user, [input_msg, chatbot], [input_msg, chatbot], queue=False).then( 124 | bot, [chatbot], chatbot 125 | ) 126 | generate_button.click(user, [input_msg, chatbot], [input_msg, chatbot], queue=False).then( 127 | bot, [chatbot], chatbot 128 | ) 129 | 130 | demo.queue() 131 | demo.launch(share=False, server_port=args.port, server_name='0.0.0.0') 132 | 133 | -------------------------------------------------------------------------------- /demo/run_inference_v1.md: -------------------------------------------------------------------------------- 1 | # 模型推理 2 | 我们目前公开了以下版本的Lawyer LLaMA: 3 | * lawyer-llama-13b-beta1.0: 以[Chinese-LLaMA-13B](https://github.com/ymcui/Chinese-LLaMA-Alpaca)为底座,**未经过法律语料continual training**,使用通用instruction和法律instruction进行SFT,配有婚姻相关法律检索模块。 4 | 5 | 我们计划公开: 6 | * 以ChatGLM为底座训练的模型 7 | * 经过法律语料continual training的版本 8 | 9 | ## 运行环境 10 | 建议使用Python 3.8及以上版本。 11 | 12 | 主要依赖库如下: 13 | * `transformers` >= 4.28.0 14 | * `sentencepiece` >= 0.1.97 15 | * `gradio` 16 | 17 | ## 获取模型 18 | 为了符合LLaMA的使用规范,我们发布的Lawyer LLaMA权重需要使用原始LLaMA权重文件进行解码(相关代码来自[point-alpaca](https://github.com/pointnetwork/point-alpaca/))。 19 | 20 | 1. 通过[官方途径](https://github.com/facebookresearch/llama)获取LLaMA原始模型。 21 | 22 | 2. 通过[Hugging Face](https://huggingface.co/pkupie/lawyer-llama-13b-beta1.0)或者[百度网盘](https://pan.baidu.com/s/1cE9_c8er3NASpDkFou-B9g?pwd=lwhx)(提取码:lwhx)获取Lawyer LLaMA权重。 23 | 24 | 3. 利用原始LLaMA文件中的`7B/consolidated.00.pth`文件,运行以下bash命令,使用`decrypt.py`对Lawyer LLaMA模型文件进行解码。 25 | ```bash 26 | for f in "/path/to/model/pytorch_model"*".enc"; \ 27 | do if [ -f "$f" ]; then \ 28 | python3 decrypt.py "$f" "/path/to_original_llama/7B/consolidated.00.pth" "/path/to/model"; \ 29 | fi; \ 30 | done 31 | ``` 32 | 将以上命令中的`/path/to/model/`替换成下载后的Lawyer LLaMA所在路径。 33 | 34 | 4. 从[百度网盘](https://pan.baidu.com/s/1tBkgMzcDe3zZ8Xyf22T7Wg)(提取码:jxqh)下载法条检索模块,并运行其中的`python server.py`启动法条检索服务,默认挂在9098端口。 35 | 36 | ## 模型运行 37 | ### 使用命令行运行 38 | ```bash 39 | python demo_cmd.py \ 40 | --checkpoint /path/to/model \ 41 | --classifier_url "http://127.0.0.1:9098/check_hunyin" \ 42 | --use_chat_mode 43 | ``` 44 | 45 | ### 使用交互界面运行 46 | 运行以下命令启动交互网页,访问`http://127.0.0.1:7863`。 47 | ```bash 48 | python demo_web.py \ 49 | --port 7863 \ 50 | --checkpoint /path/to/model \ 51 | --classifier_url "http://127.0.0.1:9098/check_hunyin" 52 | ``` 53 | 54 | 如需使用nginx反向代理访问此服务,可参考https://github.com/LeetJoe/lawyer-llama/blob/main/demo/nginx_proxy.md (Credit to [@LeetJoe](https://github.com/LeetJoe)) 55 | -------------------------------------------------------------------------------- /demo/run_inference_v2.md: -------------------------------------------------------------------------------- 1 | # 模型推理 2 | 我们目前公开的最新版本Lawyer LLaMA是: 3 | * **Lawyer LLaMA 2 (`lawyer-llama-13b-v2`)**: 以[quzhe/llama_chinese_13B](https://huggingface.co/quzhe/llama_chinese_13B)为底座,使用通用instruction和法律instruction进行SFT,配有婚姻相关法律检索模块。 4 | 5 | ## 运行环境 6 | 建议使用Python 3.8及以上版本。 7 | 8 | 主要依赖库如下: 9 | * `transformers` >= 4.28.0 **注意:检索模块需要使用transformers <= 4.30** 10 | * `sentencepiece` >= 0.1.97 11 | * `gradio` 12 | 13 | ## 获取模型 14 | 1. 从[HuggingFace](https://huggingface.co/pkupie/lawyer-llama-13b-v2)下载 **Lawyer LLaMA 2 (`lawyer-llama-13b-v2`)**模型参数。 15 | 16 | 17 | 4. 从[HuggingFace](https://huggingface.co/pkupie/marriage_law_retrieval)下载法条检索模块,并运行其中的`python server.py`启动法条检索服务,默认挂在9098端口。 18 | 19 | ## 模型运行 20 | ### 使用命令行运行 21 | ```bash 22 | python demo_cmd.py \ 23 | --checkpoint /path/to/model \ 24 | --classifier_url "http://127.0.0.1:9098/check_hunyin" \ 25 | --use_chat_mode 26 | ``` 27 | 28 | ### 使用交互界面运行 29 | 运行以下命令启动交互网页,访问`http://127.0.0.1:7863`。 30 | ```bash 31 | python demo_web.py \ 32 | --port 7863 \ 33 | --checkpoint /path/to/model \ 34 | --classifier_url "http://127.0.0.1:9098/check_hunyin" 35 | ``` 36 | 37 | 如需使用nginx反向代理访问此服务,可参考https://github.com/LeetJoe/lawyer-llama/blob/main/demo/nginx_proxy.md (Credit to [@LeetJoe](https://github.com/LeetJoe)) 38 | -------------------------------------------------------------------------------- /lawyer_llama_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewZhe/lawyer-llama/abaa09586081b82ceb7b0a9f41d05a68897b24ee/lawyer_llama_report.pdf -------------------------------------------------------------------------------- /scripts/convert_hf-7b_to_llama-pth.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | import shutil 4 | 5 | from tqdm import tqdm 6 | import torch 7 | from transformers import LlamaConfig, LlamaForCausalLM, LlamaTokenizer 8 | 9 | 10 | def convert_model(input_model_path, output_model_path, model_size): 11 | if model_size != '7B': 12 | raise ValueError(f"Unsupported model size: {model_size}") 13 | 14 | # Load model 15 | hf_config = LlamaConfig.from_pretrained(input_model_path) 16 | hf_model = LlamaForCausalLM.from_pretrained(input_model_path, config=hf_config, torch_dtype=torch.float16) 17 | 18 | n_layers = hf_config.num_hidden_layers 19 | n_heads = hf_config.num_attention_heads 20 | dim = hf_config.hidden_size 21 | 22 | # permute for sliced rotary 23 | def permute(w): 24 | return w.view(n_heads, 2, dim // n_heads // 2, dim).transpose(1, 2).reshape(dim, dim) 25 | 26 | # Convert huggingface model to pytorch 27 | hf_state_dict = hf_model.state_dict() 28 | 29 | pth_state_dict = {} 30 | # possibly dangerous: remove last token embed 31 | pth_state_dict["tok_embeddings.weight"] = hf_state_dict["model.embed_tokens.weight"][:-1, :] 32 | pth_state_dict["norm.weight"] = hf_state_dict["model.norm.weight"] 33 | pth_state_dict["output.weight"] = hf_state_dict["lm_head.weight"][:-1, :] 34 | 35 | for layer_i in tqdm(range(n_layers)): 36 | pth_state_dict.update({ 37 | f"layers.{layer_i}.attention.wq.weight": permute( 38 | hf_state_dict[f"model.layers.{layer_i}.self_attn.q_proj.weight"] 39 | ), 40 | f"layers.{layer_i}.attention.wk.weight": permute( 41 | hf_state_dict[f"model.layers.{layer_i}.self_attn.k_proj.weight"] 42 | ), 43 | f"layers.{layer_i}.attention.wv.weight": hf_state_dict[f"model.layers.{layer_i}.self_attn.v_proj.weight"], 44 | f"layers.{layer_i}.attention.wo.weight": hf_state_dict[f"model.layers.{layer_i}.self_attn.o_proj.weight"], 45 | f"layers.{layer_i}.feed_forward.w1.weight": hf_state_dict[f"model.layers.{layer_i}.mlp.gate_proj.weight"], 46 | f"layers.{layer_i}.feed_forward.w2.weight": hf_state_dict[f"model.layers.{layer_i}.mlp.down_proj.weight"], 47 | f"layers.{layer_i}.feed_forward.w3.weight": hf_state_dict[f"model.layers.{layer_i}.mlp.up_proj.weight"], 48 | f"layers.{layer_i}.attention_norm.weight": hf_state_dict[f"model.layers.{layer_i}.input_layernorm.weight"], 49 | f"layers.{layer_i}.ffn_norm.weight": hf_state_dict[f"model.layers.{layer_i}.post_attention_layernorm.weight"], 50 | }) 51 | 52 | for layer_i in range(n_layers): 53 | pth_state_dict[f"layers.{layer_i}.attention.inner_attention.rope.freqs"] = hf_state_dict[f"model.layers.{layer_i}.self_attn.rotary_emb.inv_freq"] 54 | 55 | # Save model 56 | torch.save(pth_state_dict, output_model_path) 57 | 58 | 59 | def convert_tokenizer(input_tokenizer_path, output_tokenizer_path): 60 | shutil.copyfile(os.path.join(input_tokenizer_path, "tokenizer.model"), os.path.join(output_tokenizer_path, "tokenizer.model")) 61 | 62 | 63 | if __name__ == '__main__': 64 | parser = argparse.ArgumentParser() 65 | parser.add_argument( 66 | "--hf_model_path", 67 | type=str, 68 | help="Path to the HuggingFace model", 69 | ) 70 | parser.add_argument( 71 | "--hf_tokenizer_path", 72 | type=str, 73 | help="Path to the HuggingFace tokenizer", 74 | ) 75 | parser.add_argument( 76 | "--output_dir", 77 | type=str, 78 | default="tmp", 79 | help="Path to the output directory", 80 | ) 81 | 82 | args = parser.parse_args() 83 | 84 | if not os.path.exists(args.output_dir): 85 | os.makedirs(args.output_dir) 86 | 87 | convert_model(args.hf_model_path, os.path.join(args.output_dir, "consolidated.00.pth"), "7B") 88 | 89 | convert_tokenizer(args.hf_tokenizer_path, args.output_dir) 90 | 91 | -------------------------------------------------------------------------------- /scripts/model_delta.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | import torch 4 | from tqdm import tqdm 5 | from transformers import AutoTokenizer, AutoModelForCausalLM 6 | 7 | # reference: https://github.com/lm-sys/FastChat/blob/main/fastchat/model 8 | 9 | def make_delta(base_model_path, target_model_path, delta_path): 10 | print(f"Loading the base model from {base_model_path}") 11 | base = AutoModelForCausalLM.from_pretrained( 12 | base_model_path, low_cpu_mem_usage=True) 13 | 14 | print(f"Loading the target model from {target_model_path}") 15 | target = AutoModelForCausalLM.from_pretrained(target_model_path, low_cpu_mem_usage=True) 16 | 17 | ''' 18 | Problem Shooting: 19 | RuntimeError: The size of tensor a (32001) must match the size of tensor b (32000) at non-singleton dimension 0 20 | model.embed_tokens.weight 21 | 因为aplaca的词表加了一维 22 | 所以需要对原始llama的的输入输出层进行resize 23 | 代码来自于alpaca的smart_tokenizer_and_embedding_resize 24 | ''' 25 | # special treatment to the input and output embedding of the base model 26 | base_vocab_size = base.config.vocab_size 27 | target_vocab_size = target.config.vocab_size 28 | if base_vocab_size != target_vocab_size: 29 | print("Resizing the input and output embedding of the base model") 30 | num_new_tokens = target_vocab_size - base_vocab_size 31 | print(f"Base model vocab size: {base_vocab_size}") 32 | print(f"Number of new tokens: {num_new_tokens}") 33 | base.resize_token_embeddings(base_vocab_size + num_new_tokens) 34 | 35 | input_embeddings = base.get_input_embeddings().weight.data 36 | output_embeddings = base.get_output_embeddings().weight.data 37 | 38 | input_embeddings_avg = input_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True) 39 | output_embeddings_avg = output_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True) 40 | 41 | input_embeddings[-num_new_tokens:] = input_embeddings_avg 42 | output_embeddings[-num_new_tokens:] = output_embeddings_avg 43 | 44 | 45 | print("Calculating the delta") 46 | for name, param in tqdm(target.state_dict().items(), desc="Calculating delta"): 47 | # print(name) 48 | assert name in base.state_dict() 49 | param.data -= base.state_dict()[name] 50 | 51 | print(f"Saving the delta to {delta_path}") 52 | 53 | target.save_pretrained(delta_path) 54 | 55 | 56 | def apply_delta(base_model_path, target_model_path, delta_path): 57 | print(f"Loading the base model from {base_model_path}") 58 | base = AutoModelForCausalLM.from_pretrained( 59 | base_model_path, low_cpu_mem_usage=True) 60 | 61 | print(f"Loading the delta from {delta_path}") 62 | delta = AutoModelForCausalLM.from_pretrained(delta_path, low_cpu_mem_usage=True) 63 | 64 | # special treatment to the input and output embedding of the base model 65 | base_vocab_size = base.config.vocab_size 66 | delta_vocab_size = delta.config.vocab_size 67 | if base_vocab_size != delta_vocab_size: 68 | print("Resizing the input and output embedding of the base model") 69 | num_new_tokens = delta_vocab_size - base_vocab_size 70 | print(f"Base model vocab size: {base_vocab_size}") 71 | print(f"Number of new tokens: {num_new_tokens}") 72 | base.resize_token_embeddings(base_vocab_size + num_new_tokens) 73 | 74 | input_embeddings = base.get_input_embeddings().weight.data 75 | output_embeddings = base.get_output_embeddings().weight.data 76 | 77 | input_embeddings_avg = input_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True) 78 | output_embeddings_avg = output_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True) 79 | 80 | input_embeddings[-num_new_tokens:] = input_embeddings_avg 81 | output_embeddings[-num_new_tokens:] = output_embeddings_avg 82 | 83 | print("Applying the delta") 84 | for name, param in tqdm(base.state_dict().items(), desc="Applying delta"): 85 | # print(name) 86 | assert name in delta.state_dict() 87 | param.data += delta.state_dict()[name] 88 | 89 | print(f"Saving the target model to {target_model_path}") 90 | base.save_pretrained(target_model_path) 91 | 92 | 93 | def check_model_equality(model1_path, model2_path): 94 | print("Loading model1 from", model1_path) 95 | model1 = AutoModelForCausalLM.from_pretrained(model1_path, low_cpu_mem_usage=True) 96 | print("Loading model2 from", model2_path) 97 | model2 = AutoModelForCausalLM.from_pretrained(model2_path, low_cpu_mem_usage=True) 98 | 99 | for name, param in model1.state_dict().items(): 100 | print(name) 101 | assert name in model2.state_dict() 102 | assert torch.allclose(param, model2.state_dict()[name]) 103 | 104 | print("All parameters are equal") 105 | 106 | if __name__ == '__main__': 107 | parser = argparse.ArgumentParser() 108 | parser.add_argument("--base-model-path", type=str, required=True) 109 | parser.add_argument("--target-model-path", type=str, required=True) 110 | parser.add_argument("--delta-path", type=str) 111 | parser.add_argument("--mode", type=str, required=True, choices=["make_delta", "apply_delta", "check_model_equality"]) 112 | 113 | args = parser.parse_args() 114 | 115 | if args.mode == "make_delta": 116 | make_delta(args.base_model_path, args.target_model_path, args.delta_path) 117 | elif args.mode == "apply_delta": 118 | apply_delta(args.base_model_path, args.target_model_path, args.delta_path) 119 | elif args.mode == "check_model_equality": 120 | check_model_equality(args.base_model_path, args.target_model_path) 121 | --------------------------------------------------------------------------------