保留正文与补采附件。源页面当前未重新核验;具体限制见交付清单。

Revisit consent button We value your privacy We use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking "Accept All", you consent to our use of cookies. Customise Reject All Accept All Customise Consent Preferences We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below. The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more NecessaryAlways Active Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Analytics Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Advertisement Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

Uncategorised Other uncategorised cookies are those that are being analysed and have not been classified into a category as yet. No cookies to display. Reject All Save My Preferences Accept All Toggle SearchToggle Mobile Navigation Publish AI, ML & data-science insights to a global community of data professionals. Sign inSubmit an Article LatestEditor's PicksNewsletterShipAI


Write For TDS LinkedInXToggle Search Machine Learning

The Machine Learning “Advent Calendar” Day 23: 1D CNN for Text in Excel

A 1D Convolutional Neural Network for Text Classification, Built Step by Step in Excel Angela and Kezhan Shi December 23, 20259 min read 1D CNN in excel Convolutional Neural Networks were first introduced for images, and for images they are often easy to understand. A filter slides over pixels and detects edges, shapes, or textures. You can read this article I wrote earlier to understand how CNNs work for images with Excel. For text, the idea is the same.

And many important patterns in text are very local. One simple and intuitive use case is to detect negation. Let's take these very simple examples:

In my previous article, we saw how to represent words as numbers using embeddings. We also saw a key limitation: when we used a global average, word order was completely ignored. From the model’s point of view, “not good” and “good not” looked exactly the same. So the next challenge is clear: we want the model to take word order into account. A 1D Convolutional Neural Network is a natural tool for this, because it scans a sentence with small sliding windows and reacts when it recognizes familiar local patterns. Learn this step by step with the interactive Machine Learning roadmap.

1. Understanding a 1D CNN for Text: Architecture and Depth

1.1. Building a 1D CNN for text in Excel

In this article, we build a 1D CNN architecture in Excel with the following components:

1D CNN in Excel - all images by author This pipeline corresponds to a standard CNN text classifier.
The only difference here is that we explicitly write and visualize the forward pass in Excel.

1.2. What “deep learning” means in this architecture

Before going further, let us take a step back.
Yes, I know, I do this often, but having a global view of models really helps to understand them. The definition of deep learning is often blurred.
For many people, deep learning simply means “many layers”. Here, I will take a slightly different point of view. What really characterizes deep learning is not the number of layers, but the depth of the transformation applied to the input data. With this definition:

On the other hand, taking raw input data, applying one-hot encoding, and stacking many fully connected layers does not necessarily make a model deep in a meaningful sense.
In theory, if we don’t have any transformation, one layer is enough. In CNNs, the presence of multiple layers has a very concrete motivation. Consider a sentence like: This movie is not very good With a single convolution layer and a small window, we can detect simple local patterns such as: “very + good” But we cannot yet detect higher-level patterns such as: “not + (very good)” This is why CNNs are often stacked:

In this article, we deliberately focus on one convolution layer.
This makes every step visible and easy to understand in Excel, while keeping the logic identical to deeper CNN architectures.

2. Turning words into embeddings

Let us start with some simple words. We will try to detect negation, so we will use these terms, with other words (that we will not model)

We keep the representation intentionally small so that every step is visible. We will only use a dictionary of three words : good, bad and not. All other words will have 0 as embeddings.

2.1 Why one dimension is not enough

In a previous article on sentiment detection, we used a single dimension.
That worked for “good” versus “bad”. But now we want to handle negation. One dimension can only represent one concept well.
So we need two dimensions :

2.2 The embedding dictionary

Each word becomes a 2D vector:

This is not how real embeddings look. Real embeddings are learned, high-dimensional, and not directly interpretable. But for understanding how Conv1D works, this toy embedding is perfect. In Excel, this is just a lookup table.
In a real neural network, this embedding matrix would be trainable.

3. Conv1D filters as sliding pattern detectors

Now we arrive at the core idea of a 1D CNN. A Conv1D filter is nothing mysterious. It is just a small set of weights plus a bias that slides over the sentence. Because:

each filter has:

That is all. You can think of a filter as repeatedly asking the same question at every position: “Do these two neighboring words match a pattern I care about?”

3.1 Sliding windows: how Conv1D sees a sentence

Consider this sentence: it is not bad at all We choose a window size of 2 words. That means the model looks at every adjacent pair:

Important point:
The filters slide everywhere , even when both words are neutral (all zeros).

3.2 Four intuitive filters

To make the behavior easy to understand, we use four filters.

Filter 1 – “I see GOOD”

This filter looks only at the sentiment of the current word. Plain-text equation for one window: z = senti(current_word) If the word is “good”, z = 1
If the word is “bad”, z = -1
If the word is neutral, z = 0 After ReLU, negative values become 0. But it is optional. Understanding the mechanism sometimes comes with MODEL_NOT_MAGIC.

Filter 2 – “I see BAD”

This one is symmetric. z = -senti(current_word) So:

Filter 3 – “I see NOT GOOD”

This filter looks at two things at the same time:

Equation: z = neg(previous_word) + senti(current_word) - 1 Why the “-1”?
It acts like a threshold so that both conditions must be true. Results:

Filter 4 – “I see NOT BAD”

Same idea, slightly different sign: z = neg(previous_word) + (-senti(current_word)) - 1 Results:

This is a very important intuition: A CNN filter can behave like a local logical rule , learned from data.

3.3 Final result of sliding windows

Here is the final results of these 4 filters.

4. ReLU and max pooling: from local to global

ReLU is a gate, max pooling is a memory.

4.1 ReLU

After computing z for every window, we apply ReLU: ReLU(z) = max(0, z) Meaning:

Each filter becomes a presence detector. By the way, it is an activation function in the Neural network. So a Neural network is not that difficult after all.

4.2 Global Max pooling

Then comes global max pooling. For each filter, we keep only: max activation over all windows Interpretation: “I do not care where the pattern appears, only whether it appears strongly somewhere.” At this point, the whole sentence is summarized by 4 numbers:

4.3 What happens if we remove ReLU?

Without ReLU:

This mixes two ideas:

The filter stops being a clean detector and becomes a signed score. The model could still work mathematically, but interpretation becomes harder.

5. The final layer is logistic regression

Now we combine these signals. We compute a score using a linear combination: score = 2 × F_good - 2 × F_bad - 3 × F_not_good - 3 × F_not_bad - bias Then we convert the score into a probability: probability = 1 / (1 + exp(-score)) That is exactly logistic regression. So yes:

6. Full examples with sliding filters

Example 1

"it is bad, so it is not good at all" The sentence contains:

After max pooling:

Final score becomes strongly negative.
Prediction: negative sentiment.

Example 2

"it is good. yes, not bad." The sentence contains:

After max pooling:

The final linear layer learns that “not bad” should outweigh “bad”. Prediction: positive sentiment. This also shows something important: max pooling keeps all strong signals.
The final layer decides how to combine them.

Exemple 3 with A limitation that explains why CNNs get deeper

Try this sentence: "it is not very bad" With a window of size 2, the model sees:

It never sees (not, bad), so the “not bad” filter never fires. It explains why real models use:

Conclusion

The strength of Excel is visibility. You can see:

Training is simply the process of adjusting these numbers. Once you see that, CNNs stop being mysterious. They become what they really are: structured, trainable pattern detectors that slide over data. ··· All the Excel files are available through this Kofi link. Your support means a lot to me. The price will increase during the month, so early supporters get the best value. All Excel/Google sheet files for ML and DL

Register Now to Continue Reading

Unlock Towards Data Science with a Free Account

All articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more. Register for freeSign in to your account


Written By

Angela and Kezhan Shi

See all from Angela and Kezhan Shi Artificial IntelligenceCnnData ScienceDeep LearningMachine Learning Share This Article

Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program. Write for TDS

Related Articles

ML Metamorphosis: Chaining ML Models for Optimized Results

Machine Learning The universal principle of knowledge distillation, model compression, and rule extraction Vadim Arzamasov October 23, 20247 min read

einsum - an underestimated function

Machine Learning One function - many possibilities. How to use linear algebra for deep learning in a clear and simple way. Chris Lemke August 16, 20213 min read

Implementing Generative Adversarial Networks (GANs) for Increasing a Convolutional Neural Network's...

Machine Learning Introduction Benjamin McCloskey September 29, 202110 min read

What is Machine Learning: A Short Note on Supervised, Unsupervised, Semi-Supervised and...

Artificial Intelligence A short post about what Machine learning is: Supervised, Unsupervised, Semi-Supervised and Reinforcement learning Serafeim Loukas, PhD June 10, 20204 min read

Feature Selection for the Lazy Data Scientist

Machine Learning A comprehensive literature review and code on Filter-based methods for Feature Selection David Harar April 26, 202225 min read

How to Build and Manage a Portfolio of Data Assets

Data Science A step-by-step approach Willem Koenders September 14, 202314 min read

Linear Algebra Essentials with Numpy (part 2)

Artificial Intelligence Learn the Essential Linear Algebra skills for Data Science - Part 2/2 Dario Radečić September 23, 20198 min read

ML & DL Learning path

Deep Learning A guide through the myriad online courses & MOOCs available for ML & DL Raj March 26, 20199 min read

5 real handy python decorators for analyzing/debugging your code

Programming Apply these handy, general-purpose decorators directly to your code Mike Huls March 14, 20224 min read

Your home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals. Subscribe to Our NewsletterWrite For TDS•About•Advertise•Privacy Policy•Terms of Use © Insight Media Group, LLC 2026•The New Stack•roadmap.sh•Creator Network

Recommended Articles

Close