Coding, Casting, and Control: What Cooking Christmas Dinner Teaches Us About Designing NLP Pipelines
Eric Famanas
~7 min read

Earlier today, I was discussing with my partner on the cooking schedule during the run-up to Christmas. It's typically a multi-stage event spanning about three days, as she likes to cook very elaborate festival meals. As we were discussing the schedule, I was reminded of a conversation that Nikos Karagiannakis, PhD had about a year ago, where he was equating coding and application design to cooking. I believe this analogy also holds true to when designing pipelines for data ingestion, specifically when developing an Natural Language Processing (NLP).
Getting the Ingredients Ready
It's not always about preparation!
As part of our annual ritual, we go out and pick our ingredients from the local market; this usually consists of vegetables, eggs, and meats. If you cook to even a basic level, you know that ingredient selection is particularly important for a variety of reasons:
Vegetables - free of bugs, rot or decay
Meat - for us, as little fat as possible. If boiling or grilling, we would also want it on the bone
Eggs - larger ones for mixing and baking, smaller ones can be used for toppings
The list above is just an example, and something that we may expect to see every day, factors that are related to: health, cooking approach, or components for other dishes. Under this context, everything seems quite simple. We should treat our data ingestion pipeline the same way.

The dimensions that my wife uses for selecting ingredients is more exhaustive. In her mind, she is already thinking downstream about things like how she plans to prep and the end result. Those results will dictate whether a carrot is going to be baked or boiled, for example.
So when we look at data, the idea of consuming and processing all data that comes through the pipeline seems a bit absurd. It would be the equivalent of peeling all potatoes in the shop, knowing that there are bad ones in the batch that should be thrown out. Quality data selection, however, is not that simple. The idea of sorting, labelling, and categorising data manually is one method, and has been the foundation of preparing machine learning data for the past few years. However, in order to define this data curating process, we should do what my wife does: think about the intent before attempting to implement.
Coding and Cooking
It's both a process AND an art!
A very simple way that people look at data and function inputs, or hyper-parameters, or really when measuring anything, people have the tendency to be attracted to big numbers. Petabytes of data? Sounds good! Eighty billion parameters! That must be a good model!
However, the result of processing so much information unfiltered and un-gated is that your compute demands such as RAM and processor power become that much more expensive. While the inner code, particularly the functions which support the machine learning process, may have great time-complexity, the ultimate bottleneck is the hardware the application is running on, because compute demands scale with the amount of data you need to process.
Imagine me telling my wife:
"I wasn't sure how many potatoes you wanted boiled, so I grabbed the biggest pot I could find and boiled the whole bag. It took twice as long and now our cooking schedule is off track."
She would probably kill me. :)
To add even more complexity to this problem, we also need to discuss the command sequence in which each function is called. Would you boil potatoes and then peel them? That doesn't make any sense! Just as applying tokenization before data cleaning and normalization equally doesn't make any sense!

As mentioned earlier, designing our NLP ingestion is like making our shopping list: we need to have the end goal in mind of what kind of dish we are going to make. Everything upstream is going to pivot around that idea. Regarding my own research project and designing the NLP pipeline, I set aside the following objectives, or user stories:
I am looking for conversational data related to my overall context
I am interested in data where there are interactions between two or more people
I am looking for discussions around project development and management
From here, we can actually design a data colander or some kind of mesh filter that will only give us the kind of data we want.
Casting Types and Data Shapes
Tidying up BEFORE the mess happens
To recap on a part of my PhD, particularly the Systematic Literature Review (SLR) that I am currently writing for journal submission, I am designing an NLP pipeline that will parse conversational data to extract and quantify communication signals that can be correlated to software project risk factors.

An important thing to highlight at this junction is that my user stories that I am using for screening criteria do not actually mention things related to software projects or even risk itself; these omissions are deliberate in that, when we are looking for clues or indicators that something has gone wrong, we typically infer the situation based on the context. NLP and semantic analysis techniques also work the same way.
Going back to our cooking analogy:
"I went to the store and tried to find potatoes that were exactly 4cm in diameter and 6cm in length with less than 8 eyes that are pre-peeled. I could only find two. I hope these are enough."
Again, my wife would kill me if I ever said that. :) Instead, a more appropriate response would be:
"I brought back a 2kg of baby potatoes. I cut the small ones and peeled them to size."
Does this make more sense? This single sentence tells us exactly what we need to do to our data before processing, and what kind of tooling needs to be present within our pipeline.
I only want 2kg of potatoes - volume of data
I only want potatoes - type of data (or vegetable)
I only want baby potatoes - data labeled as type, or a generic subclass
I will only use potatoes that are roughly 6cm in length - casting into a specific property
I peeled and shaped them to 4cm in diameter - casting and transforming
With respect to our NLP problem, I would design my pipeline like so:
I only want 60,000 chunks of data, 80% for training, 20% for validation - volume
I only want short message data such as emails, chat logs, issue comments - class
I only want data that can be related to internal and external project factors - subclass
I only want data where I can infer team relationships and assign a label, even through abstraction like SVM, and apply to a generic function - casting based on a property
I only care about tokenizing key words that show relationship vectors in my graph - pruning and transforming the data frame
At a high level, I know I need at least these five higher order components as part of my data ingestion pipeline before I begin processing the data. This strategy will reduce the amount of unused or unrelated data. But what happens if you don't do this? You risk drift and hallucinations based on irrelevant data. At that point, the only choice you have is that you will have to manually circle back and perform intensive data labelling and curation before the model can be retrained.
Preparation is Key to a Good Result
And this just doesn't matter with cooking or coding!

At the end of the day, we can learn valuable lessons about designing architecture and process flows by simply examining seemingly routine tasks such as cooking or cleaning; our process designs, as they are driven by humans, will initially follow the precedent that we have sent when we are aiming to achieve a specific goal as efficiently as possible. Just like anything else:
We lay out what we want to do
We plan on how we are going to do it
We scope out the things we need
We evaluate wether the things on hand will work
If we can, we try to make them work
In this exact order. Arguably, you can start from the bottom of the list and work backwards, but the end result may not be the expected outcome. Regardless of your aims and approach, there is just one more I want to say: