ProbablyFaiz commited on
Commit
f897b80
1 Parent(s): 15cafa7

Add usage ex

Browse files
Files changed (2) hide show
  1. README.md +87 -1
  2. tokenizer_config.json +0 -1
README.md CHANGED
@@ -6,4 +6,90 @@ base_model:
6
  - mistralai/Mistral-7B-v0.1
7
  tags:
8
  - legal
9
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  - mistralai/Mistral-7B-v0.1
7
  tags:
8
  - legal
9
+ ---
10
+
11
+ # reglab-rrc/mistral-rrc
12
+
13
+ **Paper:** [AI for Scaling Legal Reform: Mapping and Redacting Racial Covenants in Santa Clara County]()
14
+
15
+
16
+ ## Usage
17
+
18
+ Here is an example of how to use the model to find racial covenants in a page of text:
19
+
20
+ ```python
21
+ from transformers import AutoTokenizer, AutoModelForCausalLM
22
+ import re
23
+
24
+ # Load model and tokenizer
25
+ tokenizer = AutoTokenizer.from_pretrained("reglab/mistral-rrc")
26
+ model = AutoModelForCausalLM.from_pretrained("reglab/mistral-rrc")
27
+
28
+ def format_prompt(document):
29
+ return f"""### Instruction:
30
+ Determine whether the property deed contains a racial covenant. A racial covenant is a clause in a document that \
31
+ restricts who can reside, own, or occupy a property on the basis of race, ethnicity, national origin, or religion. \
32
+ Answer "Yes" or "No". If "Yes", provide the exact text of the relevant passage and then a quotation of the passage \
33
+ with spelling and formatting errors fixed.
34
+
35
+ ### Input:
36
+ {document}
37
+
38
+ ### Response:"""
39
+
40
+ def parse_output(output):
41
+ answer_match = re.search(r"\[ANSWER\](.*?)\[/ANSWER\]", output, re.DOTALL)
42
+ raw_passage_match = re.search(r"\[RAW PASSAGE\](.*?)\[/RAW PASSAGE\]", output, re.DOTALL)
43
+ quotation_match = re.search(r"\[CORRECTED QUOTATION\](.*?)\[/CORRECTED QUOTATION\]", output, re.DOTALL)
44
+
45
+ answer = answer_match.group(1).strip() if answer_match else None
46
+ raw_passage = raw_passage_match.group(1).strip() if raw_passage_match else None
47
+ quotation = quotation_match.group(1).strip() if quotation_match else None
48
+
49
+ return {
50
+ "answer": answer == "Yes",
51
+ "raw_passage": raw_passage,
52
+ "quotation": quotation
53
+ }
54
+
55
+ # Example usage
56
+ document = "Your property deed text here..."
57
+ prompt = format_prompt(document)
58
+ inputs = tokenizer(prompt, return_tensors="pt")
59
+ outputs = model.generate(**inputs, max_new_tokens=512)
60
+ result = tokenizer.decode(outputs[0])
61
+ parsed_result = parse_output(result)
62
+
63
+ print(parsed_result)
64
+ ```
65
+
66
+ The model was trained with the given input and output formats, so be sure to use them
67
+ when performing inference.
68
+
69
+ ## Intended Use
70
+
71
+ This model is designed to detect racial covenants in property deeds.
72
+
73
+ ## Training Data
74
+
75
+
76
+ ## Performance
77
+
78
+
79
+ ## Limitations
80
+
81
+
82
+ ## Ethical Considerations
83
+
84
+
85
+
86
+ ## Citation
87
+
88
+ ```
89
+ @article{suranisuzgun2024,
90
+ title={AI for Scaling Legal Reform: Mapping and Redacting Racial Covenants in Santa Clara County},
91
+ author={Surani, Faiz and Suzgun, Mirac and Raman, Vyoma and Manning, Christopher D. and Henderson, Peter and Ho, Daniel E.},
92
+ journal={},
93
+ year={2024}
94
+ }
95
+ ```
tokenizer_config.json CHANGED
@@ -41,7 +41,6 @@
41
  "sp_model_kwargs": {},
42
  "spaces_between_special_tokens": false,
43
  "tokenizer_class": "LlamaTokenizer",
44
- "tokenizer_file": "/scratch/users/faiz/hf_cache/models--reglab-rrc--mistral-rrc3.3/snapshots/18d20c079ee2a6b18567a9ff73e61281b6e6bf0e/tokenizer.json",
45
  "unk_token": "<unk>",
46
  "use_default_system_prompt": true
47
  }
 
41
  "sp_model_kwargs": {},
42
  "spaces_between_special_tokens": false,
43
  "tokenizer_class": "LlamaTokenizer",
 
44
  "unk_token": "<unk>",
45
  "use_default_system_prompt": true
46
  }