I couldn’t miss the fun Twitter hashtag #BadStockPhotosOfMyJob thanks to a tweet by Julia Silge and another one by Colin Fay. The latter inspired me to actually go and look for what makes a data science photo… What characterizes “data science” stock photos?
My (not bad) stock photo source
Pexels metadata for the win
Where to find information related to stock photos? In two previous blog posts of mine I used Pexels, a website providing CC0 pictures which is quite nice. My goal was to obtain the titles and the tags of stock photos of “data science”: for instance if you look at this picture, its tags are “business”, “contemporary”, “computer”, etc. Pexels tags are very useful metadata, saving me the effort to use machine learning methods to analyse images.
Responsible webscraping
When researching this post I discovered that Pexels has an API, documented here but this API does not get you the title nor the tags associated to a picture so only webscraping could get me what I needed.
Webscraping is a powerful tool allowing one to rectangle webpages but with great power comes great responsability. Being able to scrape a webpage does not mean you are allowed to. You could get sued or your IP could get blocked. I am far from being an expert but I often read Bob Rudis’ blog where I learnt about rOpenSci’s robotstxt package that does “robots.txt file parsing and checking for R” which in plain language means it checks for you what a webpage legally allows you to do. See below,
# how I'll find pictures
robotstxt::paths_allowed(&quot;https://www.pexels.com/search&quot;)
## [1] TRUE
# where tags live
robotstxt::paths_allowed(&quot;https://www.pexels.com/photo&quot;)
## [1] TRUE
robots.txt files often also tell you how often you can hit a page by defining a “crawling delay”. Sadly Pexels robots.txt doesn’t:
robotstxt::get_robotstxt(&quot;https://www.pexels.com&quot;)
## Sitemap: https://s3.amazonaws.com/pexels/sitemaps/sitemap.xml.gz
But Bob Rudis, who was patient and nice enough to answer my questions, told me that I should probably respect the rate limit defined in Pexels API docs. “Do not abuse the API. The API is rate-limited to 200 requests per hour and 20,000 requests per month.” As I recently explained in a post on Locke Data’s blog, these days to limit rate of a function I use the very handy ratelimitr package by Tarak Shah.
limited_get %
ggplot() +
geom_lollipop(aes(bigram, n),
size = 2, col = &quot;salmon&quot;) +
hrbrthemes::theme_ipsum(base_size = 16,
axis_title_size = 16) +
ggtitle(&quot;300 data science stock photos&quot;,
subtitle = &quot;Most frequent bigrams in titles. Source: https://www.pexels.com&quot;)+
coord_flip()
So there’s a lot of holding computer happening, and these laptops are either black or white… And well Macbook Pro probably looks more professional?
Hold my laptop and watch…
my trying to find a good post conclusion! In this post, I tried to responsibly and elegantly scrape rich photo metadata from Pexels to characterize stock photos of data science. Using tags, and most common bigrams in titles, I found that data science stock photos are associated with data, business and computers; and that they often show people holding computers. Now, you’ll excuse me while I try and comfort my poor pink laptop that feels a bit too un-data-sciency.