How to Understand Men: Building a ‘Boyz II woMen’ Text Translator in Python

Alice Yen
8 min readJul 17, 2017

--

Relationships are all about communication — how we convey our emotions to our significant others, understand how they make sense of this crazy world, and empathize when one of us faces a welcome (or unwelcome) life surprise. These days, communication between special someones more often than not happens over text. Maybe it all starts with a flirty iMessage or the old school ‘hey’ SMS at two thirty in the morning. It’s only later on into the relationship that texts shift to how we figure out where we’re headed for dinner Saturday night and how you tell me you’re thinking of me in the middle of the work day when you share that random gif trending off Reddit (are you on your lunch break?).

After many ladies nights filled with frustrations about some ‘seemed like a good guy,’ it comes as no surprise that men and women communicate differently, particularly when it comes to texting in romantic contexts. Along with many other women, my texts are filled with emojis and exclamation points while most of my male counterparts’ are passing by with one-word “Hey.”s and “Thanks.” It’s not to say these men aren’t full of wisdom and witty banter — I know they are. But more often than not, males and females diverge in how they communicate with one another.

Over July 4th weekend, while hiking with a few friends on a trail called Inspiration Point in Berkeley, ‘inspiration’ struck. Maybe it was the fresh air sweet with freedom, independence, and cow manure or the stunning 360 degree views of the grassy hills echoing of life, liberty, and the pursuit of happiness. While making our way up to the viewpoint, we chatted about our goals for the summer, as one does when hiking up to a pinnacle of inspiration.

In true Bay Area fashion, I shared how I am hoping to learn how to code in Python and make the most of my time being back in San Francisco. Soon after, we broached the often-discussed topic of dating in the Bay, observing how so many single straight women are caught in these waters where the “odds are good, but the goods are odd.” I thought back to conversations where so many of my girlfriends texted back-and-forth with some ‘seems like a good guy’ on Tinder / Bumble / Coffee Meets Bagel / Hinge / The League / pick-your-own app but soon found themselves having things lost in translation (not the literal Bill Murray can’t speak Japanese Lost in Translation, but the ‘He didn’t return my winky face emoticon… will we make it?’ kind).

It dawned on me that it is possible to merge these two topics of interest with one fun side project — using Python to build a “men to women” text translator, which henceforth shall be called the “Boyz II woMen” text translator because who doesn’t like the smooth harmonies of 90’s R&B?

As I started the process, however, I soon hit the initial hurdle of coding— How do I begin? I Googled things like “How to build a text translator” and found myself jumbled between foreign language translation services and all sorts of computer software packages that can help you translate one obscure computer language to another. It was only after a conversation with my friend K who advised,

“You have to remember computers don’t understand English. Think about how they process information — it’s all inputs and outputs.”

Taking her advice, I thought about how a translator is analogous to how a computer would process a dictionary or thesaurus, where one word is substituted for another. My Googling shifted away from “translators” to more conceptually understanding how to build dictionaries and replace terms in Python strings.

I downloaded Sublime Text (a text editor used to write code), opened up my Terminal (the window used to process Python and spit back my output), and started coding. With the mindset of how do you have a string input and get back a translated output, I determined I needed to create a substitution mechanism, where certain words would convert into ‘translated’ words and phrases.

After extensive user research and an exhaustive review of historical texting behaviors from my male friends in the Bay (thanks guys!) along with a sprinkling of hyperboles (because why not spice it up a bit?), I inputted a mix of translatable phrases to serve as the source of truth for the Boyz II woMen text translator. Including a sampling of such translations below.

Formatting for reference: “Any time a man [Boyz] uses this word/phrase” II “It becomes this [woMen] word/phrase”):

  • Boyz II woMen
  • hey II oh helllllo you beautiful strong independent woman
  • thanks II thank you sooooo much
  • like II red heart emoji
  • my girlfriend II my meant-to-be soulmate

For my test case, I inputted the following [pseudo] text string from a [pseudo] male living in San Francisco (Go get ’em, ladies!). Let’s call him Josh, and let’s call his lady friend Liz. Here goes Josh:

… After you work that Boyz II woMen text translation magic, it becomes …

All of the sudden, Josh’s [psuedo] text of manly affection has been upgraded to an excited little boy in middle school who still hasn’t figured out more lettersssss doesn’t make his words more powerfullll. Thanks to the Boyz II woMen text translator, Josh’s typical “Hey.”s and “Thanks.” have become so much more captivating.

For those curious, from here on out, we’ll focus on understanding and breaking down the Python code. For reference, see a snapshot below and on Github here.

“Boyz II woMen” Text Translator Python code in Sublime Text …
… with results in Terminal after running Python

To understand what’s happening behind-the-scenes in the Python code of the Boyz II woMen text translator, I’ve divided each section by a hashtag (used in coding as comments so you can see a summary description for each section within the code itself).

#Defining the method

# defining the method for how we will translate Josh texts to Liz texts
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text

First, to define the logic I am running upfront, I use [def replace_all(text,dic)] to let the computer know I will be giving it replacement terms (j) to substitute anytime it sees designated terms (i). This reasoning is essential to the idea of using substitute terms, similar to a dictionary or thesaurus.

#Inputting the pseudo text

# the pseudo text Josh sends which will ultimately be translated into comprehendible Liz text
JOSH_TEXT = "hey. what are you doing tonight? i'm gonna grab drinks later with some friends if you wanna join."

Here’s where I drop in Josh’s man/boyz text and define our input variable as “JOSH_TEXT,” setting it equal to the designated phrase of interest (per above, “hey. what are you doing tonight?”).

#Translation dictionary

# our Josh to Liz translation dictionary with our key:values.
REPS_WORDS = {'hey':'why hello you beautiful independent woman',
'what are you doing tonight':'just thinking about you and wondering what you are up to','if you wanna join':'if you are up for hanging out because i think you are amazinggg [winky face][red heart emoji]','okay':'amazingggg', 'good':'incredibleeee', 'like':'red heart emoji', 'thanks':'thank you soooo much', 'babe':'mah lady','my boyfriend':'my meant-to-be soulmate','my girlfriend':'my meant-to-be soulmate','haha':'lolll','yeah':'yesss','baby':'my wonderful significant other', '.':'!', '!':'!!!!!', '?':'??'}

Next, I’m going to skip the “#Capping the excitement” section and jump to the dictionary itself (don’t you worry, we’ll get to “#Capping the excitement” right after). Here in this #Translation section, I define our dictionary variable REPS_WORDS (call it whatever — I used REPS_WORDS to refer to ‘replacement words’). In Python, I can create what is called an “associative array,” essentially a legend for how one phrase links to another. Here, I am able to tie an input key to an output value. For example, ‘Hey’ in Josh-speak becomes ‘Oh helllllo you beautiful strong independent woman’ in Liz-speak. An exclamation point ‘!’ for Josh translates to a whole lot of exclamation points “‘!!!!!’ for Liz (a 5:1 ratio, in fact). In Python, this linking is designated by a colon ‘:’ and can include a list of pairings (divided by commas) as shown in the code screenshot above.

#Capping the excitement

# our Josh to Liz translation dictionary with our key:characters to put a max on the excitement
if JOSH_TEXT.count(‘!!’) <= 1:
JOSH_TEXT
else:
COUNT = JOSH_TEXT.count(‘!!’)-1
JOSH_TEXT = JOSH_TEXT.replace(‘!!’,’’,COUNT)

Now that I have defined the dictionary itself, let’s jump back to the “#Capping the excitement” section. Given I have set one Josh exclamation point to translate into five Liz exclamation points, I recognize there may be a case for wayyyy too much excitement. I mean, if Josh decides he’s so excited (three exclamation points worth) that Game of Thrones came back on Sunday, Liz (post-Boyz II woMen translation) has gone through the roof with a solid fifteen exclamation points!!!!!!!!!…

In order to cap the excitement such that Josh is not overwhelmed by Liz’s enthusiasm, I’ve built in a check such that the most exclamation points that can occur are ten for our translated Liz output.

I debated how to code this check and ultimately determined the best method was to set a cap on exclamation points upfront before I translate Josh’s text into Liz’s. This intermediary step essentially caps Josh’s usage of exclamation points to two max such that the most points Liz’s translated phrase can have is ten (2x5).

In the code, I count the number of ‘!!’s. If there are only two exclamation points, the translation runs through as expected. However, if there are more, then I will replace Josh’s extra exclamation points with nothing [or two quotes ‘’ as it reads in the code, essentially deleting the extra exclamation points. This is denoted below ‘else’, where if JOSH_TEXT has more than one set of ‘!!’, then I replace the additional ‘!!’ with two single quotes ‘’ [aka nothing], making it disappear and ready for further translation as described in the #Translation dictionary section above.

Printing the final output

LIZ_TEXT = replace_all(JOSH_TEXT, REPS_WORDS)print LIZ_TEXT

After I have officially wrapped up all replacements, where I define LIZ_TEXT by replacing all REP_WORDS terms in our input phrase JOSH_TEXT, I can then ‘print’ our output, which is our final translated Liz-speak string. Hence, “oh helllllo you beautiful strong independent woman!”

… And there you have it, ladies and gents / Josh’s and Liz’s … The Boyz II woMen Text Translator is ready for your texting consumption and entertainment. In this world where texting remains a major communication platform for the foreseeable future, there is no question emotions will get lost in the mix of emojis and emoticons, particularly when there are so many fish to ‘swipe’ at in these tumultuous romantic waters. More often than not, it’s sometimes worth giving those texting thumbs a rest and meeting up for a coffee instead. Feelings are sometimes best felt in person.

And with that, I’m signing off to go grab a coffee.

See ya, Josh [… or translated ….] xoxoxo, Liz 😍 ☕ 😘

Additional Notes:

  • The Josh-Liz dynamic is based on real accounts of straight male-female Bay Area relationships but is not intended to be representative of all such relationships.
  • The third # section that mentions capping the excitement level was recommended by my favorite G.
  • Thanks (translation: Thank you soo much!!!!) to free online resources and websites like Stack Overflow for the guidance and to K, A, J for a great hike. … And of course, Inspiration Point’s cows for the inspiration.

--

--