JRQi commited on
Commit
2443dec
β€’
1 Parent(s): 8a63757

Update game3.py

Browse files
Files changed (1) hide show
  1. game3.py +24 -33
game3.py CHANGED
@@ -40,9 +40,9 @@ def func3(num_selected, human_predict, num1, num2, user_important):
40
 
41
  golden_label = (text['binary_label']^1) * 100
42
  if golden_label == 0:
43
- golden_label = 50 * (1 - text['binary_score'])
44
  else:
45
- golden_label = 50 * (1 + text['binary_score'])
46
  # (START) off-the-shelf version -- slow at the beginning
47
  # Load model directly
48
  # Use a pipeline as a high-level helper
@@ -55,8 +55,10 @@ def func3(num_selected, human_predict, num1, num2, user_important):
55
 
56
  # (END) off-the-shelf version
57
 
58
- # ai_predict = out['label']
59
- ai_predict = out['score']
 
 
60
 
61
  user_select = "You focused on "
62
  flag_select = False
@@ -76,28 +78,20 @@ def func3(num_selected, human_predict, num1, num2, user_important):
76
  # if not flag_select:
77
  # user_select += "nothing. Interesting! "
78
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
79
- if abs(ai_predict - golden_label) < 12.5:
80
- if abs(human_predict - golden_label) < 12.5: # Both correct
81
- golden_label = int((human_predict + ai_predict) / 2)
82
- chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
83
- num1 += 1
84
- num2 += 1
85
- else:
86
- golden_label += random.randint(-2, 2)
87
- while golden_label > 100 or golden_label < 0 or golden_label % 25 == 0:
88
- golden_label += random.randint(-2, 2)
89
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
90
- num2 += 1
91
  else:
92
- if abs(human_predict - golden_label) < abs(ai_predict - golden_label):
93
- if abs(human_predict - golden_label) < 12.5:
94
- golden_label = int((golden_label + human_predict) / 2)
95
- chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
96
- num1 += 1
97
- else:
98
- chatbot.append(("The correct answer is " + str(golden_label) + ". Both wrong... Maybe next time you'll win!", user_select))
99
- else:
100
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
101
 
102
  tot_scores = ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human </p>'''
103
 
@@ -169,19 +163,16 @@ def func3_written(text_written, human_predict, lang_written):
169
  out = output[0]
170
  # (END) off-the-shelf version
171
 
 
 
 
 
172
 
173
- # ai_predict = star2num[out['label']]
174
- ai_predict = out['score']
175
-
176
- if abs(ai_predict - human_predict) <= 12.5:
177
  chatbot.append(("AI gives it a close score! πŸŽ‰", "⬅️ Feel free to try another one! ⬅️"))
178
  else:
179
- ai_predict += random.randint(-2, 2)
180
- while ai_predict > 100 or ai_predict < 0 or ai_predict % 25 == 0:
181
- ai_predict += random.randint(-2, 2)
182
  chatbot.append(("AI thinks in a different way from human. πŸ˜‰", "⬅️ Feel free to try another one! ⬅️"))
183
 
184
-
185
  import shap
186
 
187
  gender_classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification", return_all_scores=True)
 
40
 
41
  golden_label = (text['binary_label']^1) * 100
42
  if golden_label == 0:
43
+ golden_label = int(50 * (1 - text['binary_score']))
44
  else:
45
+ golden_label = int(50 * (1 + text['binary_score']))
46
  # (START) off-the-shelf version -- slow at the beginning
47
  # Load model directly
48
  # Use a pipeline as a high-level helper
 
55
 
56
  # (END) off-the-shelf version
57
 
58
+ if out['label'] == 'Female':
59
+ ai_predict = int(out['score'])
60
+ else:
61
+ ai_predict = 1 - int(out['score'])
62
 
63
  user_select = "You focused on "
64
  flag_select = False
 
78
  # if not flag_select:
79
  # user_select += "nothing. Interesting! "
80
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
81
+
82
+
83
+ if abs(golden_label - human_predict) <= 20 and abs(golden_label - ai_predict) <= 20:
84
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
85
+ num1 += 1
86
+ num2 += 1
87
+ elif abs(golden_label - human_predict) > 20 and abs(golden_label - ai_predict) > 20:
88
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
89
+ elif abs(golden_label - human_predict) <= 20 and abs(golden_label - ai_predict) > 20:
90
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
91
+ num1 += 1
 
92
  else:
93
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
94
+ num2 += 1
 
 
 
 
 
 
 
95
 
96
  tot_scores = ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human </p>'''
97
 
 
163
  out = output[0]
164
  # (END) off-the-shelf version
165
 
166
+ if out['label'] == 'Female':
167
+ ai_predict = int(out['score'])
168
+ else:
169
+ ai_predict = 1 - int(out['score'])
170
 
171
+ if abs(ai_predict - human_predict) <= 20:
 
 
 
172
  chatbot.append(("AI gives it a close score! πŸŽ‰", "⬅️ Feel free to try another one! ⬅️"))
173
  else:
 
 
 
174
  chatbot.append(("AI thinks in a different way from human. πŸ˜‰", "⬅️ Feel free to try another one! ⬅️"))
175
 
 
176
  import shap
177
 
178
  gender_classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification", return_all_scores=True)