If you're doing data science and have mostly spent your time doing exploratory or just local development, this could be the episode for you.
We're joined by Catherine Nelson to discuss techniques and tools to move your data science game from local notebooks to full-on production workflows.
And O'Reilly and Catherine are giving away five copies of her book, Software Engineering for Data Scientists.
If you want to be in the running, just enter your email and the Google Forms link in the links section below.
This is Talk Python To Me, episode 511, recorded May 12th, 2025.
Welcome
to Talk Python To Me, a weekly podcast on Python.
This is your host, Michael Kennedy.
Follow me on Mastodon where I'm @mkennedy and follow the podcast using @talkpython, both accounts over at fosstodon.org and keep up with the show and listen to over nine years of episodes at talkpython.fm. If you want to be part of our live episodes, you can find the live streams over on YouTube. Subscribe to our YouTube channel over at talkpython.fm/youtube and get notified about upcoming shows. This episode is brought to you by Sentry. Don't let those errors go unnoticed, use Sentry like we do here at Talk Python. Sign up at talkpython.fm/sentry.
And it's brought to you by Agntcy. Discover agentic AI with Agntcy. Their layer lets agents find, connect, and work together, any stack, anywhere. Start building the internet of agents at talkpython.fm/Agntcy, spelled A-G-N-T-C-Y. It's once again new course time at Talk Python.
This time, the topic is a little-known one called AI and LLMs.
Seriously, though, it's a great new course by Vincent Warmerdam called LLM Building Blocks for Python.
The idea of this course is that you would like to use LLMs in your Python code.
This could be from OpenAI's APIs or Anthropics or even local LLMs running on your machine.
So how do you get programmable structured data rather than just text from these LLMs?
How do you test whether a prompt is succeeding or another prompt would be better?
When is it better to just use traditional machine learning?
What libraries and toolkits are good for these types of apps?
How do you save money and speed up your apps when you're working with these LLMs?
These are the types of questions this concise course will answer for you.
We're already getting reviews in and people love the course.
It's for sale now for just $19 over at Talk Python.
Just visit talkpython.fm and click on Courses in the nav bar.
The link is also in your podcast player's show notes.
Dr. Catherine Nelson, welcome to Talk Python To Me.
Awesome to have you here.
So excited to talk about notebooks and production and all these things.
It's been fantastic.
Yeah, it's great to be here.
Thank you for inviting me on the show.
I'm a big fan of the podcast.
Oh,
thank you so much.
Yeah.
Yeah, I'm happy to have you on the show.
I really am a fan of helping data scientists move beyond just the playing around with the data science tools.
And by playing around, I mean like exploring data or building stuff just for yourself.
I don't know how many people know.
I'm going to talk about it a little bit, but not very much.
My very first programming job was writing software in C++ of all languages for a scientific research lab and company.
And so I would talk to a lot of scientists and cognitive scientists mostly who would be working in MATLAB.
and they go, here's what I have in MATLAB, make that a C++ program that integrates with this other thing or implement this algorithm in this other tool or whatever.
And it was always an amazing experience, but also like, oh, if it was just written a little bit better, you could iterate on this a lot more.
You could experiment with this a lot more.
You could try this in different situations instead of just this, it wasn't a notebook at the time, but the MATLAB, whatever those things are called, those projects, they're similar in style to that, I think.
I've actually been on a similar journey because before I was a data scientist, I was a geologist.
And my first programming experience was in MATLAB.
And I've taken that journey.
But it was thanks to a really nice conversation I had early in my career.
I was the only data scientist working on a team of developers, designers, and so on.
And I had a conversation with a teammate where I was like, do I really need to learn all this stuff?
I can write code that gets the job done.
But he was like, if you write better code, you can do more data science faster.
And that comment really started me on the journey I've taken towards writing my book, towards feeling that I wanted to help data scientists write better code.
It's interesting to live it, right?
Not just read about, oh, we should be probably using Git or whatever, but be down in it.
It sounds like you've sort of come from this non-rigorous background and working more towards that.
You've probably seen and experienced a lot of things like, oh, now I see why people care about source control or now I see why people care about single responsibility functions or whatever.
It's a different type of rigor.
So there's the scientific rigor where you're going through that process and testing your hypothesis, but you're not necessarily writing scalable codes to do that.
The scientific rigor is there, but then there's the software principles that are a different type of standardization.
Before we dive into moving from exploratory data to production data science and scaling notebooks, give us a quick bit of background on yourself.
I was a data scientist for about 10 years from 2015.
I've always had a strong focus on the machine learning side of things.
Until 2023, I worked for SAP Concur as a principal data scientist and dealing with production NLP models there.
I left there to finish writing my second book, which is Software Engineering for Data Scientists.
And now I'm self-employed doing a whole mix of things from developer relations contracting work through AI consultancy startups, some writing work and also continuing my personal journey from data science towards software engineering. So I don't even know whether I'd call myself a data scientist at the moment.
Yep, doing a whole mix of things.
I don't know what you would call it either, but it sounds super interesting. Like one of the problems with working at large companies is you kind of get pigeonholed, not just into one thing, but one part of one thing. And it sounds like you You get to explore a lot of the very exciting and rapidly changing parts of the industry.
So super cool.
I'm not great at specializing in any particular one thing.
And I used to see that as a downside.
But now I see that as like a huge strength to be able to generalize and pick up new things.
And
like I alluded to in the intro, before I was a data scientist, I was a geologist.
So I did an undergrad and PhD in geology.
I worked in the oil industry for a little bit and then transitioned to data science in 2015 when I was struggling to find good jobs in geology.
Machine learning, data science were just becoming a big thing.
There were a ton of good options for transitioning from one to the other, so many good courses and so on.
So I improved my Python programming.
I learned a bunch about machine learning and I made that jump into tech.
And it was just a great move.
It's worked out.
I really, really enjoy what I do.
Oh, that's fantastic.
And one drawback, less outside work, right?
You don't get to go to Greenland or wherever.
I do miss that.
But living in the Pacific Northwest, I do get outdoors a lot of the time.
So that's
pretty great.
Let's talk PyCon first.
Because, yes, you just had your talk.
Do you know this is up on YouTube yet?
Have you seen this?
I do.
It just came up a couple of days ago.
Yeah, absolutely.
Such
a quick turnaround because when we're recording this late May, PyCon was finished 10 days ago, so it's super fresh.
Yeah, this is a lot better than previously because I think last year, maybe the year before, it was three or four months until the talks came out.
We talked to people, oh, it was a great talk, but we can't really share it with anyone who didn't already go to it.
So I saw your talk and I thought, oh, this sounds super interesting.
I want to talk to Catherine about it.
And I think there's a lot of interesting stories around it.
But before we get into the topic of what you're covering there, let's just talk PyCon.
How was the experience?
Oh,
PyCon is the best.
It is just like one of the friendliest conferences I go to.
I was so happy to get a talk accepted this time around.
I had previously got a talk accepted in 2020.
So I got the notification in January, February 2020.
And I was like, oh, great.
I can't wait to stand up on stage and meet all the people.
And then obviously it was all virtual.
I sat in my home office.
I recorded my talk.
So nice to finally be able to have that experience.
It's just such a supportive environment.
Everyone's very friendly.
The questions that I had at the end of the talk were really good questions, really positive.
And then a bunch of people came up to me after the talk and they're like, oh, yeah, I really enjoyed that.
And just that kind of atmosphere, you really don't get at every conference.
No, it's really different to do it in person.
You really get a lot more gratifying to do it, I think, because you can see the effect you have on people.
When you're doing some sort of Zoom presentation or a podcast, you're speaking to zero or one people in effect, right?
And you don't realize the reach it has, right?
But that's great.
What a weird time 2020 was, huh?
So weird.
I'm so glad that we're back to meeting people in person and getting to go to all the other talks at PyCon.
And I think for me, the advantage of it is I tend to go to a bunch of talks there that I don't know very much about.
So there's such a huge range of things to learn about.
So everything from like what visualizations you can do in a browser with Python to improvements that are being made right at the deep levels of the language, like improving the speed and so on.
Yeah, and just to be there with the people creating Python and creating the libraries and so on, seeing with the maintainers and the companies creating all this stuff, it's a super neat experience.
Yeah.
Let's
talk about your books a bit.
So this talk sort of comes from your newer book.
Absolutely.
Maybe 2020 is great.
Let's go back to 2020.
Tell us about this one first.
Some people buy your book.
First
book is Building Machine Learning Pipelines that I co-authored with Hannah's Hapke.
And we released that in 2020.
And it's all about how to build production machine learning systems with TensorFlow.
So how you go from, you've done the experiments, you have a working machine learning model.
How do you deploy that in a way that's standardized, scalable, reproducible, and automated?
So it's based on TensorFlow Extended, which is a project from Google that helps you to basically one button, press one button, and then your machine learning model would import the data.
You'd check that the data was what you expected to be, train that model, and then deploy it into production.
And at the time we wrote this book, that was really the only technology that lets you do that.
Since then, there's a lot more have come along.
Like AWS has their own solution.
MLflow is a big one.
But 2020, this was a really new thing.
So we wanted to explain the principles of this.
Very neat.
Well, that's the thing with good ideas.
They catch on.
That's book number one.
Now, to be fair, I think TensorFlow is still a super important library, right?
It's still relevant.
100%.
Yeah, yeah, absolutely.
Okay, on to software engineering for data scientists.
Tell us about this.
This is where this idea of this talk came from, right?
The
notebooks talk is an expansion of one of the chapters in this book.
So software engineering for data scientists is based on advice that I was giving my mentees in my previous job.
And it's also the book I wanted to read when I was transitioning into data science myself.
So it tries to answer questions like, what is a test? Why should I use one? How do I make my code more efficient? What even is an API? Like all these things that I, as someone not coming from any kind of software engineering background, was facing as I was transitioning into a job in the tech industry.
And it's something that's often missed in data science intro courses or degrees.
There is so much to learn in data science.
You go from data analysis, statistics, data visualization, you pick up some SQL, you pick up machine learning.
It feels like this fire hose of dozens and dozens of things you need to learn.
And then someone's like, oh, by the way, you need to integrate this into a piece of software as well.
So I felt like this was a real pain point for a lot of people.
And there wasn't anything that really served them from when I started to read around about code quality.
I'd very quickly get into examples in Java.
I'd be looking at web development examples.
There wasn't anything that I could relate to in my job.
So I decided to write it.
This portion of Talk Python To Me is brought to you by Sentry.
Over at Talk Python, Sentry has been incredibly valuable for tracking down errors in our web apps, our mobile apps, and other code that we run.
I've told you the story how more than once I've learned that a user was encountering a bug through Sentry and then fixed the bug and let them know it was fixed before they contacted me.
That's pretty incredible.
Let me walk you through the few simple steps that you need to add error monitoring and distributed tracing to your Python web app.
Let's imagine we have a Flask app with a React front end, and we want to make sure there are no errors during the checkout process for some e-commerce page.
I don't know about you, but anytime money and payments are involved, I always get a little nervous writing code.
We start by simply instrumenting the checkout flow.
To do that, you enable distributed tracing and error monitoring in both your Flask backend and your React front end.
Next, we want to make sure that you have enough context that the front-end and back-end actions can be correlated into a single request.
So we enrich a Sentry span with data context.
In your React checkout.jsx, you'd wrap the submit handler in a Sentry start span call.
Then it's time to see the request live in a dashboard.
We build a real-time Sentry dashboard.
You spin up one using span metrics to track key attributes like cart size, checkout duration, and so on, giving you one pain for both performance and error data.
That's it.
When an error happens, you open the error on Sentry and you get end-to-end request data and error tracebacks to easily spot what's going on.
If your app and customers matter to you, you definitely want to set up Sentry like we have here at Talk Python.
Visit talkpython.fm/sentry and use the code TALKPYTHON, all caps, just one word.
That's talkpython.fm/sentry, code TALKPYTHON.
Thank you to Sentry for supporting the show.
I think this is really, really valuable.
I think as much as we can do to help people come into the data science side and software side and just feel like they belong because it's so easy to just feel like you're banging your head against the wall.
And you're like, what do you mean?
Dependencies are incompatible.
What do you mean?
Like there's a Git merge conflict.
I didn't even want to use Git.
What is this horrible thing, right?
And just battling against it.
So putting something out there to sort of be the roadmap for people to follow.
Great.
Even though the title is data scientists, I think it will be useful to a much broader set of people than that.
Because what I ended up writing, it has some things that are specific to data science, like how you write a test for machine learning.
But I
could also probably title it a friendly introduction to software engineering.
So like anyone who's not a software engineer is their job title, but wants to learn more about those principles would probably benefit from it.
I
think a lot of that stuff's not really taught in universities either.
I know there's computer science degrees, obviously, but a lot of times it's more theoretical and it doesn't really end up with like, this is how you do a pull request type of conversations rather than, here's how you implement a database in Lisp.
That's your homework.
Like, great.
That was my CS experience from my CS class.
Okay, so let's talk notebooks. And I think I want to start where you started with your talk, in that before we talk about the challenges with notebooks, things you need to do to move maybe beyond notebooks in certain circumstances, how about we give some love to notebooks?
And you talk about how great they are and how useful they are in the circumstances they're supposed to be used, right? I
love notebooks for exploring for the very initial stages of a project, particularly a data-driven project where you want to take a look at some data, you want to play around with it, you don't know exactly where you're going to end up with that project at all.
You want the flexibility of being able to play and explore. And notebooks are fantastic for this because you have that instant feedback from the code you're writing to what effect has that had on the data and you can make whatever visualizations you want.
You can look at whatever piece of data you feel like.
So they're fantastic for that initial stage where you don't know where you're going to end up, but you want to look around.
But they do have some challenges and that makes them difficult to reuse, kind of like I opened this show with, right?
Like you've got all the stuff in one file, potentially, effectively, Jupyter Notebooks particular suffer from order of operations variability, right? You can run them top to bottom or you can kind of bump around. I changed that cell and re-ran it. Then I ran two more down.
I went down a ways and wrote a new one, but something in the middle didn't take those changes, right? Things like this.
They're a fantastic tool, but they're not the right tool for everything.
If you want something that you're going to run repeatedly and in automated fashion, That's not what they're designed for.
People, there are sometimes moves to put notebooks in production.
And there's a few projects all about this, like NB Dev is one.
Netflix make a huge thing out of putting notebooks in production.
But I'm going to say I'm not a fan of that.
I'm
not either.
I think it's the right tool for the right job.
And they just weren't designed for that.
There are some attempts to rethink how some of this goes.
Like, for example, I had the folks from Marimo on.
It tries to resist being run out of order, right?
You can either set it up so you can't run stuff out of order because it'll understand cell dependencies and rerun them if needed.
Or at least it'll show you, if you say, like, that's going to be too slow, it'll at least show you stuff is stale and so on.
Yeah.
That's cool.
I think it's going to be interesting.
But the truth is people are using Jupyter almost entirely these days, right?
I just learned about Marimo and Picon.
It sounds really cool.
I had a quick look into that.
I think that's a great option.
And another option is refactoring from a notebook into a regular Python script.
That's the final skill, right?
And that lets you work more closely as a data scientist person, work more closely with software engineering and so on if you're integrating with a larger team.
Rather than like, here's our notebook, you guys figure out how to run it.
Like, oh, this is a new fancy notebook that runs slightly better.
But still, how do I work with this again?
right? But you kind of work more at the Python script level and so on. Okay. So I want to maybe talk a bit about what are some of the software engineering concepts that you feel like data scientists should be paying attention to? Because you use the phrase like the firehose of information sort of thing. And I think when you're coming into this, you're like, well, okay, I realize I need to up my game to be a little more software side rigorous with things, but I can't do everything.
I can't boil the ocean and learn all the advanced programming concepts and all the DevOps and all these things. So what are the few things that people should really start paying attention to first?
I'm going to break this down into tools that you want to be aware of. And let's call it the mindset, the strategies and how you want to think about things. I'll talk about the strategies first because that's going to inform the tools. So a lot of people in a data scientist role, their job is to explore and discover and come up with new ideas, test hypotheses. So like, oh, what happens if we do this? Can we test? In what way will our users react if we change this thing? But when you're moving more towards code that's going to go into production, that's going to be run and used repeatedly.
You've got to think about how to standardize that and how to automate that, how to make it efficient, how to make it run well in a big system.
So that's a real change in mindset that you have to go through.
Software engineers have a ton of tools that will help you write that code that is more robust, more reproducible.
A
huge one is learning how to test your code.
to make sure that your code is doing what you want it to do.
Learning to use version control so that you can share your code so that other people can pick it up and use it.
And also learning to refactor your code and being happy with that process.
And obviously tests are going to play into this as well so that you can be sure that when you change your code, it didn't break something that you were relying on.
I totally agree with that.
Let's talk to those backwards.
So one challenge that I see that I think would be tricky.
So I have this notebook and it's all just top to bottom immediate execution code and I want to test it.
Right. It seems challenging to me.
Like, how do I run that in a unit test?
Is a unit test even the right thing?
Yeah.
If
your notebook is carrying out many tasks in one go, do you want to break out those tasks first rather than test the whole thing in one go?
I think you almost have to because otherwise, how do you test it enough
to
make sure?
I mean, I guess you could say, what's the final answer?
27.
Okay.
Long as we keep getting 27 for the final answer, we could just keep it.
That's not necessarily catching all the details there, right?
As long as there's only one way of getting to 27, then you're sorted.
You're fine.
Or it's a true or false at the end or something like that.
Buy the company, don't buy the company.
Not always the same.
So I guess that stepping back a bit, then that means we need to break our code, break our notebook, code within the notebook, and break it into pieces, sort of assess what is going on there and going, well, what are the actual steps, right?
And in your talk, you're like, here's, you go through actually an example with penguins, right?
And you're like, okay, what is this notebook actually doing in its steps?
Because it's doing not just one thing.
It's doing everything needed to get penguin classification running, right?
Yeah, that's right.
I did a little example of giving a data set to predict the penguin species.
The notebook in that talk goes from downloading the data to cleaning the data, feature engineering for a machine learning model, training that machine learning model, and then making a prediction on new code.
That you can really break down into those steps. And I love just drawing diagrams and flowcharts if I have a big complex notebook to figure out what all the steps are. And this ends up being kind of backwards from what you might do in the engineering world because they probably start from knowing what steps you're going to do and then writing the code accordingly.
But in the data world, you don't necessarily know what the outcome of your project is going to be.
And a lot of projects will not produce a result that you even want to use and deploy into production.
So you don't need to go through the process of making well-engineered code until you know that the project has legs.
It's going to go somewhere.
It's almost like the reverse.
You play around, you play around, and it evolves, and you iterate, and then you're like, okay, this.
Yes.
As you point out in the talk, it's not just a matter of going, okay, we'll take that and we'll put that into functions.
It's like there might be parts that are irrelevant or little exploratory pieces that aren't actually germane to the thing you hear about productizing and so on.
Right.
So it's kind of an assessment you have to go through.
Right.
You
really have to go away and take a step back and then come back and take a fresh look at your code.
And then because you might have this like incredibly complex notebook.
But then you have to be like, oh, what is this actually doing here?
How do I start to break that down?
So I think what I did in the talk was I gave a checklist for how to do that.
That feels like a useful way to start thinking about it, to go from that amorphous mass of code to something that you can then vector into functions and then start building that up.
And I like to go through and then just decide what all the functions are going to be based on that code in the notebook before I actually transfer the code over.
And that helps me think through what steps are going to be happening.
And then I think about the inputs and the outputs of each of those functions to make sure that the data is taking the correct journey, that the types of the inputs and outputs are going to match, that it's all going to work together as one bigger system.
One of the things that would make that easier or a lot harder is how well structured your notebook is, right?
Are you using the little headers to say, here's what I'm doing in the next three cells, and then another markdown header that says, okay, now we're cleaning the data, and here's the various operations and why, or is it just lots of stuff, or even maybe multiple things per cell, right?
There's a lot of ways in which good data science practices will aid you, prepare you for this process, right?
This kind of thing is also hugely useful if you're going to hand your notebook over to someone else at any point or if someone else is going to work on this notebook.
Just having that little bit of documentation to give those hints for what it's doing.
The
original vision, as I remember it being described for notebooks, is sort of literate programming where the code is like storytelling and then there's the code and describing what's happening.
But I think in practice, a lot of people just use it as a scratch pad.
You know what I mean?
You'll definitely see that style of programming if people are writing tutorials in notebooks or they're deliberately setting them out as documentation.
And that works great.
That's another fantastic use for a notebook.
Yeah, it definitely does.
Okay, so what you're recommending is, and what you just show in your talk, is like actually go and create a Python file,.py file, and put just stub functions in there for each thing, each category of things or each step of things that you've identified in the notebook.
And not actually move the code.
Just put pass.
If you want to confuse people, put triple dot, dot, dot, dot, and that actually serves the same function.
Whatever, right?
Just leave them empty so that you get all that structure laid out.
and then when you're happy with it, start moving your code over.
Yes. And this seems like a manual, time-consuming process.
It's like, why can't we automate this?
But I feel like going through that process really helps me change hats from my exploratory hats to my production hats so that I'm really thinking about what this code is going to do.
So I think baking that into your project, that you're going to spend the time to actually think through what your code is going to do when it's run repeatedly in the production setting is key to success here.
What do you think about multiple Python files for different sections of the code or just one? What's your rule of thumb there?
It's going to depend very much on the project for that.
If it's small and simple, one file seems fine.
If there's an obvious hierarchy, If there's like some functions that are associated together, then putting those into their own separate file seems helpful.
If there's like helper functions that are going to get called in multiple places, then breaking those out into their own separate Python file.
That seems like a good strategy.
It definitely
does.
I guess you want to keep in mind, well, what's the goal, right?
Is it just to make it something I can run in another, in the context of, say, an API call?
Or are you trying to create a library that someone else can reuse this code throughout different places?
Right?
That's probably part of the consideration.
Definitely.
What are your goals with this code?
In your example, we talked about some of the tools, right?
You talked about, let's see.
I guess it's worth pointing out this example you talked about.
It's actually available on GitHub.
Slides, code, and so on.
So I'll link to that.
But you talked about two tools in particular to help do this conversion.
Although it sounds to me like maybe you almost want to just manually do it, but maybe one is a step towards another.
But you talked about NB convert and Jupytext.
These are definitely helpful because they're very simple to use.
You can install them and run them with just one line in the command line, and then they will convert your Jupyter Notebook to a script and strip out all the JSON that's in the back of the notebook file.
So if you have a really simple notebook and you do just want to run the whole thing, then you're pretty much done with these tools.
And that also helps you with the manual copying and pasting process that I'm talking about.
So they're a good halfway house between the notebook and a refactored script.
This portion of Talk Python To Me is brought to you by Agntcy.
Agntcy, spelled A-G-N-T-C-Y, is an open-source collective building the internet of agents.
We're all very familiar with AI and LLM these days.
But if you have not yet experienced the massive leap that agentic AI brings, herein for a treat.
Agentic AIs take LLMs from the world's smartest search engine to truly collaborative software.
That's where Agntcy comes in.
Agntcy is a collaboration layer where AI agents can discover, connect, and work across frameworks.
For developers, this means standardized agent discovery tools, seamless protocols for interagent communication, and modular components to compose and scale multi-agent workflows.
Agntcy allows AI agents to discover each other and work together regardless of how they were built, who built them, or where they run.
Agntcy just announced several key updates as well, including interoperability for Anthropics Model Contacts Protocols, MCP, across several of their key components.
A new observability data schema enriched with concepts specific to multi-agent systems, as well as new extensions to the Open Agentic Schema Framework, OASF.
Be ready to build the future of multi-agent software.
Get started with Agntcy and join Crew AI, LangChain, Llama Index, BrowserBase, Cisco, and dozens more.
Build with other engineers who care about high-quality multi-agent software.
Visit talkpython.fm/Agntcy to get started today.
That's talkpython.fm/Agntcy.
The link is near podcast players, show notes, and on the episode page.
Thank you to Agntcy for supporting Talk Python To Me.
I feel like it might be easier to just export everything to a Python file, at the top of it write those stub functions,
and then go
and just move the pieces in, rather than trying to copy out of cells and then mark down sections, and then, you know what I mean, like trying to reformat plus.
Like this will get it into the destination format, I guess.
And talking about copying and pasting, it leads us on to talking about why you might want to write tests at the same time as this.
You want to know that each of these new functions that you're making is doing what you expect it to do.
So it's a pretty nice workflow to just write the unit tests for each of these functions at the same time as you're copying and pasting that code over.
And then you know when you've left a line behind.
I'm
going to go back a little bit on my earlier statement.
I said I think it's really difficult to take this imperative immediate execution code from notebooks and test them.
But I think you could probably do something like put an assert cell into the notebook right after the step you want to take.
So if you're like, these three cells are going to be basically this function, just do a B, put a cell below it, and then write the assert that you would have in your unit test there, and then move them over to the test.
I think you could actually make that work.
Yeah, that's nice.
And that's also really helping you break things down into the steps that you want to put into your functions because you're thinking about, like, here is a point where I want to stop and see what's happened.
I suppose it's worth
pointing out that nbconvert is not just to get Python as an executable script, but you can get markdown, restructured text, reveal.js for presentation, LaTeX, PDFs.
Like, this is just one of its features, but it's a tool that applies here, right?
Similar with Jupytext, but with that one you can also, you can pair your notebook and your export so that when you update the notebook, the linked script also updates, which is really neat.
I
see there's a certain type of comment, I guess, comment percent percent type of thing, which comes out of Jupytext.
Is that understood by VS Code and PyCharm?
I feel like it is.
It almost treats those as cells or something.
You talked about these paired notebooks.
So in addition to just getting the Python script, you can set it up to be paired.
So if you go into JupyterLab and say pair notebook with something, then as the notebook changes, it'll basically probably just overwrite the output Python file, something like that.
They sync with each other.
So the Python script updates when you update the notebook.
That's
a super cool feature.
So if you're, I guess it only really applies if you're willing to kind of live with that output.
right? You don't want to restructure and completely change the Python file, but you're like, I just need this thing to have a Python version.
Yeah, exactly. They're really neat tools that I wasn't aware of until I started researching for this talk. Where
do you see AI in this process?
Because I, you know what I mean? Like you're working, doing a lot of how do I build tools that use LLMs and
so on. A
ton of the data science and software development space is like, How do I use LLMs to write code for me?
So, for example, one of the things you show a lot of is, here's your stub functions, and let's put some nice documentation for it, and then write your code for it.
Could you, say, have some kind of copilot type thing, look at just the code you copied and go, document this for me, right?
Write me Python doc strings for this function or whatever.
I think that's like with many LLM questions.
It's how do you know what to ask for unless you've actually gone through that process yourself and you know why it's valuable.
So if you're coming to this fresh without having previous, more engineering experience, how do you know that you should ask it for documentation?
How do you know that doc strings exist?
This can work if you're in the situation where it's quite obvious what your documentation should be.
There's no caveats.
There's no special cases that you need to actually communicate to someone.
So it's definitely useful, but it's also very easy to generate a lot of these things and then not go back and actually check that it's communicating what you want it to.
It's easy to have it just tell you how it's doing things instead of why.
It doesn't necessarily always get that right.
For me, it's definitely a help, but then I have to kind of force myself to go back and check that it is actually the point that I want to make in this documentation or that it's test if I ask an LLM to write a test for me.
Is it actually testing what I care about in this function or is it just writing some generic test so that I can say, well, there's a test, but it doesn't test anything that's actually a useful input that's actually a potential thing that could go wrong with this code.
And there's always the danger if you have the LLM write the code and the test together.
It'll just make it so the tests pass, not necessarily so the tests are testing the thing you care about, right?
You said the tests have to pass, so now they pass.
You didn't notice they actually changed in a way that no longer validates what you care about, yeah.
Yeah, just update the test until it passes, yes.
I do fear that this kind of stuff is going to create an expertise gap, chasm or whatever, where there's the people who were forced to do it because these tools didn't exist, will have this tribal knowledge of here's how you do this and here's why you do it.
And a lot of people who are in a hurry, especially, I'm not a programmer.
I'll just have this tool help me write the tests because I'm worried about the science or worried actually about the code or whatever.
And then five years down in your career, you're like, well, I've never actually written the tests.
And I think it's going to be a challenge.
It's not just a challenge for programming or data science.
It's a challenge for education.
It's a challenge for so many aspects of society.
But while we're on the topic of data science.
It's a huge challenge.
How do you know what to ask it for if you haven't lived that process yourself?
And how do you know whether the answers are correct if you haven't gone through it yourself?
So for senior people, it's a hugely powerful tool and you can get a lot more done.
But how you gain that expertise, like you say, without going through that, that's a challenge.
It is a challenge.
People often make the analogy, comparison of calculators and math.
There's some similarities, but I think it's a different scale.
if we might see different interfaces to LLMs that help with this.
So just having chat is not necessarily what we want to, the best interface for an LLM to write code.
I have no idea what.
I would love someone to invent something that kind of helps you review and helps you to learn that process, but still have the increase in speed and productivity that you can get within LLM.
Whatever, it's going to be an interesting time.
That's for sure, isn't it?
It's going to be a very interesting time.
Another thing that strikes me as that there's going to be a tension here has to do with what makes notebooks special in the first place, right?
Notebooks are about exploring data and like sort of free form and just let me try this.
Let me try that.
Being experimental and fluid.
And this process, while not completely removing that, does solidify it quite a bit.
Like we're down to these five steps.
It takes these arguments.
And maybe as an experienced software developer, you're ready to just refactor this code and keep working on it.
But I can see earlier stage people this being a challenge.
Like, well, now I can no longer just play with the data and just I can't do like df.head and see what the heck it is.
Like, it's lost to me.
So what do you think about this tension between the notebook freedom and the more rigorous software side of things?
I
would see it as different phases of a data science project.
And not all data science projects will even make it to this stage.
So some, the exploratory process, that might give you your answers.
That might be your project is done while you're still in notebook land.
In some situations, you'll hand over to a development team to go through the process of taking your code into a production environment.
But there's going to be, so depending on the makeup of the team and your exact job role, you might not, you're going to break out of this process at a different point.
Sure.
I think thinking about it in terms of a different phase of the project is useful.
So you go through the exploratory process and you've done all that you need to do of viewing the data, of exploring the data.
What is in your data set?
You're really familiar with it.
And then hopefully you can move to that stage where you don't need to be looking at it in quite the same way.
But you should also be using your tests and your debugger to check that your data is what it needs to be when you move to this next step.
But you probably need to do that less because you've done that exploratory work to figure out what there is and what you need to use in the final project.
I phrase it as a negative, like you're giving up the stuff.
Maybe we should rethink about it as like a positive.
I was listening to you talk and I'm like, well, when you get to this stage, it's kind of like your project has succeeded.
In the sense like you've done all you need to do.
Now it's ready to put it to use.
Let's put this in the hands of some users.
Let's put it on prime time.
Let's share it with different teams.
Yeah, exactly.
So
see it as a celebration, not like I'm losing my freedom or whatever to just keep exploring.
That's pretty cool.
Similar to maybe legacy code.
I know people lament like, oh, I've got this thing and it's so, so badly written and it's so convoluted.
And it's, but we still, it's so important.
We have to still use it like, well, that's also kind of like a success story, even if it's a bit of a hassle in some of the ways.
If your code has that much longevity, it's clearly doing something right.
Exactly.
Celebrate that.
Celebrate it.
Okay.
Let's talk DevOps, ML Ops a little bit.
Like, what are your thoughts on later?
Right.
So I've written this code, maybe I've trained some models or put in some algorithms in place.
How do you keep it working, keep it running, monitor it?
What are your thoughts around this?
I'm a big proponent of standardization.
So if your company has many machine learning models, then picking some kind of standardized framework, putting them into production is huge.
It's so easy to just have ad hoc code for each model and then it becomes extremely hard to maintain.
You can't keep track of what many models are doing.
So picking one of the popular frameworks and putting it into production is key here.
And those will come with things like validating your data to make sure that your new training data has the same statistics as the old one.
you can set up automated analysis so that you know that if your production model has ditched below some certain threshold, you can trigger a retraining loop.
Being able to automate it and sort of step back from the manual process of training and deploying the model is huge here, I think.
Yeah. Observability.
Yes.
And those sorts of things.
So when you say picking one of the frameworks, what frameworks are we talking?
TensorFlow Extended, MLflow, AWS, SageMaker.
There may well be others these days as well.
Yeah,
something that comes with this all built in.
So the ML ops side of things basically becomes operating TensorFlow Extended or operating SageMaker.
And then if something goes wrong, then you can maybe go back to the data scientists.
It
looks like it's not relevant to the data that we're working with, right?
Or something along those lines, right?
It's drifted or...
If it's sort of a simple, oh, our data has changed slightly, then you can hopefully just trigger a retraining loop.
But then other times you might be like, oh, our customers have suddenly decided to behave totally differently because of some external event.
We need to go back to the drawing board with this.
Or we've decided to add in a new feature that this feature isn't quite what we wanted.
Let's change this up a bit.
One of the biggest tools in the MLOps toolkit is just being, just remaining cynical about your machine learning model is doing and expecting it to fail in unexpected ways and give examples, give answers that you have no idea that have failed in ways that you never even thought of.
It's going to keep happening.
What about understanding code running in Linux or in containers or stuff like that?
I can easily see a lot of folks coming from non-software backgrounds going, I already didn't know what the terminal was.
How am I supposed to work with containers inside of Linux machines or something like that?
Assume that these things are learnable.
There's going to be, you might have to play around with these things and read three different types of documentation before it starts to make sense.
But there are a lot of resources out there to get you from not knowing how these things work, them seeming like magic, to being able to use them in the way that you want to.
Good
advice.
I think I would say to folks something to the effect of if you see other people who look like they understand this really well and you're like, well, those people just know it.
And I'm always confused or whatever.
Almost all those people got there by taking little steps, failing, reading the documentation, adding one more little skill.
Okay, now I can figure out what the size of files over an SSH.
Okay, next.
And you just slowly, you just work your way through like little periods of frustration until you get there.
You look down the road at people who have made the whole transition or they really understand that all well.
And it's like, well, how do they?
There's no way I can do that.
I just, that's beyond.
It's not.
It's just you've got to be willing to take the little steps and embrace the frustration because on the other side is a new skill.
I think if you are one of these people with that expertise, then remembering that you didn't used to have that knowledge and being open to answering the questions of people who are just getting into that, it would be great if more people would be able to remember that.
Yeah, I absolutely agree. Don't say it's a dumb question. I'm not answering it.
There are no dumb questions.
Remember that you had that same dumb question 10 years ago or something like that. Absolutely. You talked about these different frameworks and potentially others. How do you pick?
sometimes there's not even a choice because your company is already using aws for storing the data
that's fair because you you said like if you're going to standardize on one if they've already standardized like well you pick that one that's
probably the simplest way of choosing but i think you've got to involves putting some thought into the project at the at the start and being like okay what's going to be the scope of our machine learning in this company are we expecting to have like 50 different models doing different things. But a lot of the time, you don't know this is going to be successful until you start doing it. So you get to a situation where you already have a few models, they're starting to become successful, then you suddenly need to transfer them all onto some framework. I think sort of checking that they do all the things that are important in your use case. So if you expect to be needing to retrain your model very frequently, then something that makes that easy. If it's really important that your model gives some specific answers in some specific case, then good observability is very important.
I'm a huge fan of awesome lists. I'm kind of a sucker for listicles in general, but awesome lists are cool. I just found an awesome ML Ops list.
And I'll put that in the show notes.
People can go around and it looks really cool.
I mean, I just found it, so I don't know, but I'll put that in there as a resource.
People can use that to start the research journey, I guess.
What do you think?
Yeah, definitely.
I'd also recommend the ML Ops community, which is a big Slack workspace of people talking about all things ML Ops.
That's a good place to get into.
Did you want to give away a copy of your book?
We're trying tentatively, maybe?
Yes, I will have some copy, some ebook copies of software engineering for data scientists to give away to listeners of this show.
I guess we'll put out the details with the podcast version.
Yeah, we'll figure it out. And I'll put it in the show notes, which will eventually find their way to the YouTube live stream once I get that turned around.
But yeah, if you want to get a free copy of the book, I imagine there's limited copies, so you'll have to act soon when you hear this episode come out. But I'll put in some kind of instructions into the show notes and you can check that out.
put the names into a hat and pick out however many copies I'm able to give out.
Exactly.
So here's what I propose. I think what we're going to do is we're going to create a notebook, figure out how to pick all the names. We're going to then productize it, put it into TensorFlow Extended, train an LLM, and then we're going to let it pick the winners. How's that sound?
Reasonable?
That sounds perfect.
Totally. Totally easy. I love it. All right. Well, let's close things out with maybe a little advice for people who are coming into the space, they've been using notebooks for exploratory type of work generally. What do you tell them to maybe take their notebooks to the next level or take their code out of notebooks into the Python to do the next thing?
I think my message here is please share your code with other people, share what your code can do with the world and make your code so that it is easy for other people to use, so that it is robust, so that it's reproducible and just encouraging people to put that time in to refactor and improve their codes because it is very worthwhile and it's not as hard as you think it's going to be.
I
think that's great advice. And I would just throw out also that if you're not familiar with it, if you've been working in notebooks a lot of times, the more software-oriented editors are often very good at algorithmically refactoring your code. You highlight a bet and go make that a function and it'll do it without making mistakes it might not be the result you ended up actually wanted but it will do it without mistakes and so you can leverage some of these tools to sort of keep it to be make it less error
that's a great strategy and can prompt some ideas for how you might want to move from one to the other and you can accept those or you can be like oh no actually i wanted it to do this so yeah great starting point exactly
control z no i don't want that anymore I changed my mind.
That looks bad.
At least you don't waste time on it.
All right.
Well, Catherine, thank you so much for being here, sharing your ideas.
I will link to your talk if people want to see PyCon version as well.
So thanks for the excellent ideas and thanks for being here.
Thanks.
This has been a lot of fun.
Great conversation.
Yeah.
Bye-bye.
Bye.
This has been another episode of Talk Python To Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
Take some stress out of your life.
Get notified immediately about errors and performance issues in your web or mobile applications with Sentry.
Just visit talkpython.fm/sentry and get started for free.
And be sure to use the promo code talkpython, all one word.
And it's brought to you by Agntcy.
Discover agentic AI with Agntcy.
Their layer lets agents find, connect, and work together, any stack, anywhere.
Start building the Internet of Agents at talkpython.fm/Agntcy, spelled A-G-N-T-C-Y.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our content ranges from true beginners to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
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 think
is the norm.