Stop Wasting Time Watching Your Machine Learning Model Train

Michael McManus
7 min readOct 8, 2021

--

Photo by Tim Gouw on Unsplash

While working on a project recently, I realized I wasted a lot of time sitting around waiting for my models to train or coming back to it repetitively out of anxiety and nervous anticipation. Sort of like when you’re waiting for that “something special” to arrive in the mail and you check the mailbox a hundred times a day until you receive it. Could be a tax return for instance. Anyway, this is what I had going on while trying different modeling approaches and methods and it suddenly occurred to me, I know how to send a text to myself using Python, so why not send myself a text when my model is done training? In fact, I have a model training right now while writing this article and I’m able to focus because I’ll know immediately when the model is done training. In this article I’ll show you how to send yourself a text message using Python so you too can avoid the countless trips to the “mailbox”.

Background and Fundamental Knowledge

Sending Texts via Email

Firstly, to avoid paying a third party service like Twilio to send text messages through an automation process, you can send a text message via email to any phone number for free. All you need are the phone number, the mobile carrier, and the mobile carrier’s domain.

Quick Clarification of Terms

A carrier is the company that provides the cell phone service; a domain is the part that comes after the @ in an email address like @gmail.com or @outlook.com. As an example, let’s say your mobile carrier is Verizon and you want to send yourself a text message as proof of concept. Assuming your phone number is (111)-222–3333 in the To: line of your email, you would type 1112223333@myvswpix.com .

If you’re not a Verizon customer, there’s a great table to get you started with all the major carriers on Wikipedia. There’s a more comprehensive table of MMS domains/gateways here, and SanDisk has one as well. Chances are, you’ll find what you need in one of those places. If not, just do a quick search for (my carrier) sms mms gateway and I’m sure you’ll find a resource to fit your particular use case. For ease of use, a quick reference table for gateways to some of the major mobile carriers in the U.S. can be seen below.

Table by Author Adapted from Multiple Sources

Note: I’m less familiar with mobile carriers outside the U.S. so I’m not sure which ones would be useful to include. If you’d like me to update the table with any particular carriers, leave a comment below and I’ll update as requests come in.

Case Study — Send a Text to Yourself

Try it! Go to your email, compose a new email, and in the To: box type your phone number without spaces or hyphens at the domain your carrier uses. As an example, if your phone number (U.S.) is inexplicably (111)-222-3333 and you are a Verizon customer, then you would enter 1112223333@vtext.com . Write yourself a friendly message, i.e. To whom it may concern, You are amazing!and send it. Wait a moment… now check your phone. You just successfully sent yourself a text message via email. Next we’ll explore how to write a Python script that sends text messages via email.

Sending Text Messages with Python

Now that we know we can send text messages for free via email, all we need to do now is send an email with Python. If you already know how to send an email with Python, simply use the method described above to set the To: field of the email accurately and you’re on your way. If you don’t know how to send an email with Python or you don’t have a good understanding of when or why to use SMS vs MMS, read on.

Types of Text Messages and When You Should Use Them

You may be asking, when or why should I use SMS vs MMS to send a text message? For this application, sending a text message to alert you that your machine learning model is finished training, you likely want to just use SMS. There may be circumstances when sending an MMS might be the better option though, so we’ll go over that here.

Definition of Terms

SMS (Short Message Service) is a regular text message, MMS (Multimedia Message Service) is a picture message. Mobile carriers often call their SMS/MMS domain a gateway. SMS and MMS text message types often have different gateways within the same carrier. You can reference the table above for some examples of this.

SMS vs MMS

Think of SMS as a simple short message to your mother: Hello, Mom. I love you. Now think of MMS as that long message you sent to your best friend outlining the crazy experience you had at the grocery store and how the cashier was rude and impatient with you and how you’ll never return. Personally, I don’t send many MMS type text messages but the analogy holds. Were you to send the message about the rude grocery clerk via SMS, the message would be broken up into a bunch of shorter messages. Sent via MMS, the message would appear as one long message. Ever typed a long message and seen the 1/2, 2/2 indicator? That’s an SMS message being created and this happens because there is a character limit on SMS messages. In other words, if you send a long SMS message then you’re bound to send several short messages which break up the longer full message. If you send a message as MMS, your message won’t be broken into several messages if it is long.

Let’s see what happens when we send the same message via SMS and MMS:

To whom it may concern,

You are amazing! This is a very long message to illustrate the point that SMS will break this message up into several shorter messages while MMS will send the entire message in whole. As a side note and completely irrelevant, what if the hokey pokey really is what it’s all about? I’m not sure I buy into that level of existentialism but it’s a fun question nonetheless. Good day.

SMS and MMS:

Guess what. The SMS version never fully made it to my phone. All that arrived was the version you see above. The MMS version was fully viewable after I pressed the View All option on my phone. Results may vary depending on your phone and mobile carrier but the point remains. Send SMS for short messages because they are typically free. MMS messages could come at a cost as they are Multimedia messages and require data usage to download.

Send an Email with Python

I’m going to spare you a bunch more reading and just kind of cut to the chase here. There are two ways I think that are common to send an email with Python. Firstly, in a workplace setting, I think it’s fairly common to use Microsoft Outlook so I’ll show that first. I think it’s all around simpler. Secondly, you may want to use Gmail, Yahoo, or some other email… AOL? If you’re still using an AOL email address, your fortitude is admirable. I’ll leave it at that.

Sending an Email with Python via Outlook

This method is very simple. Here is an example script.

Sending an Email with Python via Gmail

This method is a bit more tricky and involved. Rather than walk you through all of the setup steps required to send an email via Gmail, I’ll defer you for now to a great article I learned from. In the future, I hope to create a longer tutorial on this step. In short, you’ll need to create an App Key through your Google account in order to do this. Just follow Step 1 from this great tutorial.

After creating the app key, I would create a separate Python file where you can import all your secrets from. This way, the script your running won’t have to contain your app key which is essentially a password. You’ll see that in the version of the script below. You’ll see the import statement from MyCreds.mycreds import Google . Contained in that Python script is a class, the attributes of which contain my Google email, password, phone number etc.

There you have it. All you have to do there is pass a string to the function which will become the text of the body of the email, or in this case text message, and then simply call the function in your script after your machine learning model is finished training and you’ll know the second it’s done.

As always, thanks for reading. If you have any questions let me know in the comments below.

References

--

--

Michael McManus

Master of Applied Data Science — University of Michigan School of Information.