Spaces:
Runtime error
Runtime error
Rami Nasser
commited on
Commit
•
8fbc997
1
Parent(s):
dd034f2
judge list new model
Browse files- app.py +11 -12
- j_year.json +331 -0
- utils/__init__.py +0 -16
app.py
CHANGED
@@ -2,8 +2,9 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
from utils import *
|
4 |
from datasets import load_dataset
|
|
|
5 |
|
6 |
-
pipe = pipeline(model="raminass/
|
7 |
all = load_dataset("raminass/full_opinions_1994_2020")
|
8 |
df = pd.DataFrame(all["train"])
|
9 |
choices = []
|
@@ -11,11 +12,9 @@ for index, row in df[df.category == "per_curiam"].iterrows():
|
|
11 |
if len(row["text"]) > 1000:
|
12 |
choices.append((f"""{row["case_name"]}""", [row["text"], row["year_filed"]]))
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
)
|
17 |
-
additional_judges = ["Justice Breyer", "Justice Kennedy"]
|
18 |
-
unique_judges_by_year[1994] = list(unique_judges_by_year[1994]) + additional_judges
|
19 |
|
20 |
|
21 |
# https://www.gradio.app/guides/controlling-layout
|
@@ -32,8 +31,8 @@ def set_input(drop):
|
|
32 |
|
33 |
def update_year(year):
|
34 |
return gr.CheckboxGroup(
|
35 |
-
|
36 |
-
value=
|
37 |
label="Select Judges",
|
38 |
)
|
39 |
|
@@ -48,14 +47,14 @@ with gr.Blocks() as demo:
|
|
48 |
)
|
49 |
year = gr.Slider(
|
50 |
1994,
|
51 |
-
|
52 |
step=1,
|
53 |
label="Year",
|
54 |
info="Select the year of the opinion if you manually pass the opinion below",
|
55 |
)
|
56 |
exc_judg = gr.CheckboxGroup(
|
57 |
-
|
58 |
-
value=
|
59 |
label="Select Judges",
|
60 |
info="Select judges to consider in prediction",
|
61 |
)
|
@@ -96,4 +95,4 @@ with gr.Blocks() as demo:
|
|
96 |
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
-
demo.launch(
|
|
|
2 |
from transformers import pipeline
|
3 |
from utils import *
|
4 |
from datasets import load_dataset
|
5 |
+
import json
|
6 |
|
7 |
+
pipe = pipeline(model="raminass/94-23", top_k=17, padding=True, truncation=True)
|
8 |
all = load_dataset("raminass/full_opinions_1994_2020")
|
9 |
df = pd.DataFrame(all["train"])
|
10 |
choices = []
|
|
|
12 |
if len(row["text"]) > 1000:
|
13 |
choices.append((f"""{row["case_name"]}""", [row["text"], row["year_filed"]]))
|
14 |
|
15 |
+
with open("j_year.json", "r") as j:
|
16 |
+
judges_by_year = json.loads(j.read())
|
17 |
+
judges_by_year = {int(k): v for k, v in judges_by_year.items()}
|
|
|
|
|
18 |
|
19 |
|
20 |
# https://www.gradio.app/guides/controlling-layout
|
|
|
31 |
|
32 |
def update_year(year):
|
33 |
return gr.CheckboxGroup(
|
34 |
+
judges_by_year[year],
|
35 |
+
value=judges_by_year[year],
|
36 |
label="Select Judges",
|
37 |
)
|
38 |
|
|
|
47 |
)
|
48 |
year = gr.Slider(
|
49 |
1994,
|
50 |
+
2023,
|
51 |
step=1,
|
52 |
label="Year",
|
53 |
info="Select the year of the opinion if you manually pass the opinion below",
|
54 |
)
|
55 |
exc_judg = gr.CheckboxGroup(
|
56 |
+
judges_by_year[year.value],
|
57 |
+
value=judges_by_year[year.value],
|
58 |
label="Select Judges",
|
59 |
info="Select judges to consider in prediction",
|
60 |
)
|
|
|
95 |
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
+
demo.launch()
|
j_year.json
ADDED
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"1994": [
|
3 |
+
"Rehnquist",
|
4 |
+
"Stevens",
|
5 |
+
"Scalia",
|
6 |
+
"O'Connor",
|
7 |
+
"Ginsburg",
|
8 |
+
"Thomas",
|
9 |
+
"Souter",
|
10 |
+
"Breyer",
|
11 |
+
"Kennedy"
|
12 |
+
],
|
13 |
+
"1995": [
|
14 |
+
"Scalia",
|
15 |
+
"Stevens",
|
16 |
+
"Ginsburg",
|
17 |
+
"Breyer",
|
18 |
+
"Souter",
|
19 |
+
"O'Connor",
|
20 |
+
"Thomas",
|
21 |
+
"Kennedy",
|
22 |
+
"Rehnquist"
|
23 |
+
],
|
24 |
+
"1996": [
|
25 |
+
"Scalia",
|
26 |
+
"Stevens",
|
27 |
+
"Rehnquist",
|
28 |
+
"Souter",
|
29 |
+
"O'Connor",
|
30 |
+
"Kennedy",
|
31 |
+
"Breyer",
|
32 |
+
"Ginsburg",
|
33 |
+
"Thomas"
|
34 |
+
],
|
35 |
+
"1997": [
|
36 |
+
"Ginsburg",
|
37 |
+
"Stevens",
|
38 |
+
"Souter",
|
39 |
+
"Thomas",
|
40 |
+
"Rehnquist",
|
41 |
+
"Breyer",
|
42 |
+
"Scalia",
|
43 |
+
"O'Connor",
|
44 |
+
"Kennedy"
|
45 |
+
],
|
46 |
+
"1998": [
|
47 |
+
"Scalia",
|
48 |
+
"Thomas",
|
49 |
+
"Stevens",
|
50 |
+
"Breyer",
|
51 |
+
"Rehnquist",
|
52 |
+
"Souter",
|
53 |
+
"Kennedy",
|
54 |
+
"O'Connor",
|
55 |
+
"Ginsburg"
|
56 |
+
],
|
57 |
+
"1999": [
|
58 |
+
"Breyer",
|
59 |
+
"Rehnquist",
|
60 |
+
"Souter",
|
61 |
+
"Thomas",
|
62 |
+
"Stevens",
|
63 |
+
"Kennedy",
|
64 |
+
"Scalia",
|
65 |
+
"Ginsburg",
|
66 |
+
"O'Connor"
|
67 |
+
],
|
68 |
+
"2000": [
|
69 |
+
"O'Connor",
|
70 |
+
"Breyer",
|
71 |
+
"Ginsburg",
|
72 |
+
"Kennedy",
|
73 |
+
"Rehnquist",
|
74 |
+
"Scalia",
|
75 |
+
"Souter",
|
76 |
+
"Stevens",
|
77 |
+
"Thomas"
|
78 |
+
],
|
79 |
+
"2001": [
|
80 |
+
"Stevens",
|
81 |
+
"Kennedy",
|
82 |
+
"Thomas",
|
83 |
+
"Scalia",
|
84 |
+
"Breyer",
|
85 |
+
"Ginsburg",
|
86 |
+
"Rehnquist",
|
87 |
+
"O'Connor",
|
88 |
+
"Souter"
|
89 |
+
],
|
90 |
+
"2002": [
|
91 |
+
"Rehnquist",
|
92 |
+
"Stevens",
|
93 |
+
"Thomas",
|
94 |
+
"Souter",
|
95 |
+
"Breyer",
|
96 |
+
"Ginsburg",
|
97 |
+
"Scalia",
|
98 |
+
"Kennedy",
|
99 |
+
"O'Connor"
|
100 |
+
],
|
101 |
+
"2003": [
|
102 |
+
"Scalia",
|
103 |
+
"Souter",
|
104 |
+
"Kennedy",
|
105 |
+
"Stevens",
|
106 |
+
"Thomas",
|
107 |
+
"O'Connor",
|
108 |
+
"Breyer",
|
109 |
+
"Rehnquist",
|
110 |
+
"Ginsburg"
|
111 |
+
],
|
112 |
+
"2004": [
|
113 |
+
"Ginsburg",
|
114 |
+
"Stevens",
|
115 |
+
"Kennedy",
|
116 |
+
"Thomas",
|
117 |
+
"Scalia",
|
118 |
+
"Breyer",
|
119 |
+
"Souter",
|
120 |
+
"Rehnquist",
|
121 |
+
"O'Connor"
|
122 |
+
],
|
123 |
+
"2005": [
|
124 |
+
"Ginsburg",
|
125 |
+
"Thomas",
|
126 |
+
"Stevens",
|
127 |
+
"Breyer",
|
128 |
+
"Souter",
|
129 |
+
"Kennedy",
|
130 |
+
"Roberts",
|
131 |
+
"Scalia",
|
132 |
+
"O'Connor",
|
133 |
+
"Rehnquist"
|
134 |
+
],
|
135 |
+
"2006": [
|
136 |
+
"Breyer",
|
137 |
+
"Stevens",
|
138 |
+
"Souter",
|
139 |
+
"Thomas",
|
140 |
+
"Ginsburg",
|
141 |
+
"Scalia",
|
142 |
+
"Alito",
|
143 |
+
"Kennedy",
|
144 |
+
"Roberts",
|
145 |
+
"O'Connor"
|
146 |
+
],
|
147 |
+
"2007": [
|
148 |
+
"Ginsburg",
|
149 |
+
"Scalia",
|
150 |
+
"Thomas",
|
151 |
+
"Alito",
|
152 |
+
"Stevens",
|
153 |
+
"Kennedy",
|
154 |
+
"Breyer",
|
155 |
+
"Souter",
|
156 |
+
"Roberts"
|
157 |
+
],
|
158 |
+
"2008": [
|
159 |
+
"Thomas",
|
160 |
+
"Breyer",
|
161 |
+
"Ginsburg",
|
162 |
+
"Kennedy",
|
163 |
+
"Roberts",
|
164 |
+
"Scalia",
|
165 |
+
"Stevens",
|
166 |
+
"Souter",
|
167 |
+
"Alito"
|
168 |
+
],
|
169 |
+
"2009": [
|
170 |
+
"Scalia",
|
171 |
+
"Kennedy",
|
172 |
+
"Breyer",
|
173 |
+
"Ginsburg",
|
174 |
+
"Thomas",
|
175 |
+
"Stevens",
|
176 |
+
"Alito",
|
177 |
+
"Sotomayor",
|
178 |
+
"Roberts",
|
179 |
+
"Souter"
|
180 |
+
],
|
181 |
+
"2010": [
|
182 |
+
"Breyer",
|
183 |
+
"Scalia",
|
184 |
+
"Kennedy",
|
185 |
+
"Stevens",
|
186 |
+
"Sotomayor",
|
187 |
+
"Alito",
|
188 |
+
"Ginsburg",
|
189 |
+
"Thomas",
|
190 |
+
"Roberts"
|
191 |
+
],
|
192 |
+
"2011": [
|
193 |
+
"Kennedy",
|
194 |
+
"Breyer",
|
195 |
+
"Scalia",
|
196 |
+
"Thomas",
|
197 |
+
"Ginsburg",
|
198 |
+
"Sotomayor",
|
199 |
+
"Alito",
|
200 |
+
"Kagan",
|
201 |
+
"Roberts"
|
202 |
+
],
|
203 |
+
"2012": [
|
204 |
+
"Kennedy",
|
205 |
+
"Ginsburg",
|
206 |
+
"Breyer",
|
207 |
+
"Roberts",
|
208 |
+
"Alito",
|
209 |
+
"Thomas",
|
210 |
+
"Sotomayor",
|
211 |
+
"Scalia",
|
212 |
+
"Kagan"
|
213 |
+
],
|
214 |
+
"2013": [
|
215 |
+
"Ginsburg",
|
216 |
+
"Alito",
|
217 |
+
"Breyer",
|
218 |
+
"Kennedy",
|
219 |
+
"Scalia",
|
220 |
+
"Roberts",
|
221 |
+
"Thomas",
|
222 |
+
"Sotomayor",
|
223 |
+
"Kagan"
|
224 |
+
],
|
225 |
+
"2014": [
|
226 |
+
"Roberts",
|
227 |
+
"Thomas",
|
228 |
+
"Breyer",
|
229 |
+
"Kagan",
|
230 |
+
"Ginsburg",
|
231 |
+
"Scalia",
|
232 |
+
"Sotomayor",
|
233 |
+
"Kennedy",
|
234 |
+
"Alito"
|
235 |
+
],
|
236 |
+
"2015": [
|
237 |
+
"Breyer",
|
238 |
+
"Sotomayor",
|
239 |
+
"Roberts",
|
240 |
+
"Thomas",
|
241 |
+
"Alito",
|
242 |
+
"Scalia",
|
243 |
+
"Kagan",
|
244 |
+
"Ginsburg",
|
245 |
+
"Kennedy"
|
246 |
+
],
|
247 |
+
"2016": [
|
248 |
+
"Ginsburg",
|
249 |
+
"Thomas",
|
250 |
+
"Roberts",
|
251 |
+
"Alito",
|
252 |
+
"Breyer",
|
253 |
+
"Sotomayor",
|
254 |
+
"Kagan",
|
255 |
+
"Kennedy",
|
256 |
+
"Scalia"
|
257 |
+
],
|
258 |
+
"2017": [
|
259 |
+
"Ginsburg",
|
260 |
+
"Thomas",
|
261 |
+
"Sotomayor",
|
262 |
+
"Kagan",
|
263 |
+
"Kennedy",
|
264 |
+
"Alito",
|
265 |
+
"Breyer",
|
266 |
+
"Roberts"
|
267 |
+
],
|
268 |
+
"2018": [
|
269 |
+
"Kennedy",
|
270 |
+
"Kagan",
|
271 |
+
"Ginsburg",
|
272 |
+
"Thomas",
|
273 |
+
"Breyer",
|
274 |
+
"Alito",
|
275 |
+
"Sotomayor",
|
276 |
+
"Roberts"
|
277 |
+
],
|
278 |
+
"2019": [
|
279 |
+
"Thomas",
|
280 |
+
"Ginsburg",
|
281 |
+
"Alito",
|
282 |
+
"Breyer",
|
283 |
+
"Sotomayor",
|
284 |
+
"Kagan",
|
285 |
+
"Roberts"
|
286 |
+
],
|
287 |
+
"2020": [
|
288 |
+
"Alito",
|
289 |
+
"Kagan",
|
290 |
+
"Breyer",
|
291 |
+
"Sotomayor",
|
292 |
+
"Ginsburg",
|
293 |
+
"Thomas",
|
294 |
+
"Roberts",
|
295 |
+
"Kavanaugh",
|
296 |
+
"Gorsuch"
|
297 |
+
],
|
298 |
+
"2021": [
|
299 |
+
"Kagan",
|
300 |
+
"Breyer",
|
301 |
+
"Sotomayor",
|
302 |
+
"Gorsuch",
|
303 |
+
"Roberts",
|
304 |
+
"Thomas",
|
305 |
+
"Alito",
|
306 |
+
"Kavanaugh",
|
307 |
+
"Barrett"
|
308 |
+
],
|
309 |
+
"2022": [
|
310 |
+
"Kagan",
|
311 |
+
"Breyer",
|
312 |
+
"Sotomayor",
|
313 |
+
"Gorsuch",
|
314 |
+
"Roberts",
|
315 |
+
"Thomas",
|
316 |
+
"Alito",
|
317 |
+
"Kavanaugh",
|
318 |
+
"Barrett"
|
319 |
+
],
|
320 |
+
"2023": [
|
321 |
+
"Kagan",
|
322 |
+
"Jackson",
|
323 |
+
"Sotomayor",
|
324 |
+
"Gorsuch",
|
325 |
+
"Roberts",
|
326 |
+
"Thomas",
|
327 |
+
"Alito",
|
328 |
+
"Kavanaugh",
|
329 |
+
"Barrett"
|
330 |
+
]
|
331 |
+
}
|
utils/__init__.py
CHANGED
@@ -37,19 +37,3 @@ def average_text(text, model, judges):
|
|
37 |
sumary = {k: round(sum(v) / len(v), 2) for k, v in pred.items()}
|
38 |
sumary = normaliz_dict(sumary)
|
39 |
return dict(sorted(sumary.items(), key=lambda x: x[1], reverse=True)), new_res
|
40 |
-
|
41 |
-
|
42 |
-
# def find_case_by_name(df, name):
|
43 |
-
# return display(
|
44 |
-
# HTML(
|
45 |
-
# df[df["case_name"].str.contains(name)]
|
46 |
-
# .iloc[:, :-1]
|
47 |
-
# .to_html(render_links=True, escape=False)
|
48 |
-
# )
|
49 |
-
# )
|
50 |
-
|
51 |
-
|
52 |
-
# def head_df(df):
|
53 |
-
# return display(
|
54 |
-
# HTML(df.iloc[:, :-1].head().to_html(render_links=True, escape=False))
|
55 |
-
# )
|
|
|
37 |
sumary = {k: round(sum(v) / len(v), 2) for k, v in pred.items()}
|
38 |
sumary = normaliz_dict(sumary)
|
39 |
return dict(sorted(sumary.items(), key=lambda x: x[1], reverse=True)), new_res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|