We all have smartphones these days, and we take them with us everywhere we go.
How much could you infer about a person, their stage in life, their driving style,
their work-life balance, based on just a phone's motion and GPS data?
With the right mix of analytics and machine learning, it turns out you can learn a lot
about a person. Are they a dog-owning workaholic or an early rising parent of young children?
This week you'll meet Vincent Spert, who is the chief data scientist at Sentience,
a company building an SDK to answer these exact questions. You'll learn how they're using Python
to make this happen and how they think this data could be used for the greater good.
This is Talk Python to Me, episode 135, recorded October 25, 2017.
Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the
ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,
and follow the show on Twitter via at Talk Python. This episode is brought to you by Datadog and
GoCD. Please check out what they're offering during their segments. It really helps support
the show. Vincent, welcome to Talk Python.
Thank you.
It's great to have you here. You guys have a super cool platform. You're doing some seriously
deep learning and AI and machine learning, and I think everyone's going to get a pretty cool look
at what you guys are doing and how you're doing it. There's a bunch of cool algorithms going on here.
But before we get into all that detail, let's talk about how you got into programming and Python,
things like that.
Yeah, sure. Cool. It started when I was about 14, and I started hacking around with some web design.
Remember those days where everyone used those marquee banners? There was no CSS and stuff like
that.
Like the blink tag. Yeah, yeah, that was wonderful. Those were good days.
Exactly. So over the years, I went more into network security and hacking, started a company
when I was around 18, and converted more to languages like Java and C++ throughout my PhD.
What was the company you started when you were 18?
It was a network security company, so quite different from what I'm doing today. It was
a lot about the... You know, back then, the internet was more or less the Wild West. Everything
was wide open, so interesting times.
Yeah, I remember back then that things like Windows XP was the most popular operating system,
and it had no firewall at all.
Yeah, yeah, exactly.
Right?
Exactly.
No, it was right on the internet. It was really bad. Yeah, cool. Okay, so yeah, those were interesting
Wild West days for sure. And then you said you moved on to...
C++ and Java?
Yeah, so during my PhD, I was mostly working on computer vision, machine learning, so that
was heavily focused on real-time processing, so most of the work was done in C++. And then
I joined Sentience about three years ago to start out a data science team. So back then, Sentience
was quite small. I think we were with five people. And we had to choose a main programming language
for the machine learning stuff, the data science part. And so I guess, coming a bit from an academic
background, I was looking for a language that both had the ease of use as that MATLAB or
R has. But on the other hand, also is a language that allows us to go to production and build
scalable systems. That's how we came up with Python. And so since then, Python has been
my go-to.
Yeah, that's really great. Three years ago, I think it was probably on the border of whether
Python was going to be one of the really dominant machine learning languages. I mean, now it's
like really a clear choice. But three years ago, it was just starting to be a clear choice,
right? What other things did you consider? And why, in the end, did you choose Python?
The thing is that obviously you don't want to use MATLAB in a production system. So then I guess the
choice was whether or not we would want to use a programming language like Java for the data science
work. And there has been some discussion around that because the data engineering team here at
Sentience does most of the stuff in Java, you know, making sure everything is scalable, all the
infrastructure stuff is Java. But for us, we noticed that although we love Java, doing rapid prototyping,
quickly coming up and testing your models, it's just much easier in Python. And actually,
although there is a lot of discussion on whether or not Python is a production-friendly language,
if you look at, for example, YouTube, they also use mainly Python for their whole platform. So
it's quite powerful.
Yeah, it's incredibly powerful. You look at some of the people or some of the companies doing
really interesting things. YouTube is a great example. YouTube handles like a million requests per
second. So that's a pretty insane level of web traffic right there. And yeah, there's some other
really cool use cases like that as well. So I guess the main takeaway is sort of the combination of
it's quick and easy, but also you can go fully to production, like all the way to like real scalable
levels of running and production, right?
Yeah, indeed. And of course, the machine learning communities is, these days is growing. And I mean,
the amount of libraries and support you have for machine learning in Python is just huge compared to
almost any other language.
Yeah, absolutely. So what do you do at Sentience now?
So I'm the chief data scientist at Sentience. So basically, my job is mostly focused on the research
part and on building the algorithms together with the team, of course. So Sentience is an AI company
first. So we are currently with about 50 people, and about 40 of them are actually technical, half of
them data engineering, and half of them data science. And with data science, we mostly mean, you know,
machine learning, signal processing, building the actual algorithms there.
Okay, that sounds, that sounds pretty awesome, like a pretty fun job to be part of, I'm sure.
So I guess, you know, probably a lot of the listeners don't know about Sentience, maybe give us
like a high level idea of what you guys do. I mean, you have this specific SDK that people can plug into
their mobile apps. And then you look at the behaviors and stuff. Tell us what the big idea is.
Well, the idea is that these days, I mean, everyone has a smartphone, to that extent that the
smartphone is almost like an extension of your body, you continuously use it. And every smartphone
is packed with sensors, you have accelerometer sensors measuring every small vibration of the
phone, you have the gyroscope, of course, you have the location subsystem. So what we do is we have an
SDK that plugs in into the app of our customers, which are companies. And once the SDK is in the app,
we start logging all that sensor data, accelerometer, gyroscope, location, we send that to our backend,
running on Amazon Cloud. And there we have a bunch of machine learning algorithms that extract behavioral
intelligence from it. So we learn about your behavior. What is your home? What is your work
location? What do you do every day? Why do you do it? Can we predict your future behavior, etc?
Wow. Okay. So I totally agree that, you know, it's a crazy world where we always have our phones with us.
Like I would rather accidentally leave my keys at home and leave my house unlocked and leave my house
without my phone. You know what I mean?
So if you can take this information about what people are doing just ambiently, I do more with it. That sounds
pretty cool. So you take all the sensor data, orientation, accelerometer, location, things like
that. And you say you extract intelligence from it. So I watched there's a video on your homepage,
I'll link to it in the show notes where you have these different layers, right? Like one layer comes in and
just takes in this ambient deformation. One tries to understand what you're doing. And then the other,
what's the final one to try to create like these moments or something? Tell us about that.
We start with a low level sensor data. And based on that, we do what we call event detection. So we
have a whole bunch of classifiers that take in the sensor data and for example, try to classify your mode
of transport. Based on the vibrations of the phone, you can figure out is this person walking,
biking in a train, on a subway, in a car, or for example, given your location, your current location,
we want to figure out where are you? I mean, are you visiting the bus stop that is five meters from
your location? Or maybe if you're there in the middle of the night for five hours in a row,
you're not visiting the bus stop, you're actually in the bar that is like 50 meters further, right?
And so we end up with this whole timeline of human behavior. But of course, then you know what the
user is doing, but not why he's doing it. So we feed this event timeline into our deep learning
based prediction model, we can predict what you're going to do next. And that allows us to explain why
you're doing something, you know, is this are you in a car because it's your commute or because it's
your shopping routine? Is this a business trip? Is it a leisure trip, etc. And then finally, indeed, we
aggregate all that data, all those timelines over weeks. So we can come up with with more like a profile.
Are you a shopaholic, a workaholic? Are you an aggressive driver? Do you have children? And that data we then
expose back to our customers.
That's pretty wild. It sounds really challenging, because like you said, there could be a bar and
then right outside the bar could be, you could be sitting like right in the front, you know, with
like maybe on a beautiful day, like the windows are open or something. And then right next to that is a
bus stop. And so determining whether you're trying to go on the bus, or you're trying to relax after
work. That sounds like a real interesting challenge.
Yeah, exactly. Even more, I mean, you can be in a bar because you work there, you can be in a bar because
you just like to go for a drink, you can be there because you live in the apartment on top of it. So
trying to figure out why a user is doing something is pretty cool.
Yeah, that's definitely taking it to another level. So what is your day to day look like? Do you do a
lot of research? What kind of tools do you do to come up with some of these models? Do you write
production code? What are you doing?
It's a mix of both research and actually writing production code indeed. So most, most of the time when we start
on a project, there is a research phase. I mean, there's a lot of reading papers, experimenting, usually just in
iPad and notebooks, you create your models, you validate them. But then at some point, indeed, we have to convert
this code into something that is production ready. So then it actually comes or boils down to cleaning up the code,
creating a nice object oriented framework. Do you need testing, regression testing, you know, performance profiling,
make sure that everything is scalable, and then encapsulate it into an API so that we can deploy
this as a microservice. And finally, try to get a microservice running in a Docker image. And that is
actually then when the data engineering team comes in. So the data engineers take this Docker image,
refine it, basically, they built a base Docker image. So we just customize it a little bit for our specific
projects. And they help us to make sure that we can deploy it in a scalable manner.
That's cool. And do you guys deploy it to your own system? Or do you deploy,
I forgot what AWS is container service is called? But do you deploy it to the container service? Or do
you have more control over where it lives and runs?
It's our own system. So we try, I mean, we love AWS, but we try to be not too dependent on their
specific services, mainly because we need to be able to move to different cloud infrastructures if needed.
Isn't that an interesting struggle? Like, there's so many features and AWS and Azure, those are the two that
have like, a ridiculous number of things that the cloud can do. But the more that you like, put those
hooks into your system and those dependencies, like the more you're locked in, I mean, people used to talk
about lock in like with Windows or with Mac or with iOS or whatever. But like, the cloud lock in is a whole
another level if you go all in, right? Yeah, exactly. And of course, that's their business model. I mean,
they try to get you to use those specific services.
Yeah. Yeah, that's cool. Okay, so go with your own container service. That makes a lot of sense.
And for the tooling for R&D stuff, this is like IPv3 notebooks. And what are the notable packages and
libraries using there? It depends on the project, I guess. Obviously, we just use a lot of typical
libraries like scikit-learn for most of the modeling. When we talk about deep learning,
it's usually TensorFlow and some Keras. For performance and memory profiling, we create
things like flame graphs. For unit testing, we use a pytest or nosetest. Yeah, nice. Are you using
like GPU clusters in AWS or is this pure CPU-based? For deployment at inference time, it's usually CPU-based.
For research, I mean, like training the models, we indeed use GPU machines because it can take a few
weeks before a model is trained. So that really speeds it up. Yeah. And how fast is it if you use
GPUs? Also weeks. And if it's not GPUs, it's even worse. Yeah, exactly. So the last model I trained a
few weeks ago, I started using, I started out using an AWS machine that was just a CPU machine with 36
cores. And eventually, I moved to a GPU machine where I trained about two weeks. And the training there,
I mean, the loss went down about 10 times as fast as when I was using the CPU machines.
Wow, that's really awesome. Yeah. And for performance and stuff, you just get that
basically dialed in, I guess. There's two parts, right? There's training and then there's answering
the question, the inference bits. How do you sort of balance those things? Like obviously,
you're just going to train as much data as you need. But then what do you do for performance at
that point? I mean, once you have the model built and you kind of have the library, you're using
TensorFlow or whatever, you kind of like how much flexibility do you have to make it go faster?
Well, that's a good question. And usually, it's really just trying to balance performance and
cost, I guess. I mean, you can have a model with 3 million parameters and have a gain of 1% in
accuracy compared to a model with 300,000 parameters, right? While the latter, of course, is much cheaper
to be used in production. So a lot of the time, it's just balancing out those two.
Okay, that's interesting. Do you sometimes build like super detailed models in the research phase and go,
I think we can take it down to 100,000 or whatever levels and then run that in production and get good
enough answers? Yeah, we do. Especially, of course, if you, some of our models started out on the cloud,
and then at some point, we realized, you know, we could actually deploy those on the mobile phone
itself. So then it's very important to reduce the number of parameters as much as possible without
losing too much accuracy. So yeah, that's really cool. And that's definitely a trend in the space to
not have these tremendously powerful cloud infrastructures, but to push it to the edge, right?
To the devices.
Yeah, indeed, indeed. It's especially with, you know, Apple in the new iPhone has this X11 chip that is like a
dedicated coprocessor for these kind of things. And at the same time, Google with the Pixel 2, they have this
separate chip specifically for like image processing, computer vision. So more and more phones will have
coprocessors that allow us to do edge computing without draining the battery too much.
Yeah, that's more or less like running on GPUs, right? Like these specialized hardware are way more efficient and
quick. So more reasonable to run it on these wimpy devices.
Exactly.
Yeah, yeah. Cool. So you said that you guys were about 50 people. What is the and if I remember the breakdown, right?
20 or so data scientists, 20 or so sort of data software website of things.
What's the team structure? Like how do you guys work together and things like that?
We have a model that is that is like loosely based on the Spotify model. They work with a or we work in a kind of a
matrix structure where horizontally, we have a set of functional teams. So there is a data science team, there is a data
engineering team, then there is a mobile SDK team, and then there is a solutions team. But we quickly realized as those
teams grow bigger and bigger, that it's very difficult to isolate. You don't want to want to be isolated in your team, you want
to work together with people from different backgrounds. So that's why vertically over those
teams, we define cross functional teams that we call squads. So cross functional team has a quite a
specific focus, it's kind of a of a mini startup. And it consists of a few data scientists, few data
engineers, few mobile guys, they build stuff from from concept to actually build, bringing it into
production.
That sounds really like a cool way to work, actually. So there's some new major feature or new
library you guys want to build and you put together these cross functional teams to build it, huh?
Yeah, and usually cross those cross functional teams or those squads are long lift. So it's not like they
are created and then and then disbanded quickly, because of course, we continuously try to improve
our products. So we have like a mob sense, what we call a mob sense squad, the squad that focuses on
everything around signal processing, and you know, the deep learning directly on the sensor data,
then we have like a lifestyle squad that focuses more on the moments in the segments. So there we use more
like NLP related techniques. And of course, we try to move people around. I mean, you don't stay in a
single squad forever.
Of course. That sounds really cool. So let's dig into the three layers of your SDK, the event
acquisition, the moments and segments, you call them, right? So there's some pretty interesting
algorithms and libraries you're using. So the first level is this idea of events. And the basic
question you're trying to answer is what is the user doing? So maybe we could talk about some of the
some of the algorithms and techniques you're using to determine like, are they driving? Are they walking?
Are they at a bar? Whatever.
Yeah, yeah, cool. Well, so transport mode detection itself is a is a cool problem. You know, both both
iOS and Android already have what what they call motion activities. So they give you an idea already about
transport mode, but it's quite limited. I think they support walking, biking, vehicle and idle,
something like that. Also, the occurrences are quite low, usually. So indeed, we had to build our
own model to get better occurrences, and especially to extend the number of transports we support like
bus and subway and running and stuff like that.
Sure. Can you still leverage these like motion chips at a lower level and not just ask like,
what are they doing? But you know, give me the actual measurements that you were going to use to
make that assessment?
Currently, we get 25 hertz accelerometer and gyroscope data from the phone. And based on that data,
well, first, of course, there is some pre processing, some some signal processing, you have
to interpolate the samples because they don't come in on a regular on a regular grid, let's say,
you have to do some bandpass filtering to remove the high frequency components that usually contain
a lot of noise. And then after that, when you have like a signal that is more or less clean,
what we do then is a lot of data augmentation, we add some noise, you know, additive noise,
multiplicative noise. And that is mainly because every phone has different noise characteristics. And we
don't want our machine learning models to learn to recognize specific phones. So to undo those noise
characteristics, we basically deliberately add noise to our data, so that the classifiers learn to
generalize. And what we then do is we feed that sensor data. Well, maybe it's interesting to have a look at
the evolution. So today we use a neural net, a conf net, but we started out in a completely different
way. In the beginning, we actually chopped our sensor stream into pieces of several seconds. Those pieces for
those pieces of or segments of sensor data, we did a lot of manual feature engineering, like some Fourier
coefficients, like frequency domain features, time domain features. Those were fed into a random forest
back then. And the random forest then outputs class probabilities.
Maybe quickly define what a random forest is for people.
Yeah, yeah. So random forest is basically an ensemble of decision trees. So you can,
one of the most simple classifiers is a decision tree where it's just like a binary search tree where
you say, okay, if this feature is higher than a certain value, go to the left node, otherwise go
to the right node, and you go through the whole tree until you have a decision on what is the transport
mode. Problem is that decision tree is not very powerful. It quickly overfits to your data. So what
you can do is just build, you know, a thousand decision trees, all a little bit different, all on
different subsets of your data and your features, and then you end up with a random forest. So it's kind of
averaging out all those predictions.
Right. So it kind of somewhat combats against the overfitting problem you would run into.
Exactly. Exactly.
Okay.
The thing, of course, is by chopping up the sensor stream into pieces of several seconds,
you completely lose the temporal dependencies. It could be that one piece is correctly classified
as car, and the next piece maybe is incorrectly classified as walking. So you still want to do some
temporal smoothing. So what we did back then is we fed that information, those segments,
or actually the class probabilities, into a hidden Markov model. And a hidden Markov model,
is able to learn short-term temporal dependencies and kind of smooth out the end results. So that
was our first version of the transport classifier. And then over the past three years, we went through
several iterations. So the Renov Forest was replaced by boosted trees, XGBoost, which is used a lot,
for example, these days in the Kaggle competitions you read about. And now recently, we figured out that
actually just using a convolutional neural net with one-dimensional convolutions, because of course you don't have
images. It allows us to not only get an improved accuracy, but also come up with much smaller models
that more easily feed in memory compared to this huge random forest.
Okay. Yeah, that sounds really interesting. Thanks for sharing the evolution. I think that's pretty cool.
And so you've got all these events. Okay. Users driving, users at work, users walking, users at restaurant, users walking, users at work, things like that.
And then you try to create what you guys call moments, which is why are they doing this? Like, why are they walking? Oh, they're walking to lunch, things like that, right? So maybe talk about the analysis that you guys do there.
Well, similarly, there was an evolution on that level too. So the main idea is that if you can predict what users will be doing next, you can use that indeed to explain why he's doing what he's doing. So if, for example, the user is predicted to go to work, then the fact that he's in a car means he's in a commute.
While if he's predicted to go to a shop, the fact that he's in a car means he's probably in a shopping routine, right?
So the first step is to teach a model to be able to predict your next event. And there we started out with a Markov Chain-like approach.
Markov Chain basically just tries to learn transition probabilities. It just learns a distribution over, learns to predict the probability of your next event being event A, given your previous events.
So it learns very short-term dependencies. We quickly saw, though, that those short-term dependencies were not able to model complex human behavior.
So it worked in simple cases, like, especially if you include features like time and day, it worked in simple cases like going to work and going back home.
But what if suddenly, you know, you wake up an hour later than normally and your whole day shifts a little bit,
then suddenly the Markov Chain model completely kind of blacks out.
Hey, everyone. This is Michael. Let me tell you about Datadog. They're sponsoring this episode.
Performance and bottlenecks don't exist just in your application code.
Modern applications are systems built upon systems.
And Datadog lets you view the system as a whole.
Let's say you have a Python web app running Flask.
It's built upon MongoDB and hosted and scaled out on a set of Ubuntu servers running Nginx and Microwisgi.
Add Datadog and you can view and monitor and even get alerts across all of these systems.
Datadog has a great getting started tutorial that takes just a few moments.
And if you complete it, they'll send you a sweet Datadog t-shirt for free.
Don't hesitate. Visit talkpython.fm/Datadog and see what you've been missing.
That's talkpython.fm/Datadog.
What we use today there is, again, deep learning.
We use an LSTM.
What's an LSTM? Long, short-term memory?
Yeah, exactly. Exactly.
So an LSTM is a recurrent neural network that is able to...
So when you think about deep learning, convolutional neural nets, for example,
they are deep because you have a lot of layers.
LSTMs, or recurrent neural networks, they are deep not because you have, per se, a lot of layers,
but because they learn deep in the time dimension.
They learn a lot of temporal dependencies.
As opposed to a Markov chain where you only have a dependency on the previous event,
an LSTM can depend on 20, 30, 50 events back in the past, right?
It can say, okay, you know, 50 events ago, the user was in a car, and 20 events ago, he was at a shop.
And given all that behavior, the user is probably going to do this next.
That's cool, yeah. The longer you go without shopping, the more likely you are to shop.
And things like that for groceries, right?
Yeah, indeed, indeed.
And the cool thing is also that the Markov chain model, by nature,
had to be trained specifically for each user, separately, on the user's data.
While the LSTM, we trained differently.
We trained one global LSTM, feeding it thousands and thousands of different timelines of different users.
The LSTM thereby kind of learned about general human behavior,
and it learned what events from the past it has to pay attention to to predict something in the future.
And then, for a specific user that was never seen in a training set before,
we don't have to fine-tune or retrain the LSTM.
We just feed the past three weeks of events into the LSTM,
and the LSTM already learned during the training phase how it should use that pass to predict the next event.
So the nice thing is that you don't...
I mean, if you have a million users on your platform,
you cannot have a million deep learning models, right, that you have to retrain every second.
Yeah, of course.
And how do you mark them, right?
Like, all this stuff is happening without necessarily going,
yes, I'm shopping now.
Yes, I'm doing this.
And then eventually it learns, okay, you're shopping, so I know what that means, right?
This is sort of all inference-based.
It's a combination.
So on the event level, on the lowest level, we do have a lot of labeled data.
So we spend a lot of time with customers or even, I mean,
we paid a lot of students to go out on the road, take trains and trams and bus,
label the data.
And then internally we build some tools to clean up the data and make labels more accurate.
So we do have labeled data on that level.
Of course, when we go more to moments and segments,
it becomes very difficult to get your hand on labeled data indeed.
So there we focus a lot on semi-supervised learning and things like transfer learning.
For example, using triplet loss function,
we can learn this kind of high-dimensional feature space
in which two users with similar behavior are close to each other
and two users with different behavior are far from each other.
And then in that feature space, you can build very simple classifiers using limited labeled data
to actually come up with user segments.
So that's kind of a transfer learning approach that allows us to cope with limited amounts of labeled data.
Sure.
Oh, okay.
That sounds like it's working out really well.
I've definitely been part of projects where it's like,
all right, we're going to hire 100 students to do this for an hour.
Yeah.
And, you know, sometimes that's just what you got to do, right?
Yeah, exactly.
That's how we got started.
Yep.
But you can't pay a million students.
Well, not much anyway.
So, all right.
So, that's moments.
And you have your LSTM deep learning model there.
And then the final, like, the real end goal is to, I guess moments is already probably an end goal.
Like, they're at this store because also you want to classify people into groups, right?
What type of driver are they?
Do they work a lot?
Are they parents?
Are they teachers?
Why are they at the school?
Are they at the school?
Because they're teaching there?
Because they're a student?
Because they're a parent dropping off a kid?
Things like that, right?
So, tell us about the algorithms and stuff and segments.
That's a bit of what I was talking about earlier.
So, this feature space.
I think with segments is you, of course, some segments can be business rules, right?
I mean, you're a workaholic if you work more than a specific number of hours, right?
Right.
But some segments, like, are you a parent, for example?
That is less obvious.
Being a parent definitely influences your behavior.
I became a parent six months ago, and I'm a completely different person.
But how do you capture that behavior?
I mean, you cannot put that in a business rule, right?
Yeah.
So, tell us how you can determine someone is a parent, for example.
That's pretty interesting.
So, what we did there is we used deep learning to analyze, to compare, actually, the behavior of different people and to learn a feature representation,
like a feature vector consisting of 50 floating point numbers, where each dimension, each floating point number, encodes a different characteristic of the person.
Maybe the first number encodes your demographics.
Maybe the second number encodes how many times you go to sport.
The difference with traditional machine learning is that, in this case, we didn't manually define the meaning, semantic meaning of each of those 50 numbers.
Instead, we let our neural network figure out on itself which dimensions it should learn to capture human behavior.
And once you have that, you can actually take this timeline of events and code the whole event timeline into 50 floating points.
And then you have a rather small feature space with only 50 features on which you can easily build, you know, even linear classifiers, very simple classifiers,
using limited amounts of labeled data, people, for example, from which we know they are parents.
And it generalizes extremely well because your feature space is so expressive and because the feature space was learned using unsupervised learning.
So we can use all the data we gathered in the past to learn that representation.
Okay.
So you have these 50 classifiers or points that are sort of grouping people together.
How did you determine, like, this grouping means it's a parent?
Did you find some people you knew were parents and say, oh, they also have this feature that must mean they're a parent?
Or how did you, like, assign values to that?
Yeah, exactly.
So it's kind of the feature space just allows us to do user similarity modeling.
And then, indeed, we do still need labeled data, just not a whole lot of it.
We can find, we can ask 100 users to install our demo app, walk around with the data for a few weeks, with a SDK for a few weeks, tell us whether or not they are a parent.
And then in this feature space, if we look at those people, well, other parents will be very close to them.
And that's how we can then build a classifier to detect parents.
That's pretty awesome.
Do you feel like there are pieces that are missing?
Like, there's dimensions of human behavior that are not captured?
Probably.
Up till now, it works.
It's also all very, very new to us, because we started out also here with mostly business rules on top of our event sequences.
So most of the machine learning in the past was on the bottom layer, on the event layer.
It's only since recent times that we're also doing this unsupervised and semi-supervised learning on the segments and the moments.
But yeah, probably the difficulty, indeed, if you use representation learning, is that it's very difficult to control which dimensions the deep learning thinks are important to capture human behavior.
So I can imagine that not everything is captured there.
But in the end, you can easily solve that by fixing some of the bottom layers of the pre-trained network and then training it a little bit more on a smaller set of labeled data, fine-tuning the upper layers.
And that way, it still is able to learn those things.
Yeah.
Okay.
Very interesting.
The dependency that you're talking about here sounds like it could be really tricky.
Like, suppose you guys redesign your transportation mode detection.
And it turns out, some of the time you thought people were walking, they're just in traffic, but really slow traffic, or something like this, right?
Instead of every day taking a walk down I-5, the interstate highway, they're actually just driving in really bad traffic.
And that probably has knock-on effects for moments, which has knock-on effects for segments.
So how much of, like, if this training of networks takes weeks, potentially, how bad is it if, you know, you change the bottom layer?
That's indeed a very actual problem we encountered.
Especially now that we are more and more using, you know, representation learning to learn these feature spaces on the bottom layer.
Indeed, if you retrain one of the models, the resulting feature space could have a completely different meaning, which means that all the consuming models that follow in the cascade would have to be retrained.
And, of course, you don't want that.
We solve this, I guess, in different ways.
On the one hand, there is a decision you have to make between deploying a trained model as a microservice that is then consumed by other models in the cascade, versus actually just using the pre-trained model and fine-tuning it in a model that consumes that information.
If you do it the first way, if you put it in a microservice, then, indeed, if you retrain the first model, you have to retrain the second.
But if you do it in the other way, if you just combine both machine learning models eventually into one model, then, of course, you don't have this dependency.
So in this sense, we actually try to just use pre-trained models and fine-tune them and embed them into the next model as much as possible, and only go to a microservice if there is good reason for it.
If your model, for some reason, needs, for example, huge amounts of memories or a large amount of SQL queries to a database or something like that, then that is a good reason to actually put it in a microservice.
That's one way we try to solve it.
Another way, that's something we're still working on, we don't have it today, is that we're trying to create a model that basically learns a locally linear mapping from your previous feature space to the new feature space after retraining, or actually the other way around.
So if you retrain a model, but you put a mapping layer after it, then that mapping layer can actually make sure that even if the model is retrained, the new feature space is mapped to the same semantics as the old feature space.
I see.
So the inputs to the next level model basically are literally transformed to look the same as they would have before.
Exactly, exactly.
Okay.
Yeah, that sounds like a pretty interesting set of challenges and some good solutions.
But yeah, definitely it seems like that's something that's always going to be a bit of a tension.
Yeah, exactly.
And we're also, I mean, we're continuously trying to figure it out ourselves.
I mean, there is also, of course, versioning, because if you deploy a new model, there is at least some period in which you're going to have to run both the old model and the new model in parallel,
because not all the consumers will be updated at the same time.
It's getting complicated quickly, but luckily we have an awesome data engineering team there to help us solve all that.
Yeah, that's cool.
So one of the things I was wondering as I was looking through all this, like there's a lot of statistics and statistical inference and understanding these models.
So somebody who works on your team as a data scientist, like what's their general skill set?
Like how much programmer versus how much statistician versus some other skill I'm not thinking of?
It's a bit mixed.
So in general, we say that everyone at Sentience is a software engineer.
So that means that every data scientist has to have good software engineering skills, not just some, you know, some MATLAB scripting experience or something.
You have to be a software engineer.
That's for sure.
And then, of course, most people, we put a lot of emphasis on the machine learning background.
So most people in the data science team, they either have a, you know, PhD in machine learning or computer vision or something, or they have a background in physics or mathematics.
They need an analytical mindset, let's say.
And then finally, there is the signal processing, which is kind of a specific field.
So people coming from robotics or from speech recognition or also image processing often have a good signal processing background.
Yeah, it's quite challenging to find people that combine all three of them.
Yeah, I'm sure.
Definitely sounds fun in terms of projects you get to work on.
You guys don't build apps, right?
You basically provide this SDK or this API to customers who themselves build apps, right?
Well, actually, we just hired a designer, but ourselves, we're not the best in creating very fancy apps or something.
We are really a tech company.
And indeed, we have an API through which we expose all this information back to our customers.
But the customer still needs a tech team.
They need data scientists or developers to be able to do stuff with it.
This portion of Talk Python is brought to you by GoCD.
GoCD is an on-premise, open-source, continuous delivery tool to help you get better visibility into and control of your team's deployments.
With GoCD's comprehensive pipeline modeling, you can model complex workflows for multiple teams with ease.
And GoCD's value stream map lets you track changes from commit to deploy at a glance.
Say goodbye to deployment panic and hello to consistent, predictable deliveries.
We all know that continuous integration is super important to the code quality of your applications.
Choose the open-source local CI server, GoCD.
Learn more at talkpython.fm/gocd.
That's talkpython.fm/gocd.
All this sounds so cool and powerful and useful.
But at the same time, it also feels like it could be a little bit invasive into people's lives and into their privacy.
So what's the story around trying to strike that balance?
That's a question we get a lot.
And indeed, it is a balance we have to maintain.
There is a lot of information you can extract from the sensor data.
I mean, even your personality and your mood at something that's on our roadmap, something we're looking into, not something we per se have today completely.
But your personality influences how you behave and how you behave influences the motion of your phone.
So there is a lot of stuff you can do with it.
And indeed, then privacy becomes an important question for us.
On the one hand, there is a GDPR, so like the recent European privacy legislation.
If you look at the GDPR, Sentience is a data processor, not a data owner.
What actually means that compared to, let's say, Facebook or Google or something, we never claim that the data is ours.
The data is still owned by the customer, which means we cannot combine the data with other data.
We cannot sell the data.
And the data is siloed.
That's one thing.
On the other hand, and probably much more important, is that we explicitly force our customers to ask consent to their users.
So it cannot be that they use our SDK and put something in a small privacy statement, you know, hidden in the app or something.
Our customers really need to be very upfront with their end users, tell them what kind of data they gather, why they do it.
And as long as those customers provide enough value to the end users, that works.
I mean, it won't work for, let's say, advertising solutions.
Nobody wants to give consent to gather all this data to have better advertisements.
But it does work for, let's say, health and lifestyle coaching.
I mean, if we can help you live a healthier life, if we can contextualize your heart problems, or maybe even for insurance, if we can model your driving behavior.
And by that, by doing so, reducing the amount of money you have to pay to an insurance company.
Well, there is enough added value for most users to actually give that consent.
Yeah, that's a good point.
Yeah, I guess it's all about the trade-off for the benefit, right?
Like you said, no one's going to go, I would love to see better banner ads in my, like, Candy Crush app or whatever.
Yeah, indeed.
The tagline of Sentence, or at least what our CEO often says is, we want to make sure that AI improves people's life.
And it might sound a bit cheesy, but imagine indeed a world where you don't have to adapt to all your surroundings.
But instead, you know, your phone knows who you are, knows what you feel, knows what you want.
And the whole world adapts to you, not to spam you or manipulate you, but just to make your life easier and healthier and improve your quality.
That's the promise, right?
Exactly.
So, you talked about being an SDK.
Can you give us some examples of some of the apps that are using you guys as a service?
Yeah, sure.
There are different components, of course, in what we do.
One of the components I quickly mentioned before is driving behavior, where we, in a detailed manner, model, you know, how aggressively you drive, how do you take your turns, what is your driver DNA?
And that is currently being used by, I'm not allowed to name them, but let's say by the biggest ride-hailing company in the world to actually model the safety of their drivers.
So, not the passengers, but the drivers themselves, so that they can coach them and make sure that the riders are safe when they take the gap.
Another example is, for example, one of the biggest brand loyalty companies in the UK.
So, they have a huge user base of users that installed their app because they want to get the latest coupons and that kind of stuff.
And so, there they use our SDK to just personalize their communication with their users and to make sure that, you know, the user is not spammed with information that they don't care about.
But instead, it's a very personalized communication and increases engagement.
Right. So, maybe if you could tell them, like, this person is a parent versus this person is a workaholic, or if they're both, you know, that they might treat them differently, right?
Yeah, exactly. Exactly.
I mean, if you know that someone is sportive, you can propose more interesting stuff than if you know, okay, this person never sports and indeed is a workaholic or something like that.
And I guess maybe the most interesting use cases, to me at least, are in health and insurance.
So, in health, for example, we work with Samsung, who is also one of our main investors, on detection of heart arythemia.
So, problems with, I mean, if you have heart fibrillations and you want to contextualize that, you want to know why it happens, when it happens, and you want to expose that to your doctor.
So, your doctor can say, okay, we see that if you work late, and I see that you're a workaholic in general, and if you eat a lot of fast food that week, that is a time when you usually have your heart problems.
So, that's one of the use cases.
How does it know?
Do you have to, like, do you have a different device that detects the arrhythmia and, like, flags it in time, and then you can overlay it on your timeline or something like that?
Yeah, exactly. Exactly.
Okay.
Yeah, and you said you're also working with another company doing something similar?
Yeah, so there is, in the health space, we work with some smaller companies also from Europe and Belgium and the Netherlands more specifically.
So, there is FibriCheck, for example.
FibriCheck, they have a mobile app where you can put your finger on your camera, and the app will use the camera and the flashlight to extract your heart rhythm from the blood flow to your fingertip.
And so, there also, they use our SDK to contextualize that, to predict when you're probably going to have heart problems, why it's happening, and to expose this to a doctor.
And then there is another example, Medup.
Medup is a company in the Netherlands.
They have an app for care adherence, medical adherence.
So, a lot of people have to take a lot of pills, and a lot of people actually forget to take their pills.
And that's a huge problem.
So, what they did is they developed an app that reminds users to take their pills on time.
But, of course, if you just get such a reminder, you know, an alarm on your phone right before you have to go to work, or maybe even when you're in the car,
then you just snooze the alarm or dismiss it, and you forget about it altogether.
So, they use our SDK, again, to tailor those alarms to make them contextual aware and remind users at the right time.
Right.
Like, if you're driving, it makes no sense to remind you, so wait until you get to work.
Exactly.
Or wait until you return home if it knows you're coming home or something like that.
Yeah, indeed.
Or if we predict you will probably be leaving for work in 10 minutes, then this is the time to remind you, and don't wait 10 minutes.
Yeah, that'd be even better.
Cool.
So, those sound all really interesting.
We talked a lot about your architecture already, actually, but there's a few things that we haven't touched on that I think are worth covering.
One of the things you guys use is something called DevPy.
It's sort of an alternative local PyPI.
Tell people what DevPy is, and how is it helping you guys?
The problem we had with Python and PyPy as a package server is that you quickly end up in kind of a dependency hell.
You develop your project, put it in a repo, you have a setup.py to easily install it, and as a requirement, you list, let's say, NumPy version X, but also you list package Y as a dependency, but package Y actually depends on NumPy version Z.
So, you have this whole conflicting set of dependencies which quickly becomes very difficult to manage.
And how we actually did versioning of our own packages, so our repositories, is in the past we specified a version attribute in the setup.py and used git tags on BitBucket, so on our git repositories.
And those tags also contain a version number, and that kind of allowed us to pull the correct version and try to get everything installed as it should be.
But then you have to make sure that you maintain a setup.py.
Don't forget to increase the version number there.
Make sure the tags are in sync, and it really becomes messy quickly.
So, how we solve this is, indeed, we use DevPy these days.
We have our own package server, our Jenkins server.
So, Jenkins basically is our build server.
Everything gets built into packages automatically there.
Jenkins builds wheels from our internal repositories, builds those wheels both for Mac, for the developers, and for Linux, for actual production.
And it stores that with a version number.
And then if we do pip install something, then first our DevPy is consulted.
It fetches the correct version, the package with the correct version and correct dependencies.
And only if it cannot find it there, it goes further to PyPy.
Yeah, that's really cool to be able to control it like that.
Do you distribute your own packages for use on other projects within your own DevPy?
Everything we build is contained in like a functional repo, let's say, with an API.
And then we always have a microservice wrapper repo that just uses that functional repo as a dependency.
So, the functional part is always built by Jenkins, put into DevPy, and can then be used by different other projects as a dependency.
Yeah, okay.
That sounds like a really good setup you guys have going there.
Another thing that you talked about is pragmatic use of deep learning.
Tell us what do you mean by pragmatic use.
What are some of your recommendations?
Deep learning is cool.
And especially if we hire new people and they hear that we do deep learning, we use it a lot actually.
They are eager to also start using it for the problems they start working on.
But of course, we have to be pragmatic indeed in the sense that a lot of problems just don't need deep learning.
For example, if I talked earlier about detecting what is your home location and what is your work location, you can solve that without deep learning.
You just do some feature engineering, gather a little training data, and train a linear support vector machine on top of it or something.
It's important, I think, to use deep learning if it really solves your problem, if it makes your product better.
But indeed, don't just follow the hype.
Don't just do it because it's a buzzword.
Yeah, exactly.
More VC money because of it.
Indeed.
Yeah, yeah, that's really cool.
Like sometimes just standard algorithms and, you know, if cases effectively, right, are all you really need sometimes.
It is true that these days with VCs and even for customers, for some reason, it sometimes almost sounds embarrassing if you have to tell them that for a part of your product, you use traditional machine learning.
It's like, why don't you use deep learning?
But it's a matter of cost.
It's a matter of accuracy and also maintainability.
I mean, if you have a very simple – actually, I think it goes even further than the simplest example I gave.
If you can solve a problem by a simple business rule, then that's the way you should go.
Right.
Absolutely.
Let's take just a moment and, like, take a step sort of up this higher level, not anything that you guys are doing in general, not referring to your product or your mission, but just in general.
Like there's some people like Elon Musk, who I'm a big admirer of in general and others saying, like, we should be really worried about AI and machine learning.
And other people saying, no, this will make things lots better.
And you've given us some definite examples where it is going to be better for people, right, with, like, health, for example.
But where do you land in this debate?
And do we live in a simulation?
First, the extreme example or the extreme case that you sometimes read about, about, you know, AI taking over the world and stuff like that.
Well, an interesting quote there.
I think it's from Andrew NG, so one of the big deep learning guys who used to be head of AI at Baidu.
And I think today he's still head of AI at Stanford.
He said at some point, you know, that the fact or talking about AI taking over the world is a little bit like talking about overpopulation on Mars.
It might happen at some point.
It probably will.
But there is still no clear path to it, right?
So that's one thing.
Of course, it is true that AI or machine learning, which I like more as a term, actually, is becoming very powerful.
And in that sense, like any powerful tool, it can be used for the good and the bad.
So I do agree that we need politics.
We need legislation to be ready for this.
We need to make sure that governments are limited in what they can do, you know, that they cannot force you to install an app that tracks your every movement so that they can then control your future or something like that.
So I do agree with Elon Musk on that point that it's time for government officials to take this serious and to work on the legal aspect there.
Sure.
I totally agree.
And there's other interesting knock-ons.
I think the EU is working on this.
You know, when we get to things like driverless cars, if the driverless car is in an accident and it turns out the driverless car was at fault, who is responsible and how do you address that?
And if it's pure, totally unsupervised learning that made the car drive, like how do you know why it crashed?
We're going to be able to do that.
So first, a whole transformation in the mobility sector, in the insurance sector has to happen so that cars are actually seen as a service where you insure a service.
It's a different mindset.
Yeah, and I think we're going to have to get used to pushing the benefits in an aggregated way instead of a specific individual's responsibility way.
For example, yeah, the self-driver car did something really bad and it crashed into some people on the sidewalk.
But if you look at it as a whole, half a million fewer people were killed in car accidents this year.
So this is a horrible news story and we're really, you know, it's really bad.
But taken as a whole, self-driving cars are doing better for people.
That's like a theory I'm imagining, right?
But I can see the world struggling with those sort of ethical trade-offs.
Yeah, indeed.
You know, it's a little bit, I know maybe it's not a very good comparison, but if you think about the Industrial Revolution, there was a lot of people that were so scared about all the millions of jobs that would be lost if cars would not be made by hand anymore, but if machines would be used, you know.
But in the end, when we look back, I do think that most people agree that the Industrial Revolution made our life healthier.
We live longer, made it easier, we're happier.
And the same thing is going to happen with the AI revolution.
Yeah, I think that in the long term that that's definitely true.
Like I definitely wouldn't want to live pre-Industrial Revolution myself.
I wouldn't trade my spot in it now.
All right.
Well, Vincent, I think we're going to have to probably leave it there for our topics.
But that was a super interesting look inside what you guys are doing with machine learning and things like that.
So let's get to the two questions.
First one, favorite Python editor.
What do you open up if you're going to write some Python code?
By charm, for sure.
I love the JetBrains product in general.
You know, DataGrip for database stuff, IntelliJ for Java, PyTron for Python, yeah.
Yeah, awesome.
Yeah, me as well.
That's my favorite.
All right.
And notable PyPI package?
I've been thinking about this for a long time.
I think it would be Python Flame Graph just because it's a very cool way to do memory and performance profiling, create Flame Graph, see which methods in your code are the bottlenecks, and optimize them.
Yeah, I looked at that just a little bit.
And it looks like a very powerful way to quickly visualize where your performance problems are.
Yeah, exactly.
Exactly.
And to actually dig deeper into the stack of method calls and figure out what's happening.
Yeah, that's cool.
So I'll put a link to the GitHub repo for Python Flame Graph, which has a bunch of nice pictures.
Awesome.
Yeah, yeah.
So, all right, final call to action.
People are excited about deep learning.
They're excited about what you guys are doing.
What do they do to get started?
We're expanding.
We're continuously expanding.
This year, or coming year, we should grow from 50 to 80 people.
So we're always looking for passionate Python developers, machine learning guys.
Can they just reach out to you, like, on Twitter or something like that if they want to get more information?
Or how do they find out?
Yeah, yeah, definitely.
Just, you know, ping me on Twitter or LinkedIn or go through our website where there is a more official channel.
Maybe you can refer to podcast so we have an idea where you're coming from.
Don't focus too much on the machine learning part either.
If you're very good at Python or very good at machine learning or signal processing, we should talk.
Okay, awesome.
And then you guys have an app.
Even though you said you don't build apps, you have an app.
What's the story with this app?
Yeah, it's a demo app because our product is quite technical.
And so, of course, customers ask, like, okay, how does it look like?
What can I do with it?
So, indeed, we built a small demo app.
It's called Journeys.
You can find it on our website or on the App Store.
Our Play Store.
And Journeys, basically, when you install it, after a while, it will learn about your behavior.
After one week or two weeks, you will see pop up a whole set of segments that we assign to you.
Your moments, your home and work detections.
So, yeah, check it out.
Download it.
It's pretty cool.
And there is also a way to give feedback.
So, if something is wrong and you decide to give feedback, well, that helps us to retrain our models.
Oh, beautiful.
All right.
Well, thanks for sharing your story and what you guys have to.
It was great to chat with you.
Thanks a lot, Michael.
This has been another episode of Talk Python to Me.
Our guest has been Vincent Spurt.
And this episode has been brought to you by Datadog and GoCD.
Datadog gives you visibility into the whole system running your code.
Visit talkpython.fm/datadog and see what you've been missing.
Don't even throw in a free t-shirt for doing the tutorial.
GoCD is the on-premise, open-source, continuous delivery server.
Want to improve your deployment workflow but keep your code and builds in-house?
Check out GoCD at talkpython.fm/gocd and take control over your process.
Are you or a colleague trying to learn Python?
Have you tried books and videos that just left you bored by covering topics point by point?
Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm/course
to experience a more engaging way to learn Python.
And if you're looking for something a little more advanced, try my Write Pythonic Code course
at talkpython.fm/pythonic.
Be sure to subscribe to the show.
Open your favorite podcatcher and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, Google Play feed at /play,
and direct RSS feed at /rss on talkpython.fm.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I'll see you next time.