lowrollr commited on
Commit
ef1a205
1 Parent(s): 20ddb57

rubrics + essay prompt field + templates

Browse files
Files changed (3) hide show
  1. app.py +53 -15
  2. requirements.txt +3 -1
  3. rubrics/act_rubric.json +150 -0
app.py CHANGED
@@ -1,7 +1,12 @@
 
1
  import gradio as gr
2
  import openai
3
  import os
 
4
 
 
 
 
5
 
6
  MODEL = "gpt-3.5-turbo"
7
 
@@ -10,30 +15,63 @@ try:
10
  except:
11
  print("Set the OPENAI_API_KEY environment variable")
12
  exit()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def get_prompt(essay):
15
- return f"""
16
- Provide an estimate score and sub-scores for the following ACT writing sample using the ACT scoring rubric.
17
- For each sub-score also provide one example of support and one example of what could be improved.
18
- Each score should be a single number with one decimal point of accuracy and not a range.
19
- This is the provided writing sample:
20
- "{essay}"
21
- """
22
 
23
 
24
 
25
- def grade_essay(essay):
26
  response = openai.ChatCompletion.create(
27
  model=MODEL,
28
- messages=[{"role":"user", "content":get_prompt(essay)}],
29
- temperature=1,
30
- max_tokens=1000
31
  )
32
 
33
- return response['choices'][0]['message']['content']
34
-
35
 
36
- demo = gr.Interface(fn=grade_essay, inputs="text", outputs="text")
37
 
38
  demo.launch()
39
 
 
1
+ from typing import Dict
2
  import gradio as gr
3
  import openai
4
  import os
5
+ import json
6
 
7
+ from langchain import PromptTemplate
8
+ from langchain.output_parsers import PydanticOutputParser
9
+ from pydantic import BaseModel, Field
10
 
11
  MODEL = "gpt-3.5-turbo"
12
 
 
15
  except:
16
  print("Set the OPENAI_API_KEY environment variable")
17
  exit()
18
+
19
+ with open('./rubrics/act_rubric.json', 'r') as j:
20
+ act_rubric = json.loads(j.read())
21
+
22
+ class ScoreDescription(BaseModel):
23
+ score: int = Field(description="The score given")
24
+ description: str = Field(description="Why the score was given")
25
+
26
+ class ACTScore(BaseModel):
27
+ sub_scores: Dict[str, ScoreDescription] = Field(description="The sub-scores of the essay for each category in the rubric")
28
+ overall_feedback: str = Field(description="Overall feedback for the essay")
29
+
30
+ parser = PydanticOutputParser(pydantic_object=ACTScore)
31
+
32
+ grader_template = PromptTemplate(
33
+ input_variables=['rubric', 'essay_prompt', 'essay'],
34
+ template= """
35
+ You are an essay grader provided with the following grading rubric:\n
36
+ {rubric}
37
+ \n
38
+ The essay writer was given the following instructions to write the essay: \n
39
+ {essay_prompt}
40
+ \n
41
+ Grade the following essay. Provide sub-scores and rationale for each sub-score. \n
42
+ {essay}
43
+ \n
44
+
45
+ Format description:
46
+ {format_description}
47
+ """,
48
+ partial_variables={
49
+ 'format_description': parser.get_format_instructions()
50
+ }
51
+
52
+ )
53
 
54
+ def get_prompt(essay, essay_prompt):
55
+ return grader_template.format(
56
+ rubric=act_rubric,
57
+ essay=essay,
58
+ essay_prompt=essay_prompt
59
+ )
 
 
60
 
61
 
62
 
63
+ def grade_essay(essay, essay_prompt):
64
  response = openai.ChatCompletion.create(
65
  model=MODEL,
66
+ messages=[{"role":"user", "content":get_prompt(essay, essay_prompt)}],
67
+ temperature=0.0,
68
+ max_tokens=1000,
69
  )
70
 
71
+ result = response['choices'][0]['message']['content']
72
+ return result
73
 
74
+ demo = gr.Interface(fn=grade_essay, inputs=[gr.Textbox(lines=10, placeholder='Essay'), gr.Textbox(lines=10, placeholder='Essay Prompt')], outputs="text")
75
 
76
  demo.launch()
77
 
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  gradio==3.27.0
2
- openai==0.27.4
 
 
 
1
  gradio==3.27.0
2
+ openai==0.27.4
3
+ langchain
4
+ pydantic
rubrics/act_rubric.json ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "overall_scores": [
3
+ {
4
+ "score": "6",
5
+ "description": "Responses at this scorepoint demonstrate effective skill in writing an argumentative essay."
6
+ },
7
+ {
8
+ "score": "5",
9
+ "description": "Responses at this scorepoint demonstrate well-developed skill in writing an argumentative essay."
10
+ },
11
+ {
12
+ "score": "4",
13
+ "description": "Responses at this scorepoint demonstrate adequate skill in writing an argumentative essay."
14
+ },
15
+ {
16
+ "score": "3",
17
+ "description": "Responses at this scorepoint demonstrate some developing skill in writing an argumentative essay."
18
+ },
19
+ {
20
+ "score": "2",
21
+ "description": "Responses at this scorepoint demonstrate weak or inconsistent skill in writing an argumentative essay."
22
+ },
23
+ {
24
+ "score": "1",
25
+ "description": "Responses at this scorepoint demonstrate little or no skill in writing an argumentative essay."
26
+ }
27
+ ],
28
+ "categories": [
29
+ {
30
+ "name": "Ideas and Analysis",
31
+ "description": "Scores in this domain reflect the ability to generate productive ideas and engage critically with multiple perspectives on the given issue.",
32
+ "levels": [
33
+ {
34
+ "score": "6",
35
+ "description": "The writer generates an argument that critically engages with multiple perspectives on the given issue. The argument’s thesis reflects nuance and precision in thought and purpose. The argument establishes and employs an insightful context for analysis of the issue and its perspectives. The analysis examines implications, complexities and tensions, and/or underlying values and assumptions."
36
+ },
37
+ {
38
+ "score": "5",
39
+ "description": "The writer generates an argument that productively engages with multiple perspectives on the given issue. The argument’s thesis reflects precision in thought and purpose. The argument establishes and employs a thoughtful context for analysis of the issue and its perspectives. The analysis addresses implications, complexities and tensions, and/or underlying values and assumptions."
40
+ },
41
+ {
42
+ "score": "4",
43
+ "description": "The writer generates an argument that engages with multiple perspectives on the given issue. The argument’s thesis reflects clarity in thought and purpose. The argument establishes and employs a relevant context for analysis of the issue and its perspectives. The analysis recognizes implications, complexities and tensions, and/or underlying values and assumptions."
44
+ },
45
+ {
46
+ "score": "3",
47
+ "description": "The writer generates an argument that responds to multiple perspectives on the given issue. The argument’s thesis reflects some clarity in thought and purpose. The argument establishes a limited or tangential context for analysis of the issue and its perspectives. Analysis is simplistic or somewhat unclear."
48
+ },
49
+ {
50
+ "score": "2",
51
+ "description": "The writer generates an argument that weakly responds to multiple perspectives on the given issue. The argument’s thesis, if evident, reflects little clarity in thought and purpose. Attempts at analysis are incomplete, largely irrelevant, or consist primarily of restatement of the issue and its perspectives."
52
+ },
53
+ {
54
+ "score": "1",
55
+ "description": "The writer fails to generate an argument that responds intelligibly to the task. The writer’s intentions are difficult to discern. Attempts at analysis are unclear or irrelevant."
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ "name": "Development and Support",
61
+ "description": "Scores in this domain reflect the ability to discuss ideas, offer rationale, and bolster an argument.",
62
+ "levels": [
63
+ {
64
+ "score": "6",
65
+ "description": "Development of ideas and support for claims deepen insight and broaden context. An integrated line of skillful reasoning and illustration effectively conveys the significance of the argument. Qualifications and complications enrich and bolster ideas and analysis."
66
+ },
67
+ {
68
+ "score": "5",
69
+ "description": "Development of ideas and support for claims deepen understanding. A mostly integrated line of purposeful reasoning and illustration capably conveys the significance of the argument. Qualifications and complications enrich ideas and analysis."
70
+ },
71
+ {
72
+ "score": "4",
73
+ "description": "Development of ideas and support for claims clarify meaning and purpose. Lines of clear reasoning and illustration adequately convey the significance of the argument. Qualifications and complications extend ideas and analysis."
74
+ },
75
+ {
76
+ "score": "3",
77
+ "description": "Development of ideas and support for claims are mostly relevant but are overly general or simplistic. Reasoning and illustration largely clarify the argument but may be somewhat repetitious or imprecise."
78
+ },
79
+ {
80
+ "score": "2",
81
+ "description": "Development of ideas and support for claims are weak, confused, or disjointed. Reasoning and illustration are inadequate, illogical, or circular, and fail to fully clarify the argument."
82
+ },
83
+ {
84
+ "score": "1",
85
+ "description": "Ideas lack development, and claims lack support. Reasoning and illustration are unclear, incoherent, or largely absent."
86
+ }
87
+ ]
88
+ },
89
+ {
90
+ "name": "Organization",
91
+ "description": "Scores in this domain reflect the ability to organize ideas with clarity and purpose.",
92
+ "levels": [
93
+ {
94
+ "score": "6",
95
+ "description": "The response exhibits a skillful organizational strategy. The response is unified by a controlling idea or purpose, and a logical progression of ideas increases the effectiveness of the writer’s argument. Transitions between and within paragraphs strengthen the relationships among ideas."
96
+ },
97
+ {
98
+ "score": "5",
99
+ "description": "The response exhibits a productive organizational strategy. The response is mostly unified by a controlling idea or purpose, and a logical sequencing of ideas contributes to the effectiveness of the argument. Transitions between and within paragraphs consistently clarify the relationships among ideas."
100
+ },
101
+ {
102
+ "score": "4",
103
+ "description": "The response exhibits a clear organizational strategy. The overall shape of the response reflects an emergent controlling idea or purpose. Ideas are logically grouped and sequenced. Transitions between and within paragraphs clarify the relationships among ideas."
104
+ },
105
+ {
106
+ "score": "3",
107
+ "description": "The response exhibits a basic organizational structure. The response largely coheres, with most ideas logically grouped. Transitions between and within paragraphs sometimes clarify the relationships among ideas."
108
+ },
109
+ {
110
+ "score": "2",
111
+ "description": "The response exhibits a rudimentary organizational structure. Grouping of ideas is inconsistent and often unclear. Transitions between and within paragraphs are misleading or poorly formed."
112
+ },
113
+ {
114
+ "score": "1",
115
+ "description": "The response does not exhibit an organizational structure. There is little grouping of ideas. When present, transitional devices fail to connect ideas."
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ "name": "Language Use and Conventions",
121
+ "description": "Scores in this domain reflect the ability to use written language to convey arguments with clarity.",
122
+ "levels": [
123
+ {
124
+ "score": "6",
125
+ "description": "The use of language enhances the argument. Word choice is skillful and precise. Sentence structures are consistently varied and clear. Stylistic and register choices, including voice and tone, are strategic and effective. While a few minor errors in grammar, usage, and mechanics may be present, they do not impede understanding."
126
+ },
127
+ {
128
+ "score": "5",
129
+ "description": "The use of language works in service of the argument. Word choice is precise. Sentence structures are clear and varied often. Stylistic and register choices, including voice and tone, are purposeful and productive. While minor errors in grammar, usage, and mechanics may be present, they do not impede understanding."
130
+ },
131
+ {
132
+ "score": "4",
133
+ "description": "The use of language conveys the argument with clarity. Word choice is adequate and sometimes precise. Sentence structures are clear and demonstrate some variety. Stylistic and register choices, including voice and tone, are appropriate for the rhetorical purpose. While errors in grammar, usage, and mechanics are present, they rarely impede understanding."
134
+ },
135
+ {
136
+ "score": "3",
137
+ "description": "The use of language is basic and only somewhat clear. Word choice is general and occasionally imprecise. Sentence structures are usually clear but show little variety. Stylistic and register choices, including voice and tone, are not always appropriate for the rhetorical purpose. Distracting errors in grammar, usage, and mechanics may be present, but they generally do not impede understanding."
138
+ },
139
+ {
140
+ "score": "2",
141
+ "description": "The use of language is inconsistent and often unclear. Word choice is rudimentary and frequently imprecise. Sentence structures are sometimes unclear. Stylistic and register choices, including voice and tone, are inconsistent and are not always appropriate for the rhetorical purpose. Distracting errors in grammar, usage, and mechanics are present, and they sometimes impede understanding."
142
+ },
143
+ {
144
+ "score": "1",
145
+ "description": "The use of language fails to demonstrate skill in responding to the task. Word choice is imprecise and often difficult to comprehend. Sentence structures are often unclear. Stylistic and register choices are difficult to identify. Errors in grammar, usage, and mechanics are pervasive and often impede understanding."
146
+ }
147
+ ]
148
+ }
149
+ ]
150
+ }