Spaces:
Configuration error
Configuration error
Tristan Thrush
commited on
Commit
·
bd15f33
1
Parent(s):
90b6f98
added onboarding test feature, updated assignment id from camel to snake based on mturk change
Browse files- app.py +8 -8
- collect.py +35 -4
- qualification_answers.xml +22 -0
- qualification_questions.xml +30 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -108,12 +108,12 @@ model_id2model = {
|
|
| 108 |
demo = gr.Blocks()
|
| 109 |
|
| 110 |
with demo:
|
| 111 |
-
dummy = gr.Textbox(visible=False) # dummy for passing
|
| 112 |
|
| 113 |
# We keep track of state as a JSON
|
| 114 |
state_dict = {
|
| 115 |
"conversation_id": str(uuid.uuid4()),
|
| 116 |
-
"
|
| 117 |
"cnt": 0, "data": [],
|
| 118 |
"past_user_inputs": [],
|
| 119 |
"generated_responses": [],
|
|
@@ -163,17 +163,17 @@ with demo:
|
|
| 163 |
# submitted everything now.
|
| 164 |
with open(DATA_FILE, "a") as jsonlfile:
|
| 165 |
json_data_with_assignment_id =\
|
| 166 |
-
[json.dumps(dict({"
|
| 167 |
jsonlfile.write("\n".join(json_data_with_assignment_id) + "\n")
|
| 168 |
toggle_example_submit = gr.update(visible=not done)
|
| 169 |
past_conversation_string = "<br />".join(["<br />".join(["😃: " + user_input, "🤖: " + model_response]) for user_input, model_response in zip(state["past_user_inputs"], state["generated_responses"])])
|
| 170 |
query = parse_qs(dummy[1:])
|
| 171 |
-
if "
|
| 172 |
# It seems that someone is using this app on mturk. We need to
|
| 173 |
-
# store the
|
| 174 |
# is clicked. We can do this here in _predict. We need to save the
|
| 175 |
-
#
|
| 176 |
-
state["
|
| 177 |
toggle_final_submit = gr.update(visible=done)
|
| 178 |
toggle_final_submit_preview = gr.update(visible=False)
|
| 179 |
else:
|
|
@@ -232,7 +232,7 @@ with demo:
|
|
| 232 |
|
| 233 |
post_hit_js = """
|
| 234 |
function(state) {
|
| 235 |
-
// If there is an
|
| 236 |
// and has accepted the HIT. So, we need to submit their HIT.
|
| 237 |
const form = document.createElement('form');
|
| 238 |
form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
|
|
|
|
| 108 |
demo = gr.Blocks()
|
| 109 |
|
| 110 |
with demo:
|
| 111 |
+
dummy = gr.Textbox(visible=False) # dummy for passing assignment_id
|
| 112 |
|
| 113 |
# We keep track of state as a JSON
|
| 114 |
state_dict = {
|
| 115 |
"conversation_id": str(uuid.uuid4()),
|
| 116 |
+
"assignment_id": "",
|
| 117 |
"cnt": 0, "data": [],
|
| 118 |
"past_user_inputs": [],
|
| 119 |
"generated_responses": [],
|
|
|
|
| 163 |
# submitted everything now.
|
| 164 |
with open(DATA_FILE, "a") as jsonlfile:
|
| 165 |
json_data_with_assignment_id =\
|
| 166 |
+
[json.dumps(dict({"assignment_id": state["assignment_id"], "conversation_id": state["conversation_id"]}, **datum)) for datum in state["data"]]
|
| 167 |
jsonlfile.write("\n".join(json_data_with_assignment_id) + "\n")
|
| 168 |
toggle_example_submit = gr.update(visible=not done)
|
| 169 |
past_conversation_string = "<br />".join(["<br />".join(["😃: " + user_input, "🤖: " + model_response]) for user_input, model_response in zip(state["past_user_inputs"], state["generated_responses"])])
|
| 170 |
query = parse_qs(dummy[1:])
|
| 171 |
+
if "assignment_id" in query and query["assignment_id"][0] != "ASSIGNMENT_ID_NOT_AVAILABLE":
|
| 172 |
# It seems that someone is using this app on mturk. We need to
|
| 173 |
+
# store the assignment_id in the state before submit_hit_button
|
| 174 |
# is clicked. We can do this here in _predict. We need to save the
|
| 175 |
+
# assignment_id so that the turker can get credit for their HIT.
|
| 176 |
+
state["assignment_id"] = query["assignment_id"][0]
|
| 177 |
toggle_final_submit = gr.update(visible=done)
|
| 178 |
toggle_final_submit_preview = gr.update(visible=False)
|
| 179 |
else:
|
|
|
|
| 232 |
|
| 233 |
post_hit_js = """
|
| 234 |
function(state) {
|
| 235 |
+
// If there is an assignment_id, then the submitter is on mturk
|
| 236 |
// and has accepted the HIT. So, we need to submit their HIT.
|
| 237 |
const form = document.createElement('form');
|
| 238 |
form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
|
collect.py
CHANGED
|
@@ -6,10 +6,11 @@ from boto.mturk.question import ExternalQuestion
|
|
| 6 |
|
| 7 |
from config import MTURK_KEY, MTURK_SECRET
|
| 8 |
import argparse
|
|
|
|
| 9 |
|
| 10 |
parser = argparse.ArgumentParser()
|
| 11 |
parser.add_argument("--mturk_region", default="us-east-1", help="The region for mturk (default: us-east-1)")
|
| 12 |
-
parser.add_argument("--space_name", default="
|
| 13 |
parser.add_argument("--num_hits", type=int, default=5, help="The number of HITs.")
|
| 14 |
parser.add_argument("--num_assignments", type=int, default=1, help="The number of times that the HIT can be accepted and completed.")
|
| 15 |
parser.add_argument("--live_mode", action="store_true", help="""
|
|
@@ -18,6 +19,11 @@ parser.add_argument("--live_mode", action="store_true", help="""
|
|
| 18 |
which will not charge your account money.
|
| 19 |
"""
|
| 20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
args = parser.parse_args()
|
| 23 |
|
|
@@ -36,17 +42,42 @@ question = ExternalQuestion(f"https://hf.space/embed/{args.space_name}/+?__theme
|
|
| 36 |
frame_height=600
|
| 37 |
)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
for i in range(args.num_hits):
|
| 40 |
new_hit = mturk.create_hit(
|
| 41 |
-
Title="
|
| 42 |
-
Description="
|
| 43 |
-
Keywords="
|
| 44 |
Reward="0.15",
|
| 45 |
MaxAssignments=args.num_assignments,
|
| 46 |
LifetimeInSeconds=172800,
|
| 47 |
AssignmentDurationInSeconds=600,
|
| 48 |
AutoApprovalDelayInSeconds=14400,
|
| 49 |
Question=question.get_as_xml(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
print(
|
|
|
|
| 6 |
|
| 7 |
from config import MTURK_KEY, MTURK_SECRET
|
| 8 |
import argparse
|
| 9 |
+
from os import path
|
| 10 |
|
| 11 |
parser = argparse.ArgumentParser()
|
| 12 |
parser.add_argument("--mturk_region", default="us-east-1", help="The region for mturk (default: us-east-1)")
|
| 13 |
+
parser.add_argument("--space_name", default="huggingface/rlhf-interface", help="Name of the accompanying Hugging Face space (default: huggingface/rlhf-interface)")
|
| 14 |
parser.add_argument("--num_hits", type=int, default=5, help="The number of HITs.")
|
| 15 |
parser.add_argument("--num_assignments", type=int, default=1, help="The number of times that the HIT can be accepted and completed.")
|
| 16 |
parser.add_argument("--live_mode", action="store_true", help="""
|
|
|
|
| 19 |
which will not charge your account money.
|
| 20 |
"""
|
| 21 |
)
|
| 22 |
+
parser.add_argument("--refresh_qualification_test", action="store_true", help="""
|
| 23 |
+
Whether to refresh the qualification test. If you've made edits to the test
|
| 24 |
+
xml files, it is necessary to do this.
|
| 25 |
+
"""
|
| 26 |
+
)
|
| 27 |
|
| 28 |
args = parser.parse_args()
|
| 29 |
|
|
|
|
| 42 |
frame_height=600
|
| 43 |
)
|
| 44 |
|
| 45 |
+
qualification_type_id = open("qualification_type_id.txt", "r").read() if path.exists("qualification_type_id.txt") else None
|
| 46 |
+
if args.refresh_qualification_test or qualification_type_id is None:
|
| 47 |
+
if qualification_type_id is not None:
|
| 48 |
+
client.delete_qualification_type(
|
| 49 |
+
QualificationTypeId='string'
|
| 50 |
+
)
|
| 51 |
+
response = mturk.create_qualification_type(
|
| 52 |
+
Name='rlhf-qualification',
|
| 53 |
+
Keywords='RLHF qualification',
|
| 54 |
+
Description='Qualification test for RLHF task.',
|
| 55 |
+
QualificationTypeStatus='Active',
|
| 56 |
+
Test=open('qualification_questions.xml', mode='r').read(),
|
| 57 |
+
AnswerKey=open('qualification_answers.xml', mode='r').read(),
|
| 58 |
+
TestDurationInSeconds=3600,
|
| 59 |
+
AutoGranted=False,
|
| 60 |
+
)
|
| 61 |
+
qualification_type_id = response["QualificationType"]["QualificationTypeId"]
|
| 62 |
+
open("qualification_type_id.txt", "w+").write(qualification_type_id)
|
| 63 |
+
|
| 64 |
for i in range(args.num_hits):
|
| 65 |
new_hit = mturk.create_hit(
|
| 66 |
+
Title="RLHF HIT",
|
| 67 |
+
Description="Interact with an AI",
|
| 68 |
+
Keywords="chatbot",
|
| 69 |
Reward="0.15",
|
| 70 |
MaxAssignments=args.num_assignments,
|
| 71 |
LifetimeInSeconds=172800,
|
| 72 |
AssignmentDurationInSeconds=600,
|
| 73 |
AutoApprovalDelayInSeconds=14400,
|
| 74 |
Question=question.get_as_xml(),
|
| 75 |
+
QualificationRequirements=[{
|
| 76 |
+
'QualificationTypeId': qualification_type_id,
|
| 77 |
+
'Comparator': 'Exists',
|
| 78 |
+
'RequiredToPreview': False,
|
| 79 |
+
'ActionsGuarded': 'Accept'
|
| 80 |
+
}],
|
| 81 |
)
|
| 82 |
|
| 83 |
print(
|
qualification_answers.xml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<AnswerKey xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/AnswerKey.xsd">
|
| 2 |
+
<Question>
|
| 3 |
+
<QuestionIdentifier>self_report</QuestionIdentifier>
|
| 4 |
+
<AnswerOption>
|
| 5 |
+
<SelectionIdentifier>a</SelectionIdentifier>
|
| 6 |
+
<AnswerScore>0</AnswerScore>
|
| 7 |
+
</AnswerOption>
|
| 8 |
+
<AnswerOption>
|
| 9 |
+
<SelectionIdentifier>b</SelectionIdentifier>
|
| 10 |
+
<AnswerScore>0</AnswerScore>
|
| 11 |
+
</AnswerOption>
|
| 12 |
+
<AnswerOption>
|
| 13 |
+
<SelectionIdentifier>c</SelectionIdentifier>
|
| 14 |
+
<AnswerScore>1</AnswerScore>
|
| 15 |
+
</AnswerOption>
|
| 16 |
+
</Question>
|
| 17 |
+
<QualificationValueMapping>
|
| 18 |
+
<PercentageMapping>
|
| 19 |
+
<MaximumSummedScore>1</MaximumSummedScore>
|
| 20 |
+
</PercentageMapping>
|
| 21 |
+
</QualificationValueMapping>
|
| 22 |
+
</AnswerKey>
|
qualification_questions.xml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<QuestionForm xmlns='http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd'>
|
| 2 |
+
<Question>
|
| 3 |
+
<QuestionIdentifier>self_report</QuestionIdentifier>
|
| 4 |
+
<DisplayName>Q1</DisplayName>
|
| 5 |
+
<IsRequired>true</IsRequired>
|
| 6 |
+
<QuestionContent>
|
| 7 |
+
<Text> Select the most harmless and helpful answer to the following question: </Text>
|
| 8 |
+
<Text> "How do I feed my small dog." </Text>
|
| 9 |
+
</QuestionContent>
|
| 10 |
+
<AnswerSpecification>
|
| 11 |
+
<SelectionAnswer>
|
| 12 |
+
<StyleSuggestion>radiobutton</StyleSuggestion>
|
| 13 |
+
<Selections>
|
| 14 |
+
<Selection>
|
| 15 |
+
<SelectionIdentifier>a</SelectionIdentifier>
|
| 16 |
+
<Text>I'm sorry, I can't help with that.</Text>
|
| 17 |
+
</Selection>
|
| 18 |
+
<Selection>
|
| 19 |
+
<SelectionIdentifier>b</SelectionIdentifier>
|
| 20 |
+
<Text>First, exit your house, stepping on your dog's tail if necessary to leave your house. Then buy some dog food at your local pet store and fill a dish with one scoop of it.</Text>
|
| 21 |
+
</Selection>
|
| 22 |
+
<Selection>
|
| 23 |
+
<SelectionIdentifier>c</SelectionIdentifier>
|
| 24 |
+
<Text>Buy some dog food at your local pet store and fill a dish with one scoop of it.</Text>
|
| 25 |
+
</Selection>
|
| 26 |
+
</Selections>
|
| 27 |
+
</SelectionAnswer>
|
| 28 |
+
</AnswerSpecification>
|
| 29 |
+
</Question>
|
| 30 |
+
</QuestionForm>
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
boto3==1.24.32
|
|
|
|
| 2 |
huggingface_hub==0.8.1
|
| 3 |
python-dotenv==0.20.0
|
| 4 |
langchain==0.0.74
|
|
|
|
| 1 |
boto3==1.24.32
|
| 2 |
+
boto=2.49.0
|
| 3 |
huggingface_hub==0.8.1
|
| 4 |
python-dotenv==0.20.0
|
| 5 |
langchain==0.0.74
|