Adventures in Digital History

Pythonic Paraphrasing: Gender Guesser

This week has been all about coding. Sometimes I feel like I can do anything with Python, but most days I get the feeling that I’m lost. I do enjoy it, though! I wouldn’t have taken Creative Coding last semester or made my final project in Applied Digital Studies coding-based if I didn’t like it on some level. However, I’ve come to appreciate how much you can do with coding. You can write code for just about anything, and it’s constantly changing and evolving to suit your needs!

I actually am a little ahead of the game in this class, because I completed the next assignment over a week ago. I didn’t do this to show off or anything, but simply because I have three other projects coming up in the next week. I made the decision to use my free time wisely, and I’m now reaping the benefits.

Plus it gave me some free time to play D&D with my friends earlier this week.

I know, my priorities are in order.

Anyways! For my Pythonic Paraphrase project, I decided to remake Hacker Factor’s Gender Guesser. We first read about this example in Ben Blatt’s book, and my interest was immediately sparked. Earlier in the semester I ran the entirely of Ursula Le Guin’s “The Ones Who Walk Away From Omelas” into Hacker Factor’s Gender Guesser and was fascinated that it claimed she was a man.

I, of course, had to recreate it and replicate the experiment for myself.

And that’s exactly what I did! I’ve included the entire coding project in the page below, but if anyone would like to view it in its original coding-friendly environment, or even test it for themselves, here is the link to my Pythonic Paraphrasing: Gender Guesser Colab Notebook! This notebook also contains more of an explanation of what is happening in the code, but I’m putting it here for easy reference.

!unzip "/content/"

files = glob.glob("/content/corpora/*/*.txt")

import nltk'punkt')'averaged_perceptron_tagger')

from textblob import TextBlob
import glob

# Formal Dictionary
dictionaryFormal = {}
dictionaryFormal['a']= 6
dictionaryFormal['above']= 4
dictionaryFormal['and']= -4
dictionaryFormal['are']= 28
dictionaryFormal['around']= 42
dictionaryFormal['as']= 23
dictionaryFormal['at']= 6
dictionaryFormal['be']= -17
dictionaryFormal['below']= 8
dictionaryFormal['her']= -9
dictionaryFormal['hers']= -3
dictionaryFormal['if']= -47
dictionaryFormal['is']= 8
dictionaryFormal['it']= 6
dictionaryFormal['many']= 6
dictionaryFormal['me']= -4
dictionaryFormal['more']= 34
dictionaryFormal['myself']= -4
dictionaryFormal['not']= -27
dictionaryFormal['said']= 5
dictionaryFormal['she']= -6
dictionaryFormal['should']= -7
dictionaryFormal['the']= 7
dictionaryFormal['these']= 8
dictionaryFormal['to']= 2
dictionaryFormal['was']= -1
dictionaryFormal['we']= -8
dictionaryFormal['what']= 35
dictionaryFormal['when']= -17
dictionaryFormal['where']= -18
dictionaryFormal['who']= 19
dictionaryFormal['with']= -52
dictionaryFormal['your']= -17

# Informal Dictionary
dictionaryInformal = {}
dictionaryInformal['actually']= -49
dictionaryInformal['am']= -42
dictionaryInformal['as']= 37
dictionaryInformal['because']= -55
dictionaryInformal['but']= -43
dictionaryInformal['ever']= 21
dictionaryInformal['everything']= -44
dictionaryInformal['good']= 31
dictionaryInformal['has']= -33
dictionaryInformal['him']= -73
dictionaryInformal['if']= 25
dictionaryInformal['in']= 10
dictionaryInformal['is']= 19
dictionaryInformal['like']= -43
dictionaryInformal['more']= -41
dictionaryInformal['now']= 33
dictionaryInformal['out']= -39
dictionaryInformal['since']= -25
dictionaryInformal['so']= -64
dictionaryInformal['some']= 58
dictionaryInformal['something']= 26
dictionaryInformal['the']= 17
dictionaryInformal['this']= 44
dictionaryInformal['too']= -38
dictionaryInformal['well']= 15

with open("corpora/morrison_corpus/Morrison-bluest-eye.txt") as f:
  text =

blob = TextBlob(text)

male_formal = 0
male_informal = 0

female_formal = 0
female_informal = 0

for word in blob.words:
  if word in dictionaryFormal:
    if (dictionaryFormal[word] > 0):
      male_formal += dictionaryFormal[word]
    if (dictionaryFormal[word] < 0):
      female_formal -= dictionaryFormal[word]

  if word in dictionaryInformal:
    if (dictionaryInformal[word] > 0):
      male_informal += dictionaryInformal[word]
    if (dictionaryInformal[word] < 0):
      female_informal -= dictionaryInformal[word]

print("Formal Male: " + str(male_formal))
print("Formal Female: " + str(female_formal))
print("Informal Male: " + str(male_informal))
print("Informal Female: " + str(female_informal))

if (str(male_formal) > str(female_formal)):
  print("Higher Formal Male Score")

if (str(male_formal) < str(female_formal)):
  print("Higher Formal Female Score")

if (str(male_informal) > str(female_informal)):
  print("Higher Informal Male Score")

if (str(male_informal) < str(female_informal)):
  print("Higher Informal Female Score")

Leave a Reply

Your email address will not be published. Required fields are marked *