aboltachka commited on
Commit
aa1d1c2
1 Parent(s): 1b1858e

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +69 -32
  2. images/default.png +0 -0
  3. images/no.png +0 -0
  4. images/yes.png +0 -0
app.py CHANGED
@@ -30,7 +30,7 @@ group_control = [('control',0,re.compile(r'\bminimum wage\b')),
30
  ('control',13,re.compile(r'\bdoctor\b')),
31
  ('control',14,re.compile(r'\bphysician\b')),
32
  ('control',15,re.compile(r'\bself-employed\b')),
33
- ('control',16,re.compile(r'\bentrepreneur\b')),]
34
 
35
  group_issue = [('issue',0,re.compile(r'\bdiscriminat[a-zA-Z]{0,5}\b')), # changed from {0,4} to {0,5}, e/g Discriminatively
36
  ('issue',1,re.compile(r'\bprejudi[a-zA-Z]{0,4}\b')), # changed from {0,3} to {0,4}, e/g Prejudicing
@@ -219,7 +219,8 @@ group_ethnicity = [('ethnicity',0,re.compile(r'\brac[a-zA-Z]{0,3}\b')),
219
  ('ethnicity',75,re.compile(r'\bsioux\b')),
220
  ('ethnicity',76,re.compile(r'\bsiouan\b')),
221
  ('ethnicity',77,re.compile(r'\bchippewa[a-zA-Z]{0,3}\b')),
222
- ('ethnicity',78,re.compile(r'\bchoctaw[a-zA-Z]{0,3}\b'))]
 
223
 
224
  group_blackball = [('blackball',0, re.compile(r'\bblack.{0,3}market[a-zA-Z- ]{0,3}\b')),
225
  ('blackball',1, re.compile(r'\bblack.{0,3}economy\b')),
@@ -252,7 +253,7 @@ group_main_american = [1,2,3,5,6,7,11,21,25,26,27,28,29,36,44,48,49,50,51,52,67,
252
  group_minor = [15,22,23,24,30,32,34,45,46,47,55,56,]
253
  group_religious = [57,58,59,60,61,69,]
254
  group_sexual = [62,63,64,65,66]
255
- group_abstract = [0,4,17,18,35,36,37,38,39,40,41,42,43,70,71]
256
  group_tribal = [72,73,74,75,76,77,78]
257
  group_0 = group_abstract
258
  group_1 = group_abstract + group_main_american
@@ -321,7 +322,7 @@ def rr_detector(title_raw, abstract_raw):
321
  results[f'match_{int(e)}'] = 0
322
  for i in l:
323
  if result_dict[f'ethnicity_{int(i)}_t_c'] > 0:
324
- if result_dict[f'group_{int(e)}']*result_dict['issue_s_at_m'] + 1 > 0 and results.get(f'match_{int(e)}', 0) != 1:
325
  results[f'match_{int(e)}'] = 1
326
  result_dict.update(results)
327
 
@@ -392,22 +393,23 @@ def rr_detector(title_raw, abstract_raw):
392
  df_group = df_group[['type', 'term', 'freq']]
393
 
394
  df_blackball = pd.DataFrame(list(blackball_count.items()), columns=['term', 'freq'])
395
- df_blackball['type'] = 'blackball'
396
  df_blackball = df_blackball[['type', 'term', 'freq']]
397
 
398
  df_details = pd.concat([df_group, df_issue, df_blackball], ignore_index=True)
399
 
400
  #TEXT ANALYSIS
401
  #Dictionary with issue, topic, and blackball keywords
402
- keywords_dict = {"issue": [], "group": [], "blackball": []}
403
  keywords_dict["issue"].extend(issue_count.keys())
404
  keywords_dict["group"].extend(group_count.keys())
405
- keywords_dict["blackball"].extend(blackball_count.keys())
406
 
407
- combined_text = f"TITLE: {title_raw}. \nABSTRACT: {abstract_raw}"
408
 
409
  text_analysis = []
410
  for word in combined_text.split():
 
411
  if word.lower() in [item.lower() for sublist in keywords_dict.values() for item in sublist]:
412
  for key, words in keywords_dict.items():
413
  if word.lower() in [item.lower() for item in words]:
@@ -424,30 +426,39 @@ def rr_detector(title_raw, abstract_raw):
424
  #Explanation
425
  unique_group_str = ', '.join(unique_group)
426
  unique_issue_str = ', '.join(unique_issue)
427
- answer = "This paper can be considered race-related, as it mentions at least one group keyword and one topic keywords in title or abstract. Furthermore, it does not mention group keywords in last sentence of abstract, and the algorithm does not identify any blackball phrases in the title and abstract provided."
428
 
429
  else:
430
- if len(unique_blackball) > 0:
 
431
  #Result
432
  output_image = os.path.join(dirname, 'images/no.png')
433
  #Explanation
434
- unique_blackball_str = ', '.join(unique_blackball)
435
- answer = "This paper cannot be considered race-related, as it includes blackball phrases, such as: " + unique_blackball_str + "."
436
-
437
-
438
  else:
439
  #Result
440
  output_image = os.path.join(dirname, 'images/no.png')
441
  #Explanation
442
- answer = "This paper cannot be considered race-related, as it does not mention any group or topic keywords, or it does mention group keywords but only in the last sentence of provided abstract."
443
  #Details
444
- data = {
445
- "type": ["blackball", "issue", "group"],
446
- "term": ["term1", "term2", "term3"],
447
- "freq": [0, 0, 0]
448
- }
449
- df_details = pd.DataFrame(data)
450
-
 
 
 
 
 
 
 
 
 
 
451
 
452
  return(output_image, answer, df_details, text_analysis)
453
 
@@ -466,7 +477,7 @@ title_prompt = """
466
  <style>
467
  .title {
468
  font-family: Arial, sans-serif;
469
- font-size: 24px;
470
  font-weight: bold;
471
  text-align: center;
472
  letter-spacing: 3px;
@@ -502,12 +513,12 @@ description_prompt = """
502
  #####################
503
 
504
  title_smpl = "Race-related Research in Economics"
505
- abstract_smpl = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics."
506
 
507
 
508
  demo = gr.Interface(fn=rr_detector, inputs=[
509
  gr.Textbox(label="Title", value=title_smpl, lines=2),
510
- gr.Textbox(label="Abstract", value=abstract_smpl, lines=12)],
511
  outputs=[
512
  gr.Image(label = 'Result', value=def_image),
513
  gr.Textbox(label="Explanation"),
@@ -520,8 +531,8 @@ demo = gr.Interface(fn=rr_detector, inputs=[
520
  tooltip=["type", "term", "freq"],
521
  vertical=False,
522
  #caption = "TEST",
523
- #height = 150,
524
- #width = 300,
525
  color_legend_title = 'Type of Keywords',
526
  x_title = "Keywords",
527
  y_title = "Frequency"
@@ -529,14 +540,16 @@ demo = gr.Interface(fn=rr_detector, inputs=[
529
  gr.HighlightedText(
530
  label="Text Analysis",
531
  show_legend=True,
532
- color_map={"group": "yellow", "issue": "blue", "blackball": "grey"}),
533
- ], theme='ParityError/Interstellar', title = title_prompt, description = description_prompt, allow_flagging = 'auto')
534
 
 
 
535
 
536
  if __name__ == "__main__":
537
  demo.launch(share=True)
538
 
539
-
540
  # Add default picture for output
541
  # Output as graph of just text but with fancy representation -- use labels from theme
542
  # Generate picts for output with GenAi
@@ -545,6 +558,10 @@ if __name__ == "__main__":
545
  title_raw = 'When expectations work race and socioeconomic differences in school performance'
546
  abstract_raw = 'Why race between are expectations for future performance realized more often by some people than by others and why are such differences in the efficacy of performance expectations socially patterned we hypothesize that differences in attentiveness to performance feedback may be relevant reasoning that follow-through behaviors will be less well conceived when expectations are formed without regard to evaluation of previous performance. using data from baltimore fourth-grade students and their parents we find that expectations anticipate marks more accurately when recall of prior marks is correct than when it is incorrect. because errors of recall mostly on the high side are more common among lower-ses and minority children and their parents their school performance is affected most strongly. research on school attainment process from a motivational perspective must give more attention to the additional resources that facilitate successful goal attainment given high expectations. our perspective focuses on resources internal to the individual but external constraints also are important. the discussion stresses the need for further work in both areas.'
547
 
 
 
 
 
548
  #Default
549
  title_raw = "Race-related Research in Economics"
550
  abstract_raw = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics."
@@ -552,14 +569,34 @@ abstract_raw = "Issues of racial justice and persistent economic inequalities ac
552
 
553
 
554
  #non-RR
555
- title = 'Hurting stalemate or mediation the conflict over nagorno-karabakh 1990-95'
556
- abstract = 'The impacts of six attempts to mediate the conflict over the political status of nagorno-karabakh in the caucasus region of the former soviet union were compared. each mediation was intended to get the direct parties armenia azerbaijan and nagorno-karabakh to the negotiating table. nearly 4000 events were recorded for a six-year period from 1990 through 1995. each event was coded in terms of a six-step scale ranging from a significant action toward peace 3 to substantial violence directed at an adversary -3. time-series analyses of changes in the extent of violence showed no change from before to after any of the mediations. a significant change did occur however between the months preceding and following the period of intensive combat between april 1993 and february 1994. these results support the hypothesis that a mutually hurting stalemate is a condition for negotiating a ceasefire and reduced violence between warring parties. a number of theoretical and practical implications of the findings are discussed.'
557
 
 
 
558
 
559
  rr_detector(title_raw, abstract_raw)
560
 
 
 
 
 
 
 
 
561
 
 
 
562
 
563
 
564
 
 
 
 
 
 
 
565
 
 
 
 
 
30
  ('control',13,re.compile(r'\bdoctor\b')),
31
  ('control',14,re.compile(r'\bphysician\b')),
32
  ('control',15,re.compile(r'\bself-employed\b')),
33
+ ('control',16,re.compile(r'\bentrepreneur\b'))]
34
 
35
  group_issue = [('issue',0,re.compile(r'\bdiscriminat[a-zA-Z]{0,5}\b')), # changed from {0,4} to {0,5}, e/g Discriminatively
36
  ('issue',1,re.compile(r'\bprejudi[a-zA-Z]{0,4}\b')), # changed from {0,3} to {0,4}, e/g Prejudicing
 
219
  ('ethnicity',75,re.compile(r'\bsioux\b')),
220
  ('ethnicity',76,re.compile(r'\bsiouan\b')),
221
  ('ethnicity',77,re.compile(r'\bchippewa[a-zA-Z]{0,3}\b')),
222
+ ('ethnicity',78,re.compile(r'\bchoctaw[a-zA-Z]{0,3}\b')),
223
+ ('ethnicity',79,re.compile(r'\brace-related\b'))] #Added by Anton
224
 
225
  group_blackball = [('blackball',0, re.compile(r'\bblack.{0,3}market[a-zA-Z- ]{0,3}\b')),
226
  ('blackball',1, re.compile(r'\bblack.{0,3}economy\b')),
 
253
  group_minor = [15,22,23,24,30,32,34,45,46,47,55,56,]
254
  group_religious = [57,58,59,60,61,69,]
255
  group_sexual = [62,63,64,65,66]
256
+ group_abstract = [0,4,17,18,35,36,37,38,39,40,41,42,43,70,71, 78]
257
  group_tribal = [72,73,74,75,76,77,78]
258
  group_0 = group_abstract
259
  group_1 = group_abstract + group_main_american
 
322
  results[f'match_{int(e)}'] = 0
323
  for i in l:
324
  if result_dict[f'ethnicity_{int(i)}_t_c'] > 0:
325
+ if result_dict[f'group_{int(e)}']*result_dict['issue_s_at_m'] > 0 and results.get(f'match_{int(e)}', 0) != 1:
326
  results[f'match_{int(e)}'] = 1
327
  result_dict.update(results)
328
 
 
393
  df_group = df_group[['type', 'term', 'freq']]
394
 
395
  df_blackball = pd.DataFrame(list(blackball_count.items()), columns=['term', 'freq'])
396
+ df_blackball['type'] = 'whitelist'
397
  df_blackball = df_blackball[['type', 'term', 'freq']]
398
 
399
  df_details = pd.concat([df_group, df_issue, df_blackball], ignore_index=True)
400
 
401
  #TEXT ANALYSIS
402
  #Dictionary with issue, topic, and blackball keywords
403
+ keywords_dict = {"issue": [], "group": [], "whitelist": []}
404
  keywords_dict["issue"].extend(issue_count.keys())
405
  keywords_dict["group"].extend(group_count.keys())
406
+ keywords_dict["whitelist"].extend(blackball_count.keys())
407
 
408
+ combined_text = f"TITLE: {title_raw}. ABSTRACT: {abstract_raw}"
409
 
410
  text_analysis = []
411
  for word in combined_text.split():
412
+ print(word)
413
  if word.lower() in [item.lower() for sublist in keywords_dict.values() for item in sublist]:
414
  for key, words in keywords_dict.items():
415
  if word.lower() in [item.lower() for item in words]:
 
426
  #Explanation
427
  unique_group_str = ', '.join(unique_group)
428
  unique_issue_str = ', '.join(unique_issue)
429
+ answer = "This paper can be considered race-related, as it mentions at least one group keyword AND one topic keywords in title or abstract. Furthermore, the algorithm does not identify any blackball phrases in the title and abstract provided."
430
 
431
  else:
432
+
433
+ if len(blackball_count) > 0:
434
  #Result
435
  output_image = os.path.join(dirname, 'images/no.png')
436
  #Explanation
437
+ unique_blackball_str = ', '.join(blackball_count)
438
+ answer = "This paper cannot be considered race-related, as it includes the blackball phrase(s), such as: " + unique_blackball_str + "."
 
 
439
  else:
440
  #Result
441
  output_image = os.path.join(dirname, 'images/no.png')
442
  #Explanation
443
+ answer = "This paper cannot be considered race-related, as it does not mention at least one group AND one topic keywords in title or abstract, or it does mention group keywords but only in the last sentence of provided abstract."
444
  #Details
445
+ if len(issue_count.keys()) == 0 and len(group_count.keys()) == 0 and len(blackball_count.keys()) == 0 :
446
+ data = {
447
+ "type": ["blackball", "issue", "group"],
448
+ "term": ["term1", "term2", "term3"],
449
+ "freq": [0, 0, 0]
450
+ }
451
+ df_details = pd.DataFrame(data)
452
+
453
+ if len(abstract_raw) == 0:
454
+ output_image = os.path.join(dirname, 'images/default.png')
455
+ answer = "We need more information. Please submit abstact."
456
+ if len(title_raw) == 0:
457
+ output_image = os.path.join(dirname, 'images/default.png')
458
+ answer = "We need more information. Please submit title."
459
+ if len(title_raw) == 0 and len(abstract_raw) == 0:
460
+ output_image = os.path.join(dirname, 'images/default.png')
461
+ answer = "We need more information. Please submit title and abstract."
462
 
463
  return(output_image, answer, df_details, text_analysis)
464
 
 
477
  <style>
478
  .title {
479
  font-family: Arial, sans-serif;
480
+ font-size: 32px;
481
  font-weight: bold;
482
  text-align: center;
483
  letter-spacing: 3px;
 
513
  #####################
514
 
515
  title_smpl = "Race-related Research in Economics"
516
+ abstract_smpl = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics. First, since 1960 less than 2% of publications in economics have been race related, with an uptick in such work since the mid 1990s. This represents a cumulative body of knowledge of 3801 race-related publications in economics since 1960. Second, the publications process provides little disincentive to produce race-related research: such work has similar or better publication outcomes as non race-related research. Third, Black faculty are significantly more likely to publish race-related work during their career. However, citations and H-indices are significantly lower for minority faculty as a whole. However, the citation penalty for Black faculty is partially offset for their race-related publications. Fourth, over later stages of the career life cycle, Black faculty become less likely to work on race-related topics. The timing of this change coincides with their career progression up the ranking of US academic departments. We draw together policy implications for the profession related to innovative areas of race-related research that economists can engage in, and processes to improve the selection and retention of minority faculty."
517
 
518
 
519
  demo = gr.Interface(fn=rr_detector, inputs=[
520
  gr.Textbox(label="Title", value=title_smpl, lines=2),
521
+ gr.Textbox(label="Abstract", value=abstract_smpl, lines=18)],
522
  outputs=[
523
  gr.Image(label = 'Result', value=def_image),
524
  gr.Textbox(label="Explanation"),
 
531
  tooltip=["type", "term", "freq"],
532
  vertical=False,
533
  #caption = "TEST",
534
+ height = 150,
535
+ width = 300,
536
  color_legend_title = 'Type of Keywords',
537
  x_title = "Keywords",
538
  y_title = "Frequency"
 
540
  gr.HighlightedText(
541
  label="Text Analysis",
542
  show_legend=True,
543
+ color_map={"group": "yellow", "issue": "blue", "whitelist": "grey"}),
544
+ ], theme='Jameswiller/Globe', title = title_prompt, description = description_prompt, allow_flagging = 'auto')
545
 
546
+ #theme='gradio/monochrome'
547
+ #theme='ParityError/Interstellar'
548
 
549
  if __name__ == "__main__":
550
  demo.launch(share=True)
551
 
552
+ '''
553
  # Add default picture for output
554
  # Output as graph of just text but with fancy representation -- use labels from theme
555
  # Generate picts for output with GenAi
 
558
  title_raw = 'When expectations work race and socioeconomic differences in school performance'
559
  abstract_raw = 'Why race between are expectations for future performance realized more often by some people than by others and why are such differences in the efficacy of performance expectations socially patterned we hypothesize that differences in attentiveness to performance feedback may be relevant reasoning that follow-through behaviors will be less well conceived when expectations are formed without regard to evaluation of previous performance. using data from baltimore fourth-grade students and their parents we find that expectations anticipate marks more accurately when recall of prior marks is correct than when it is incorrect. because errors of recall mostly on the high side are more common among lower-ses and minority children and their parents their school performance is affected most strongly. research on school attainment process from a motivational perspective must give more attention to the additional resources that facilitate successful goal attainment given high expectations. our perspective focuses on resources internal to the individual but external constraints also are important. the discussion stresses the need for further work in both areas.'
560
 
561
+ title_raw = "Race-related Research in Economics disadvantaged minor race disparity"
562
+ abstract_raw = "Issues of race disparity "
563
+
564
+
565
  #Default
566
  title_raw = "Race-related Research in Economics"
567
  abstract_raw = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics."
 
569
 
570
 
571
  #non-RR
572
+ title_raw = 'Hurting stalemate or mediation the conflict over nagorno-karabakh 1990-95'
573
+ abstract_raw = 'The impacts of six attempts to mediate the conflict over the political status of nagorno-karabakh in the caucasus region of the former soviet union were compared. each mediation was intended to get the direct parties armenia azerbaijan and nagorno-karabakh to the negotiating table. nearly 4000 events were recorded for a six-year period from 1990 through 1995. each event was coded in terms of a six-step scale ranging from a significant action toward peace 3 to substantial violence directed at an adversary -3. time-series analyses of changes in the extent of violence showed no change from before to after any of the mediations. a significant change did occur however between the months preceding and following the period of intensive combat between april 1993 and february 1994. these results support the hypothesis that a mutually hurting stalemate is a condition for negotiating a ceasefire and reduced violence between warring parties. a number of theoretical and practical implications of the findings are discussed.'
574
 
575
+ title_raw = ""
576
+ abstract_raw = ""
577
 
578
  rr_detector(title_raw, abstract_raw)
579
 
580
+ '''
581
+
582
+
583
+
584
+
585
+
586
+ #TEXT ANALYSIS -- IMPROVE
587
 
588
+ # Graph: looks like when it is two words, it double count it: (this paper is about racial inequality, this paper is about racial inequality)
589
+ #PROBLEM OF DOUBLE COUNT: GROUP (disadvantaged minor[a-zA-Z]{0,5}) and ISSUE (disadvantage)
590
 
591
 
592
 
593
+ def highlight_words(sentence, words):
594
+ for i in range(len(sentence)):
595
+ for j in range(len(words)):
596
+ if sentence.lower().startswith(words[j].lower(), i):
597
+ sentence = sentence[:i] + sentence[i:i+len(words[j])].upper() + sentence[i+len(words[j]):]
598
+ return sentence
599
 
600
+ print(highlight_words("Have a nIcE day, you Nice person!!", ["nice"]))
601
+ print(highlight_words("Shhh, don't be so loud!", ["loud", "Be"]))
602
+ print(highlight_words("Automating with Python is fun", ["fun", "auTomaTiNG"]))
images/default.png CHANGED
images/no.png CHANGED
images/yes.png CHANGED