-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtasks_scotus.py
786 lines (721 loc) · 25.7 KB
/
tasks_scotus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
import argparse
import inspect
from typing import cast
import pandas as pd
from pandas.core.frame import DataFrame
from api import (
GooglePaLMCompletion,
LlamaChat,
OpenAIChat,
OpenAIChatGpt4,
TogetherAiLlamaChat,
)
from correctness_checks import (
affirm_reverse_correctness,
agreeement_correctness,
bool_correctness,
citation_correctness,
cited_precedent_correctness,
clean_judge_name,
clean_overruling_year,
clean_quotation,
name_correctness,
overruling_correctness,
quotation_correctness,
scotus_court_id_correctness,
)
from models import CourtCase, CourtCasePair, Query, Task
from settings import SCDB_SAMPLE_PATH, SCOTUS_OVERRULED_DB, SCOTUS_SHEPARDS_SAMPLE
from utils import (
APIBackendType,
format_case_name,
get_case_citation_for_scotus_case,
get_disposition_from_scdb_id,
get_judge_name_from_scdb_id,
)
parser = argparse.ArgumentParser()
parser.add_argument(
"--api", type=str, help="api to use", choices=["llama", "gpt3.5", "palm", "gpt4"]
)
args = parser.parse_args()
CURRENT_API: APIBackendType = OpenAIChatGpt4
match args.api:
case "llama":
CURRENT_API = LlamaChat # TogetherAiLlamaChat also okay
case "gpt3.5":
CURRENT_API = OpenAIChat
case "palm":
CURRENT_API = GooglePaLMCompletion
case "gpt4":
CURRENT_API = OpenAIChatGpt4
# Load data
scdb_sample: DataFrame = pd.read_csv(SCDB_SAMPLE_PATH, index_col=False)
# Generate Case objects
cases: list[CourtCase] = [
CourtCase(
case_name=format_case_name(case["caseName"]),
us_citation=case["usCite"],
sct_citation=case["sctCite"],
lexis_citation=case["lexisCite"],
year=case["term"],
majority_author=case["majOpinWriter"],
majority_opinion=case["majority_opinion"],
disposition=case["caseDisposition"],
winner=case["partyWinning"],
court="scotus",
source="scdb",
importance=case["pauth_score"],
)
for case in scdb_sample.to_dict("records")
]
###################################
# Case existence task
###################################
case_existence_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Say "yes" or "no" only.',
query_template="Is the case {case_name}, {case_citation} ({case_year}), a real case? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": "1"}, # parsed as True/"yes" downstream
correctness_callback=bool_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/case_existence",
)
case_existence_task.do()
case_existence_task.save()
###################################
# Case existence task (few shot)
###################################
case_existence_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Say "yes" or "no" only.',
query_template=inspect.cleandoc(
"""
Is the given case a real case? {system_message}
Examples:
```
Case: Brown v. Board of Education, 347 U.S. 483 (1954)
Answer: Yes
Case: Bowers v. Hardwick, 478 U.S. 186 (1986)
Answer: Yes
Case: Columbia University v. Rodham, 564 U.S. 911 (2010)
Answer: No
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": "1"}, # parsed as True/"yes" downstream
correctness_callback=bool_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/case_existence_few_shot",
)
case_existence_task_few_shot.do()
case_existence_task_few_shot.save()
###################################
# Citation retrieval task
###################################
citation_retrieval_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Provide ONLY the citation in "<volume>, <reporter>, <page>" format, nothing else.',
query_template="What is the citation for the case {case_name}? {system_message}",
query_content={"case_name": format_case_name(case.case_name)},
true_answer={"answer": get_case_citation_for_scotus_case(case)},
correctness_callback=citation_correctness,
)
for case in cases
],
sampling_temperature=1,
max_tokens=30,
save_string="scotus/citation_retrieval",
)
citation_retrieval_task.do()
citation_retrieval_task.save()
###################################
# Citation retrieval task (few shot)
###################################
citation_retrieval_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Provide ONLY the citation in "<volume>, <reporter>, <page>" format, nothing else.',
query_template=inspect.cleandoc(
"""
What is the citation for the given case? {system_message}
Examples:
```
Case: Brown v. Board of Education
Answer: 347 U.S. 483
Case: Bowers v. Hardwick
Answer: 478 U.S. 186
Case: McCulloch v. Maryland
Answer: 17 U.S. 316
```
Case: {case_name}
Answer:
"""
),
query_content={"case_name": format_case_name(case.case_name)},
true_answer={"answer": get_case_citation_for_scotus_case(case)},
correctness_callback=citation_correctness,
)
for case in cases
],
sampling_temperature=1,
max_tokens=30,
save_string="scotus/citation_retrieval_few_shot",
)
citation_retrieval_task_few_shot.do()
citation_retrieval_task_few_shot.save()
###################################
# Majority opinion author task
###################################
majority_author_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the first and the last name of the judge ONLY.",
query_template="Who wrote the majority opinion in {case_name}, {case_citation} ({case_year})? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={
"answer": f'{get_judge_name_from_scdb_id(case.majority_author)["first_name"]} {get_judge_name_from_scdb_id(case.majority_author)["last_name"]}'
},
correctness_callback=name_correctness,
llm_answer_postprocess=clean_judge_name,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/majority_author",
)
majority_author_task.do()
majority_author_task.save()
###################################
# Majority opinion author task (few shot)
###################################
majority_author_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the first and the last name of the judge ONLY.",
query_template=inspect.cleandoc(
"""
Who wrote the majority opinion in the given case? {system_message}
Examples:
```
Case: Brown v. Board of Education, 347 U.S. 483 (1954)
Answer: Earl Warren
Case: Bowers v. Hardwick, 478 U.S. 186 (1986)
Answer: Byron White
Case: McCulloch v. Maryland, 17 U.S. 316 (1819)
Answer: John Marshall
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={
"answer": f'{get_judge_name_from_scdb_id(case.majority_author)["first_name"]} {get_judge_name_from_scdb_id(case.majority_author)["last_name"]}'
},
correctness_callback=name_correctness,
llm_answer_postprocess=clean_judge_name,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/majority_author_few_shot",
)
majority_author_task_few_shot.do()
majority_author_task_few_shot.save()
###################################
# Affirm/reverse task
###################################
task_affirm_reverse: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Say "affirm" or "reverse" only.',
query_template="Did the court in {case_name}, {case_citation} ({case_year}) affirm or reverse the lower court's decision? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": get_disposition_from_scdb_id(case.disposition)},
correctness_callback=affirm_reverse_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/affirm_reverse",
)
task_affirm_reverse.do()
task_affirm_reverse.save()
###################################
# Affirm/reverse task (few shot)
###################################
task_affirm_reverse_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Say "affirm" or "reverse" only.',
query_template=inspect.cleandoc(
"""
Did the court in the given case affirm or reverse the lower court's decision? {system_message}
Examples:
```
Case: Plessy v. Ferguson, 163 U.S. 537 (1896)
Answer: Affirm
Case: Bowers v. Hardwick, 478 U.S. 186 (1986)
Answer: Reverse
Case: McCulloch v. Maryland, 17 U.S. 316 (1819)
Answer: Reverse
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": get_disposition_from_scdb_id(case.disposition)},
correctness_callback=affirm_reverse_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/affirm_reverse_few_shot",
)
task_affirm_reverse_few_shot.do()
task_affirm_reverse_few_shot.save()
###################################
# Court ID task
###################################
court_id_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the name of the court ONLY, nothing else.",
query_template="Which court decided the case {case_name}, {case_citation} ({case_year})? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": "Supreme Court"},
correctness_callback=scotus_court_id_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/court_id",
)
court_id_task.do()
court_id_task.save()
###################################
# Court ID task (few shot)
###################################
court_id_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the name of the court ONLY, nothing else.",
query_template=inspect.cleandoc(
"""
Which court decided the given case? {system_message}
Examples:
```
Case: Viacom International Inc. v. YouTube, Inc., 676 F.3d 19 (2012)
Answer: Second Circuit
Case: Durham v. United States, 214 F.2d 862 (1954)
Answer: D.C. Circuit
Case: Bowers v. Hardwick (1986)
Answer: Supreme Court
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": "Supreme Court"},
correctness_callback=scotus_court_id_correctness,
)
for case in cases
],
sampling_temperature=1,
save_string="scotus/court_id_few_shot",
)
court_id_task_few_shot.do()
court_id_task_few_shot.save()
###################################
# Quotation task
###################################
quotation_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="The quotation MUST be word-for-word from the majority opinion. Wrap the quotation in <quote></quote> tags.",
query_template="Provide a verbatim quotation from the majority opinion in the case {case_name}, {case_citation} ({case_year}). {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": cast(str, case.majority_opinion)},
correctness_callback=quotation_correctness,
llm_answer_postprocess=clean_quotation,
)
for case in cases
],
sampling_temperature=-99,
save_string="scotus/quotation",
)
quotation_task.do()
quotation_task.save()
###################################
# Quotation task (few shot)
###################################
quotation_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="The quotation MUST be word-for-word from the majority opinion. Wrap the quotation in <quote></quote> tags.",
query_template=inspect.cleandoc(
"""
Provide a verbatim quotation from the majority opinion in the given case. {system_message}
Examples:
```
Case: Brown v. Board of Education, 347 U.S. 483 (1954)
Answer: <quote>We conclude that in the field of public education the doctrine of "separate but equal" has no place.</quote>
Case: Bowers v. Hardwick, 478 U.S. 186 (1986)
Answer: <quote>It is obvious to us that neither of these formulations would extend a fundamental right to homosexuals to engage in acts of consensual sodomy.</quote>
Case: McConnell v. Federal Election Commission, 540 U.S. 93 (2003)
Answer: <quote>Our cases have made clear that the prevention of corruption or its appearance constitutes a sufficiently important interest to justify political contribution limits.</quote>
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": cast(str, case.majority_opinion)},
correctness_callback=quotation_correctness,
llm_answer_postprocess=clean_quotation,
)
for case in cases
],
sampling_temperature=-99,
save_string="scotus/quotation_few_shot",
)
quotation_task_few_shot.do()
quotation_task_few_shot.save()
###################################
# Cited precedent task
###################################
cited_precedent_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Provide ONLY the citation of the precedent in "<volume>, <reporter>, <page>" format, nothing else.',
query_template="What is a precedent that is cited in the majority opinion of the case {case_name}, {case_citation} ({case_year})? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": cast(str, case.majority_opinion)},
correctness_callback=cited_precedent_correctness,
)
for case in cases
],
sampling_temperature=-99,
save_string="scotus/cited_precedent",
)
cited_precedent_task.do()
cited_precedent_task.save()
###################################
# Cited precedent task (few shot)
###################################
cited_precedent_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message='Provide ONLY the citation of the precedent in "<volume>, <reporter>, <page>" format, nothing else.',
query_template=inspect.cleandoc(
"""
What is a precedent that is cited in the majority opinion of the given case? {system_message}
Examples:
```
Case: Brown v. Board of Education, 347 U.S. 483 (1954)
Answer: Plessy v. Ferguson, 163 U.S. 537
Case: Bowers v. Hardwick, 478 U.S. 186 (1986)
Answer: Griswold v. Connecticut, 381 U.S. 479
Case: McConnell v. Federal Election Commission, 540 U.S. 93 (2003)
Answer: Buckley v. Valeo, 424 U.S. 1
```
Case: {case_name}, {case_citation} ({case_year})
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
"case_year": str(case.year),
},
true_answer={"answer": cast(str, case.majority_opinion)},
correctness_callback=cited_precedent_correctness,
)
for case in cases
],
sampling_temperature=-99,
save_string="scotus/cited_precedent_few_shot",
)
cited_precedent_task_few_shot.do()
cited_precedent_task_few_shot.save()
###################################
# Doctrinal agreement task
###################################
# Load data
scotus_shepards_sample: DataFrame = pd.read_csv(SCOTUS_SHEPARDS_SAMPLE, index_col=False)
# Generate CasePair objects
case_pairs: list[CourtCasePair] = [
CourtCasePair(
citing_case=CourtCase(
case_name=format_case_name(case_pair["citing_case_name"]),
us_citation=case_pair["citing_case_us_cite"],
year=case_pair["citing_case_year"],
importance=0,
majority_author=None,
court="scotus",
source="shepards",
),
cited_case=CourtCase(
case_name=format_case_name(case_pair["cited_case_name"]),
us_citation=case_pair["cited_case_us_cite"],
year=case_pair["cited_case_year"],
importance=0,
majority_author=None,
court="scotus",
source="shepards",
),
positive_relationship=bool(case_pair["agree"]),
source="shepards",
)
for case_pair in scotus_shepards_sample.to_dict("records")
]
# Task
doctrinal_agreement_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case_pair,
system_message='Say "agree" or "disagree" only.',
query_template='Do the cases "{citing_case_name}, {citing_case_citation} ({citing_case_year})" and "{cited_case_name}, {cited_case_citation} ({cited_case_year})" agree or disagree with each other? {system_message}',
query_content={
"citing_case_name": format_case_name(case_pair.citing_case.case_name),
"citing_case_citation": get_case_citation_for_scotus_case(
case_pair.citing_case
),
"citing_case_year": str(case_pair.citing_case.year),
"cited_case_name": format_case_name(case_pair.cited_case.case_name),
"cited_case_citation": get_case_citation_for_scotus_case(
case_pair.cited_case
),
"cited_case_year": str(case_pair.cited_case.year),
},
true_answer={
"answer": str(int(case_pair.positive_relationship))
}, # parsed as True/"yes" downstream
correctness_callback=agreeement_correctness,
)
for case_pair in case_pairs
],
sampling_temperature=1,
save_string="scotus/doctrinal_agreement",
)
doctrinal_agreement_task.do()
doctrinal_agreement_task.save()
# Task (few shot)
doctrinal_agreement_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case_pair,
system_message='Say "agree" or "disagree" only.',
query_template=inspect.cleandoc(
"""
Do the two given cases agree or disagree with each other? {system_message}
Examples:
```
Case 1: Brown v. Board of Education, 347 U.S. 483 (1954)
Case 2: Plessy v. Ferguson, 163 U.S. 537 (1896)
Answer: Disagree
Case 1: Youngstown Sheet & Tube Co. v. Sawyer, 343 U.S. 579 (1952)
Case 2: Medellin v. Texas, 552 U.S. 491 (2008)
Answer: Agree
Case 1: Whitney v. California, 274 U.S. 357 (1927)
Case 2: Brandenburg v. Ohio, 395 U.S. 444 (1969)
Answer: Disagree
```
Case 1: {citing_case_name}, {citing_case_citation} ({citing_case_year})
Case 2: {cited_case_name}, {cited_case_citation} ({cited_case_year})
Answer:
"""
),
query_content={
"citing_case_name": format_case_name(case_pair.citing_case.case_name),
"citing_case_citation": get_case_citation_for_scotus_case(
case_pair.citing_case
),
"citing_case_year": str(case_pair.citing_case.year),
"cited_case_name": format_case_name(case_pair.cited_case.case_name),
"cited_case_citation": get_case_citation_for_scotus_case(
case_pair.cited_case
),
"cited_case_year": str(case_pair.cited_case.year),
},
true_answer={
"answer": str(int(case_pair.positive_relationship))
}, # parsed as True/"yes" downstream
correctness_callback=agreeement_correctness,
)
for case_pair in case_pairs
],
sampling_temperature=1,
save_string="scotus/doctrinal_agreement_few_shot",
)
doctrinal_agreement_task_few_shot.do()
doctrinal_agreement_task_few_shot.save()
###################################
# Overruled year task
###################################
# Load data
overruled_db: DataFrame = pd.read_csv(SCOTUS_OVERRULED_DB, index_col=False)
overruled_db = overruled_db[overruled_db.overruled_in_full == 1]
overruled_db = overruled_db.drop_duplicates(subset=["overruled_case_us_id"])
# Generate Case objects
overruled_cases: list[CourtCase] = [
CourtCase(
case_name=case["overruled_case_name"],
us_citation=case["overruled_case_us_id"],
year=case["overruled_case_year"],
importance=0,
majority_author=None,
special_fact=str(case["year_overruled"]),
court="scotus",
source="overruled_db",
)
for case in overruled_db.to_dict("records")
]
# Task
year_overruled_task: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the year only.",
query_template="What year was {case_name}, {case_citation}, overruled? {system_message}",
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
},
true_answer={"answer": cast(str, case.special_fact)},
correctness_callback=overruling_correctness,
llm_answer_postprocess=clean_overruling_year,
)
for case in overruled_cases
],
sampling_temperature=1,
save_string="scotus/year_overruled",
)
year_overruled_task.do()
year_overruled_task.save()
# Task (few shot)
year_overruled_task_few_shot: Task = Task(
api_backend_type=CURRENT_API,
queries=[
Query(
test_case=case,
system_message="Provide the year only.",
query_template=inspect.cleandoc(
"""
What year was the given case overruled? {system_message}
Examples:
```
Case: Whitney v. California, 274 U.S. 357
Answer: 1969
Case: Austin v. Michigan Chamber of Commerce, 494 U.S. 652
Answer: 2010
```
Case: {case_name}, {case_citation}
Answer:
"""
),
query_content={
"case_name": format_case_name(case.case_name),
"case_citation": get_case_citation_for_scotus_case(case),
},
true_answer={"answer": cast(str, case.special_fact)},
correctness_callback=overruling_correctness,
llm_answer_postprocess=clean_overruling_year,
)
for case in overruled_cases
],
sampling_temperature=1,
save_string="scotus/year_overruled_few_shot",
)
year_overruled_task_few_shot.do()
year_overruled_task_few_shot.save()