Update README.md
Browse files
README.md
CHANGED
@@ -16,6 +16,7 @@ tags:
|
|
16 |
- sft
|
17 |
---
|
18 |
|
|
|
19 |
# Phi-3.5-Law
|
20 |
|
21 |
## Model Summary
|
@@ -30,16 +31,6 @@ tags:
|
|
30 |
**License:** Apache-2.0
|
31 |
**Finetuned from model:** `microsoft/Phi-3.5-mini-instruct`
|
32 |
|
33 |
-
## Known Issues
|
34 |
-
|
35 |
-
### Model Behavior in Different Environments
|
36 |
-
|
37 |
-
**Google Colab:** The model has been tested successfully on Google Colab, where it performs as expected and provides accurate results.
|
38 |
-
|
39 |
-
**Downloaded Environment:** When downloaded and tested locally, the model may produce gibberish or unexpected outputs. This issue may be due to differences in the runtime environment or configurations between Google Colab and local setups.
|
40 |
-
|
41 |
-
If you encounter issues with the model's performance in a local environment, please ensure that all dependencies are correctly installed and that the runtime environment is properly configured. If the problem persists, consider reaching out for support or checking for any updates or patches.
|
42 |
-
|
43 |
## Intended Uses
|
44 |
|
45 |
### Primary Use Cases
|
@@ -57,231 +48,17 @@ The model is useful for legal professionals who need to quickly locate and under
|
|
57 |
|
58 |
While the model aims to provide accurate results, it may occasionally produce inaccuracies. The AI tool should not be considered legal advice or a substitute for professional judgement. Users should carefully review and verify the results before making any legal decisions or actions.
|
59 |
|
60 |
-
##
|
61 |
-
|
62 |
-
### Setting Up the Server
|
63 |
-
|
64 |
-
To run the model, you need a FastAPI server. Here’s an example script for setting up the server:
|
65 |
-
|
66 |
-
from fastapi import FastAPI, HTTPException, Depends
|
67 |
-
|
68 |
-
from pydantic import BaseModel
|
69 |
-
|
70 |
-
from transformers import pipeline
|
71 |
-
|
72 |
-
import torch
|
73 |
-
|
74 |
-
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
75 |
-
|
76 |
-
import os
|
77 |
-
|
78 |
-
from dotenv import load_dotenv
|
79 |
-
|
80 |
-
|
81 |
-
# Load environment variables from .env file
|
82 |
-
|
83 |
-
load_dotenv()
|
84 |
-
|
85 |
-
app = FastAPI()
|
86 |
-
|
87 |
-
token_auth_scheme = HTTPBearer()
|
88 |
-
|
89 |
-
|
90 |
-
# Retrieve the Hugging Face token from environment variable
|
91 |
-
|
92 |
-
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
93 |
-
|
94 |
-
|
95 |
-
# Initialize the pipeline
|
96 |
-
|
97 |
-
model_id = "DanielShaw98/phi-3.5-law"
|
98 |
-
|
99 |
-
model_pipeline = pipeline(
|
100 |
-
|
101 |
-
"text-generation",
|
102 |
-
|
103 |
-
model=model_id,
|
104 |
-
|
105 |
-
model_kwargs={"torch_dtype": torch.bfloat16},
|
106 |
-
|
107 |
-
device_map="auto" # Requires accelerate to work properly
|
108 |
-
|
109 |
-
)
|
110 |
-
|
111 |
-
|
112 |
-
class Message(BaseModel):
|
113 |
-
|
114 |
-
role: str
|
115 |
-
|
116 |
-
content: str
|
117 |
-
|
118 |
-
|
119 |
-
class RequestBody(BaseModel):
|
120 |
-
|
121 |
-
messages: list[Message]
|
122 |
-
|
123 |
-
max_new_tokens: int
|
124 |
-
|
125 |
-
|
126 |
-
# Function to verify token
|
127 |
-
|
128 |
-
async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(token_auth_scheme)):
|
129 |
-
|
130 |
-
token = credentials.credentials
|
131 |
-
|
132 |
-
if token != HUGGINGFACE_TOKEN:
|
133 |
-
|
134 |
-
raise HTTPException(status_code=401, detail="Invalid or missing token")
|
135 |
-
|
136 |
-
return token
|
137 |
-
|
138 |
-
|
139 |
-
@app.post("/generate")
|
140 |
-
|
141 |
-
async def generate_text(request_body: RequestBody, token: str = Depends(verify_token)):
|
142 |
-
|
143 |
-
try:
|
144 |
-
|
145 |
-
outputs = model_pipeline(
|
146 |
-
|
147 |
-
[{"role": msg.role, "content": msg.content} for msg in request_body.messages],
|
148 |
-
|
149 |
-
max_new_tokens=request_body.max_new_tokens,
|
150 |
-
|
151 |
-
)
|
152 |
-
|
153 |
-
return {"generated_text": outputs[0]["generated_text"]}
|
154 |
-
|
155 |
-
except Exception as e:
|
156 |
-
|
157 |
-
raise HTTPException(status_code=500, detail=str(e))
|
158 |
-
|
159 |
-
|
160 |
-
if __name__ == "__main__":
|
161 |
-
|
162 |
-
import uvicorn
|
163 |
-
|
164 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
165 |
|
166 |
-
|
167 |
|
168 |
-
|
169 |
|
170 |
-
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
require('dotenv').config(); // Make sure to install dotenv
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
// Retrieve the token from environment variables
|
179 |
-
|
180 |
-
const HUGGINGFACE_TOKEN = process.env.HUGGINGFACE_TOKEN;
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
const requestBody = {
|
185 |
-
|
186 |
-
messages: [
|
187 |
-
|
188 |
-
{ role: "system",
|
189 |
-
|
190 |
-
content: `You are Legal AI. Your job is to help lawyers by identifying specific clauses in merger and acquisition contracts.
|
191 |
-
|
192 |
-
Please identify the desired clauses and also provide an explanation for this choice based on the prompt.
|
193 |
-
|
194 |
-
If the requested clause cannot be found, please respond with 'nothing found.'
|
195 |
-
|
196 |
-
Otherwise please provide a response in the following JSON format:
|
197 |
-
|
198 |
-
{
|
199 |
-
|
200 |
-
"entries": [
|
201 |
-
|
202 |
-
{
|
203 |
-
|
204 |
-
"page": <page_number>,
|
205 |
-
|
206 |
-
"line_start": <clause_start_line_within_chunk>,
|
207 |
-
|
208 |
-
"line_end": <clause_end_line_within_chunk>,
|
209 |
-
|
210 |
-
"clause": <clause_text>,
|
211 |
-
|
212 |
-
"explanation": <explanation_text>
|
213 |
-
|
214 |
-
}
|
215 |
-
|
216 |
-
]
|
217 |
-
|
218 |
-
}`
|
219 |
-
|
220 |
-
},
|
221 |
-
|
222 |
-
{ role: "user",
|
223 |
-
|
224 |
-
content: `Prompt: Review the provided text and identify all clauses related to termination rights and conditions.
|
225 |
-
|
226 |
-
Return the exact start and end line numbers of the relevant clause within the chunk. If you cannot find anything relevant, please respond with 'nothing found.'
|
227 |
-
|
228 |
-
Please provide details in the following JSON format:
|
229 |
-
|
230 |
-
{ "relevant_chunks_found": <number>, "entries": [ { "page": <page_number>,
|
231 |
-
|
232 |
-
"line_start": <clause_start_line_within_chunk>, "line_end": <clause_end_line_within_chunk>,
|
233 |
-
|
234 |
-
"clause": <clause_text>, "explanation": <explanation_text> } ]}\n\n
|
235 |
-
|
236 |
-
Chunk: Transaction but all the conditions therein have been satisfied or complied with, \nor confirmed no such clearance is required in accordance with the applicable \ncompetition legislation, or has not objected to the Transaction within the time \nperiod prescribed by law.
|
237 |
-
|
238 |
-
\n227876-4-1460-v9.0 \n- 30 - \n70-40688062 \n \nFor the purposes of clauses 4.1.10 to 4.1.12 (inclusive) only, "Transaction" shall \nbe limited to the part or parts of the Transaction required to be notified to the \nCommission, COFECE or the competent competition authority of Vietnam (as \nappropriate).
|
239 |
-
|
240 |
-
\nNo material breach \n4.1.13 no Purchaser Covenant Breach and no Purchaser Material Breach having \noccurred; and \n4.1.14 no Chrysaor Covenant Breach and no Chrysaor Material Breach having \noccurred. \n4.2 \nAny Regulatory Condition or Antitrust Condition may be waived at any time on or \nbefore 17.00 on the Longstop Date by written agreement of the Company and the \nPurchaser.
|
241 |
-
|
242 |
-
Any Chrysaor Material Breach may be waived at any time on or before \n17.00 on the Longstop Date by the Purchaser by notice in writing to the Company. Any \nPurchaser Material Breach may be waived at any time on or before 17.00 on the \nLongstop Date by the Company by notice in writing to the Purchaser.
|
243 |
-
|
244 |
-
\n4.3 \nIf, at any time, any party becomes aware of a fact, matter or circumstance that could \nreasonably be expected to prevent or delay the satisfaction of a Condition, it shall \ninform the others of the fact, matter or circumstance as soon as reasonably practicable.
|
245 |
-
|
246 |
-
\n4.4 \nIf a Condition has not been satisfied or (if capable of waiver) waived by 17.00 on the \nLongstop Date or becomes impossible to satisfy before that time, either the \nHarbour/Chrysaor Parties or the Purchaser may terminate this Agreement by notice in \nwriting to that effect to the other, save that the Harbour/Chrysaor Parties may only \nterminate this Agreement: (i) on the basis of the Whitewash Condition not having been \nsatisfied by 17.00 on the Longstop Date or having become impossible to satisfy before
|
247 |
-
|
248 |
-
\nthat time; and (ii) on the basis of the Circular Condition and/or the FCA Admission \nCondition not having been satisfied by 17.00 on the Longstop Date or having become \nimpossible to satisfy before that time, in each case, only if the Harbour/Chrysaor Parties \nhave complied with the relevant provisions of clause 5 and/or the Purchaser has not \ncomplied with the relevant provisions of clause 5. \n4.5\n\n Chunk Meta-Data:\nPage Start: 30\n Page End: 31\nLine Start: 1405\n Line End: 1445`
|
249 |
-
|
250 |
-
}
|
251 |
-
|
252 |
-
],
|
253 |
-
|
254 |
-
max_new_tokens: 256
|
255 |
-
|
256 |
-
};
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
axios.post('http://localhost:8000/generate', requestBody, {
|
261 |
-
|
262 |
-
headers: {
|
263 |
-
|
264 |
-
'Authorization': `Bearer ${HUGGINGFACE_TOKEN}`,
|
265 |
-
|
266 |
-
'Content-Type': 'application/json'
|
267 |
-
|
268 |
-
}
|
269 |
-
|
270 |
-
})
|
271 |
-
|
272 |
-
.then(response => {
|
273 |
-
|
274 |
-
console.log('Response:', response.data);
|
275 |
-
|
276 |
-
})
|
277 |
-
|
278 |
-
.catch(error => {
|
279 |
-
|
280 |
-
console.error('Error:', error.response ? error.response.data : error.message);
|
281 |
-
|
282 |
-
});
|
283 |
|
284 |
-
|
285 |
|
286 |
## Disclaimer
|
287 |
|
|
|
16 |
- sft
|
17 |
---
|
18 |
|
19 |
+
|
20 |
# Phi-3.5-Law
|
21 |
|
22 |
## Model Summary
|
|
|
31 |
**License:** Apache-2.0
|
32 |
**Finetuned from model:** `microsoft/Phi-3.5-mini-instruct`
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
## Intended Uses
|
35 |
|
36 |
### Primary Use Cases
|
|
|
48 |
|
49 |
While the model aims to provide accurate results, it may occasionally produce inaccuracies. The AI tool should not be considered legal advice or a substitute for professional judgement. Users should carefully review and verify the results before making any legal decisions or actions.
|
50 |
|
51 |
+
## Usage Instructions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
### Environment: Google Colab
|
54 |
|
55 |
+
This model is designed to run in a **Google Colab environment**. Due to the significant hardware requirements and configurations necessary for optimal performance, it is **not recommended** to run the model locally. Google Colab's powerful infrastructure is well-suited to handle the resource demands of the model, ensuring accurate and reliable results.
|
56 |
|
57 |
+
Attempting to run the model in a local environment could result in suboptimal performance, including possible errors or incomplete outputs, due to hardware limitations.
|
58 |
|
59 |
+
### Work in Progress
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
Please note that this model is still a **work in progress**, and ongoing improvements are being made. While it performs well in Google Colab, further refinements and updates will be released to enhance the model's capabilities. Be sure to check back for updates or follow the repository for any changes.
|
62 |
|
63 |
## Disclaimer
|
64 |
|