Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-FranΓ§ois Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Artificial Intelligence   Latest   Machine Learning

KAN (Kolmogorov-Arnold Networks): A Starter Guide 🐣

Author(s): JAIGANESAN

Originally published on Towards AI.

KAN (Kolmogorov-Arnold Networks): A Starter Guide 🐣

Image by Alban Gogh from Pixabay

I want to start with a question that has been on my mind lately. Is the AI community genuinely expecting a groundbreaking innovation? I’m asking this because of two recent scenarios that caught my attention.

Firstly, when MAMBA was released in late 2023, many people were excited. The question on everyone’s mind was, β€œIs MAMBA the next big thing?” Would it revolutionize traditional transformer architecture?

Fast forward to the end of April 2024, when KAN was released. Once again, the same question echoed through the AI community, β€œIs KAN going to replace neural networks and MLP?” (Please Comment your thoughts on this)

It seems to me that we’re all eagerly anticipating the next big innovation in the AI world.

Let’s get into the Article1

It’s simply not possible to cover the entire spectrum of KAN in one article, from basics to advanced. However, my goal in this article is to give some basic understanding of KAN. We will explore the parts or building blocks of KAN in this Article.

Image 1: MLP vs KAN. Source: KAN Research Paper[1]

Take a look at Image 1, which highlights the key differences between the Multi-Layer Perceptron (MLP) and Kolmogorov-Arnold Networks (KAN). One of the Important differences between these two is that MLP is built on the principles of the Universal Approximation Theorem, while KAN is backed by the Kolmogorov-Arnold Representation Theorem.

Before we dive into the world of Kolmogorov-Arnold Networks (KAN), it’s essential to have a solid understanding of Neural Networks. Let’s start with the basics of MLPs and then explore the parts and working mechanisms of KANs.

Universal Approximation Theorem (UAT) 🐾

The Universal Approximation Theorem (UAT) states that a neural network with a single hidden layer (With N neurons) can learn to represent any continuous function to an arbitrary degree of accuracy. This means that neural networks can approximate any real-world continuous function, no matter how complex, by adjusting the weights and biases within the network.

Let’s consider an example to illustrate this point. Imagine we’ve trained a Convolutional Neural Network (CNN) to identify whether an image contains a car or not. While CNN can make predictions with a certain level of accuracy, it’s not perfect and may miss some images that do contain cars. What’s happening here is that the neural network is actually learning to approximate what a car looks like, rather than recognizing every possible instance of a car.

Multi-Layer Perceptron (ANN)

Image 2: MLP. Image by author.

Convolution helps us to get the features of the car, Car structure, shape and etc. But the Linear layer is the one that learns that feature and classifies the Images.

Consider this (Image 2) has an Artificial Neural Network / Multi-Layer Perceptron / linear layer with an input layer (4 input units), one hidden layer (5 Neurons), and an output layer (One Neuron β†’ Binary classification) to predict whether the image has a car or not. The x1, x2, x3, and x4 are features that come from the convolution layer. This inputs are fed into the hidden layer. Where the input features are getting into mathematical operations with weights and biases, then activation is applied for Non-Linearity, Then the Hidden Layer output is fed into the output layer, Which gives logits, then activation is applied, which gives the probability score, indicating the likelihood that the image contains a car.

To illustrate this, Let’s take a closer look at below 4 images.

Image 2 A: Linear Layer operation. Image by author

Note: Numbers in the images are for illustration purposes only. The same operation you are familiar with Neural Network as you see in Image 2 A, will be illustrated in the Below images. I am trying to change your perspective a little bit.

Image 3: MLP-Hidden Layer 1. Image by author

Let’s think we have 5 images, and we want to predict whether the image has a car or not. In this example, I will illustrate how prediction is made with the pre-trained model. The input Features have 5 image features that come from the convolution layer. This input feature (5,4) is multiplied with a transposed hidden layer weight matrix (5,4), resulting in an output (5,5) matrix, as shown in image 3. The Hidden layer gives 5 features to each image Because the Hidden Layer has 5 neurons.

Image 4: MLP-Hidden Layer 2. Image by author

With the Output(5,5) the bias vector (1,5) is added to each row and gives Output O1 (5,5), To introduce Non-Linearity the ReLU activation function has been applied that changes the Negative numbers to 0 as shown in Image 4.

Image 5: MLP-Output Layer 1. Image by author

Then, the hidden layer output O1 is Multiplied with the Transpose output layer weight Matrix W1(1,5), resulting in output (5,1) as shown in image 5.

Image 6: MLP- Output Layer 2. Image by author

Next, we take the output (5,1) and add the output layer bias vector B2 (1,1) to it. This is done through a process called broadcasting, which results in the Output Layer weight Matrix O2 (5,1). Then, we apply the Sigmoid activation function to O2, which converts the logits into a probability score. This gives us the final output, where any value less than 0.5 is classified as 0, and any value greater than or equal to 0.5 is classified as 1. Looking at the results, we can see that the first three images have cars in them.

I hope You understand UAT and Neural Networks. Let’s dive into the world of KAN. To See KAN as a Full picture, we need to understand its parts. We start with the Foundational theorem.

Kolmogorov-Arnold Representation Theorem

Kolmogorov-Arnold Representation Theorem backs Kolmogorov-Arnold Networks. Kolmogorov-Arnold representation theorem states that if f is a multivariate ( Multiple Feature vectors) continuous function on a bounded domain, then f can be written as a finite composition of a continuous function of a single variable and the binary operation of addition. More specifically, for a smooth f : [0,1]^n β†’ R, Where Ο†_p,q : [0,1] β†’ R and Ο†_q: R β†’ R. In a sense, they showed that the only true multivariate function is addition (βˆ‘) since every other function can be written using univariate functions (x_p) and sum.

Image 7: KAN Theorem. Image by author

B spline is an important concept in KAN, to understand B splines, we need to understand Bezier curves.

Bezier Curve

Both Bezier Curves and B-splines are Parametric curves. If you have studied Computer graphics, animation, or physics, you may have come across this term. I believe you are familiar with linear regression algorithms. In linear regression algorithms, the line or hyperplane is created by coefficients (Parameters). The same operations happen here. A Bezier curve has a set of control points(Learnable) that makes the curve. The Curve is the Linear Combination of these control points weighted by Bernstein polynomials. We will see everything below πŸ˜ƒ.

If we have two points, we use a straight line to connect, if we have three points, we need to use a quadratic equation, if we have four points, Cubic equations, so We need a Polynomial equation to connect. If we have N points and we want to connect or draw a line that passes through these points, We need an equation with a polynomial of degree N-1.

If we have lots of points and we want the line (Polynomial line) to pass through all these points (data fitting), the lines will have many peaks and valleys, making the resulting curve oscillatory as shown in image 8.

Image 8: Data fittings of multiple points. Polynomial curve. Image by author

One major issue with this method is that it can be very computationally expensive. When we’re dealing with polynomial equations, we know exactly how many operations will be required. However, if we’re working with a large number of points β€” hundreds or even thousands β€” the equation becomes extremely complex, making it very costly in terms of computational resources.

To overcome this challenge, we need to find a way to simplify these lines and make them less computationally intensive. This is where the Bezier curve comes in. The Bezier curve is a powerful tool that helps create a smooth line between points. As I mentioned earlier, the Bezier curve is a parametric curve. All the coordinates of the curve are dependent on an independent variable β€˜t’, which ranges from 0 to 1.

When it comes to the Linear Bezier Curve, things are relatively straightforward. Given two distinct points, p0 and p1, a linear Bezier curve is essentially the straight line that connects these two points.

The Mathematical representation of this Linear Bezier curve…

Image 9: Linear Bezier Curve. Source: Wikipedia [2]
Image 10: Linear Bezier Curve between 2 points. Image by author

The quantity(B(t)) p1-p0 represents the displacement vector from the start to the Endpoint.

Quadratic Bezier Curves’ Mathematical Representation…

Image 11A. Source: Wikipedia.org [2]

The explicit form of the quadratic curve is:

Image 11B: Quadratic Bezier Curve (3 points). Source: Wikipedia.org [2]

Same for cubic Bezier Curves’ Mathematical Representation…

Image 12 A. Source: Wikipedia.org [2]

The explicit form of the cubic curve is:

Image 12 B: Cubic Bezier Curve (4 points). Source: Wikipedia.org [2]

If you don’t understand, bear with me. In the end, everything will make sense. I’m trying to explain the concept of KAN’s learnable function, which is a bit different from what we have seen with traditional Multi-Layer Perceptrons (MLPs).

In MLPs, we use learnable parameters and non-linear activation functions. But KAN takes a different approach. Instead, it uses a learnable non-linear function. You can see this difference in Image 1. Ok, Now Let’s get back to the Bezier curve 😁

Image 13: Cubic Bezier curve with 4 points (4 control points). Source: Wikipedia.org [2]

Take time to check the Animated high order Bazier curve on Wikipedia.org. πŸ“Œ [Highly Recommended] It will help you understand more about Bezier curve interpolation.

Image 13 shows the smooth curve between p0 and p3 (4 points). It only parses from the first point and the last point and interpolates between intermediate points. It uses the recursive calculation to interpolate the points, as shown in Images 12 A and 12 B. As time step (t) changes or moves, the curve changes.

The Recursive calculation is computationally expensive, and we can calculate the Bezier curve without recursive calculation using the below function

Image 14 A. Source: Wikipedia.org [2]

(n i) is Binomial Co-efficient. It gives the coefficients of the Binomial when it is raised to the n_th power.

Image 14 B: Binomial Co-efficients. Source: Wikipedia.org [3]

If we have n points, we can find the n-1 degree curve using this formula.

Image 14 C. Bezier curve with Bernstein Basis polynomial. Source: Wikipedia.org
Image 14 D. Bernstein Basis Polynomial. Source: Wikipedia.org

We can interpret the Bezier curve with the Bernstein Basis polynomial with the Basis function.

Image 15: Basis function of the Cubic Bezier Curve. Source: Wikipedia.org [2]

Image 15: The basis functions on the range t in [0,1] for cubic Bezier curves: blue: y = (1 βˆ’ t)Β³, green: y = 3(1 βˆ’ t)Β²t, red: y = 3(1 βˆ’ t)tΒ², and cyan: y = tΒ³.

Image 14 C Formula for 4 points will result in polynomials like in Image 15. When the time step (x-axis) is 0, the only point 0 is contributing to the final curve (B(t)). When the time step moves, the contribution changes based on the points. Blue line y = (1 βˆ’ t)Β³ β†’ Polynomial associated with the first point (Image 13). When t is 0 (x-axis), y will be 1. When x reaches 1, the contribution of the first point will become 0. Actually, these points control the curve; that’s why it's got their names as control points. When time moves from the 1st point, we get closer to the second point where the blue and green lines meet. Same as for all the points. Then, at the end, it reaches the last point at time step 1 [0,1]. This is how the 4 points contribute to the final curve.

However, there is a problem with these Bezier curves. If we have n points, we need a Bezier curve with n-1 degrees, which is also computationally complex. And there is no local control in degree n Bezier curves β€” meaning that any change to a control point requires recalculation and thus affects the aspect of the entire curve. If the curve changes in one place, it will affect it in all the places. To solve this and Make it more efficient, researchers introduced B-Spliens. (Finally, B spline 😴😴)

B spline (Basis spline)

Instead of a Bezier curve with 50 points, We make 10 Bezier curves with each 5 points and stitch them together. How is it 😜? This is how B splines are created.

In a B-spline curve, only a specific segment of the curve shape changes or is affected by the changing of the corresponding location of the control points. If we have n points, and if we set the degree of the B-spline curve as k, we will have n-k bezier curve.

For example, if we have 50 points, the degree of the B-spline curve is 4 (5 Control points for each Bezier curve) we will have a 46 Bezier curve. Points where they meet are called knots.

Points 1,2,3,4,5 β€” Bezier Curve 1

Points 2,3,4,5,6 β€” Bezier Curve 2

Points 3,4,5,6,7 β€” Bezier curve 3

…

points 46,47,48,48,50 β€” Bezier curve 46.

In this scenario, each Bezier curve is controlled by local control points; changes made in one control point do not affect the whole curve. The formula for the Basis function is defined in terms of basis function and control points. The B spline curve is a piece-wise defined polynomial function that is smooth and flexible.

Image 16: General B-spline formula.Image by author

Image 16: C(t) is the B-spline curve. N_i,p (t) are the B-spline basis function of degree p. p_i are the control points. t is the time step parameter [0,1].

B-spline Basis functions: For p=0 (Zero degree), the N_i,p (t) is

if t_i ≀ t < t_i+1 will be 1, otherwise 0.

For p>0 (p degree)

Image 17: Basis function for degree>0. Image by author
Image 18: B spline. 7 points, degree 3. Image by author

Let’s take the example of 7 points with a degree of 3. So 7–3 = 4. We will have a 4-basis bezier curves. The Red dot is the example knot between the bezier curves.

Learnable Functions

Before we delve into the world of KAN (Kolmogorov Arnold Networks), let’s take a step back and explore another crucial topic. In this section, we’ll discover how B-splines are used as a learnable function. Take a moment to glance at Image 1 and examine the shallow formula of KAN, where you’ll notice Ξ¦(x). This is precisely what is represented in Equation 1 of Image 19.

Image 19: Ξ¦(x) expression. Image by author

The Equation 1 in Image 19 has two parts. b(x) and spline (x). Only the spline(x) is learnable. The activation function Ξ¦(x) is actually the sum of the basis function b(x) and the spline function spline(x). If we take a closer look at Equation 3 in Image 19, we can see that C_i represents the control point (Learnable), while B_i denotes the basis function of the B-spline.

In KAN there are in total O(N² L(G + k)) ∼ O(N² LG) parameters. Where L means the number of layers in the KAN. N means the number of functions in One Layer (Width). Where k is order and G is knots in the B-spline.

Kolmogorov Arnold Networks (KAN)

We know the Kolmogorov Arnold Representation theorem backs the Kolmogorov Arnold Networks.

Image 20: KAN function.

We Have seen the what Ξ¦(x). In Image 20 the n means the number of features in the vector x. p is the input feature, and q is the 2nd layer input feature that comes from the 1st layer functions.

Image 21: KAN. Image by author

Image 21: Left β†’ Notations of activations that flow through the KAN. Right β†’ an activation function is parameterized as a B-spline, which allows switching between coarse-grained and fine-grained grids.

If we have 2 (p) features in vector x, the n will be 2 so 2n+1 will be 5, So in the First Layer (L) we will have 10 Non-Linear functions as shown in image 21 [Ο•_0,1,1…]. That will give 5 features as output( 2n+1). These 5 features are given to 5 (q) Non-Linear functions [Ο•_1,1,1…] that will result in single output x_2,1.

I want you to recall the Kolmogorov-Arnold Representation theorem β€œ Kolmogorov-Arnold representation theorem states that if f is a multivariate ( Multiple Feature vectors) continuous function on a bounded domain, then f can be written as a finite composition of a continuous function of a single variable and the binary operation of addition.” According to this theorem, each variable passes through the Non-Linear functions and is Added. For example, the x_1,1 is the addition of the output from Non-Linear functions Ο•_0,1,1 and Ο•_0,2,1. The Non-Linear function Ο•_0,1,1 processes the 1st feature in vector x (x_0,1). Respectively Ο•_0,2,1 processes the second feature in vector x (x_0,2). We have also seen how the non-linear function works.

Image 22: KAN Interpretation. Source:KAN Paper[1]

In MLP, the interpretation is very difficult Because there will be millions or billions of parameters. However, in KAN, we can interpret the learned function as shown in image 22.

Image 23: KAN with 4 features. Image by author.

The Learnable function could be anything square of input, sin function, or exponential function. Control points learn and adjust the curve for the function.

And that’s a wrap! I hope I’ve explained the basic concepts of KAN and made it more understandable for you. I’ve put in a lot of effort to break down the basics in a simple and clear way, so I’d love it if you could show your appreciation πŸ‘. If you’re interested in learning more about KAN and its building blocks, I highly recommend checking out the references I’ve provided.

Thanks for reading this article 🀩. If you found my article useful πŸ‘, give ClapssssπŸ‘! Feel free to follow πŸ˜‰ for more insights.

Let’s stay connected and explore the exciting world of AI together!

Join me on LinkedIn: linkedin.com/in/jaiganesan-n/ 🌍❀️

References:

[1] Ziming Liu, Yixuan Wang, Sachin Vaidya, Fabian Ruehle, James Halverson, KAN: Kolmogorov-Arnold Networks (2024) Research Paper.

[2] Bezier Curve Explanation. Wikipedia.org [Highly Recommended]

[3] Binomial Coefficients Wikipedia.org

[4] B-spline Wikipedia.org

[5] B-Spline GeeksforGeeks.org [Recommended]

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓

Sign Up for the Course
`; } else { console.error('Element with id="subscribe" not found within the page with class "home".'); } } }); // Remove duplicate text from articles /* Backup: 09/11/24 function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag elements.forEach(el => { const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 2) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); */ // Remove duplicate text from articles function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag // List of classes to be excluded const excludedClasses = ['medium-author', 'post-widget-title']; elements.forEach(el => { // Skip elements with any of the excluded classes if (excludedClasses.some(cls => el.classList.contains(cls))) { return; // Skip this element if it has any of the excluded classes } const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 10) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); //Remove unnecessary text in blog excerpts document.querySelectorAll('.blog p').forEach(function(paragraph) { // Replace the unwanted text pattern for each paragraph paragraph.innerHTML = paragraph.innerHTML .replace(/Author\(s\): [\w\s]+ Originally published on Towards AI\.?/g, '') // Removes 'Author(s): XYZ Originally published on Towards AI' .replace(/This member-only story is on us\. Upgrade to access all of Medium\./g, ''); // Removes 'This member-only story...' }); //Load ionic icons and cache them if ('localStorage' in window && window['localStorage'] !== null) { const cssLink = 'https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css'; const storedCss = localStorage.getItem('ionicons'); if (storedCss) { loadCSS(storedCss); } else { fetch(cssLink).then(response => response.text()).then(css => { localStorage.setItem('ionicons', css); loadCSS(css); }); } } function loadCSS(css) { const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); } //Remove elements from imported content automatically function removeStrongFromHeadings() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, h6, span'); elements.forEach(el => { const strongTags = el.querySelectorAll('strong'); strongTags.forEach(strongTag => { while (strongTag.firstChild) { strongTag.parentNode.insertBefore(strongTag.firstChild, strongTag); } strongTag.remove(); }); }); } removeStrongFromHeadings(); "use strict"; window.onload = () => { /* //This is an object for each category of subjects and in that there are kewords and link to the keywods let keywordsAndLinks = { //you can add more categories and define their keywords and add a link ds: { keywords: [ //you can add more keywords here they are detected and replaced with achor tag automatically 'data science', 'Data science', 'Data Science', 'data Science', 'DATA SCIENCE', ], //we will replace the linktext with the keyword later on in the code //you can easily change links for each category here //(include class="ml-link" and linktext) link: 'linktext', }, ml: { keywords: [ //Add more keywords 'machine learning', 'Machine learning', 'Machine Learning', 'machine Learning', 'MACHINE LEARNING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ai: { keywords: [ 'artificial intelligence', 'Artificial intelligence', 'Artificial Intelligence', 'artificial Intelligence', 'ARTIFICIAL INTELLIGENCE', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, nl: { keywords: [ 'NLP', 'nlp', 'natural language processing', 'Natural Language Processing', 'NATURAL LANGUAGE PROCESSING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, des: { keywords: [ 'data engineering services', 'Data Engineering Services', 'DATA ENGINEERING SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, td: { keywords: [ 'training data', 'Training Data', 'training Data', 'TRAINING DATA', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ias: { keywords: [ 'image annotation services', 'Image annotation services', 'image Annotation services', 'image annotation Services', 'Image Annotation Services', 'IMAGE ANNOTATION SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, l: { keywords: [ 'labeling', 'labelling', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, pbp: { keywords: [ 'previous blog posts', 'previous blog post', 'latest', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, mlc: { keywords: [ 'machine learning course', 'machine learning class', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, }; //Articles to skip let articleIdsToSkip = ['post-2651', 'post-3414', 'post-3540']; //keyword with its related achortag is recieved here along with article id function searchAndReplace(keyword, anchorTag, articleId) { //selects the h3 h4 and p tags that are inside of the article let content = document.querySelector(`#${articleId} .entry-content`); //replaces the "linktext" in achor tag with the keyword that will be searched and replaced let newLink = anchorTag.replace('linktext', keyword); //regular expression to search keyword var re = new RegExp('(' + keyword + ')', 'g'); //this replaces the keywords in h3 h4 and p tags content with achor tag content.innerHTML = content.innerHTML.replace(re, newLink); } function articleFilter(keyword, anchorTag) { //gets all the articles var articles = document.querySelectorAll('article'); //if its zero or less then there are no articles if (articles.length > 0) { for (let x = 0; x < articles.length; x++) { //articles to skip is an array in which there are ids of articles which should not get effected //if the current article's id is also in that array then do not call search and replace with its data if (!articleIdsToSkip.includes(articles[x].id)) { //search and replace is called on articles which should get effected searchAndReplace(keyword, anchorTag, articles[x].id, key); } else { console.log( `Cannot replace the keywords in article with id ${articles[x].id}` ); } } } else { console.log('No articles found.'); } } let key; //not part of script, added for (key in keywordsAndLinks) { //key is the object in keywords and links object i.e ds, ml, ai for (let i = 0; i < keywordsAndLinks[key].keywords.length; i++) { //keywordsAndLinks[key].keywords is the array of keywords for key (ds, ml, ai) //keywordsAndLinks[key].keywords[i] is the keyword and keywordsAndLinks[key].link is the link //keyword and link is sent to searchreplace where it is then replaced using regular expression and replace function articleFilter( keywordsAndLinks[key].keywords[i], keywordsAndLinks[key].link ); } } function cleanLinks() { // (making smal functions is for DRY) this function gets the links and only keeps the first 2 and from the rest removes the anchor tag and replaces it with its text function removeLinks(links) { if (links.length > 1) { for (let i = 2; i < links.length; i++) { links[i].outerHTML = links[i].textContent; } } } //arrays which will contain all the achor tags found with the class (ds-link, ml-link, ailink) in each article inserted using search and replace let dslinks; let mllinks; let ailinks; let nllinks; let deslinks; let tdlinks; let iaslinks; let llinks; let pbplinks; let mlclinks; const content = document.querySelectorAll('article'); //all articles content.forEach((c) => { //to skip the articles with specific ids if (!articleIdsToSkip.includes(c.id)) { //getting all the anchor tags in each article one by one dslinks = document.querySelectorAll(`#${c.id} .entry-content a.ds-link`); mllinks = document.querySelectorAll(`#${c.id} .entry-content a.ml-link`); ailinks = document.querySelectorAll(`#${c.id} .entry-content a.ai-link`); nllinks = document.querySelectorAll(`#${c.id} .entry-content a.ntrl-link`); deslinks = document.querySelectorAll(`#${c.id} .entry-content a.des-link`); tdlinks = document.querySelectorAll(`#${c.id} .entry-content a.td-link`); iaslinks = document.querySelectorAll(`#${c.id} .entry-content a.ias-link`); mlclinks = document.querySelectorAll(`#${c.id} .entry-content a.mlc-link`); llinks = document.querySelectorAll(`#${c.id} .entry-content a.l-link`); pbplinks = document.querySelectorAll(`#${c.id} .entry-content a.pbp-link`); //sending the anchor tags list of each article one by one to remove extra anchor tags removeLinks(dslinks); removeLinks(mllinks); removeLinks(ailinks); removeLinks(nllinks); removeLinks(deslinks); removeLinks(tdlinks); removeLinks(iaslinks); removeLinks(mlclinks); removeLinks(llinks); removeLinks(pbplinks); } }); } //To remove extra achor tags of each category (ds, ml, ai) and only have 2 of each category per article cleanLinks(); */ //Recommended Articles var ctaLinks = [ /* ' ' + '

Subscribe to our AI newsletter!

' + */ '

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

'+ '

Towards AI has published Building LLMs for Productionβ€”our 470+ page guide to mastering LLMs with practical projects and expert insights!

' + '
' + '' + '' + '

Note: Content contains the views of the contributing authors and not Towards AI.
Disclosure: This website may contain sponsored content and affiliate links.

' + 'Discover Your Dream AI Career at Towards AI Jobs' + '

Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 10,000 live jobs today with Towards AI Jobs!

' + '
' + '

πŸ”₯ Recommended Articles πŸ”₯

' + 'Why Become an LLM Developer? Launching Towards AI’s New One-Stop Conversion Course'+ 'Testing Launchpad.sh: A Container-based GPU Cloud for Inference and Fine-tuning'+ 'The Top 13 AI-Powered CRM Platforms
' + 'Top 11 AI Call Center Software for 2024
' + 'Learn Prompting 101β€”Prompt Engineering Course
' + 'Explore Leading Cloud Providers for GPU-Powered LLM Training
' + 'Best AI Communities for Artificial Intelligence Enthusiasts
' + 'Best Workstations for Deep Learning
' + 'Best Laptops for Deep Learning
' + 'Best Machine Learning Books
' + 'Machine Learning Algorithms
' + 'Neural Networks Tutorial
' + 'Best Public Datasets for Machine Learning
' + 'Neural Network Types
' + 'NLP Tutorial
' + 'Best Data Science Books
' + 'Monte Carlo Simulation Tutorial
' + 'Recommender System Tutorial
' + 'Linear Algebra for Deep Learning Tutorial
' + 'Google Colab Introduction
' + 'Decision Trees in Machine Learning
' + 'Principal Component Analysis (PCA) Tutorial
' + 'Linear Regression from Zero to Hero
'+ '

', /* + '

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

',*/ ]; var replaceText = { '': '', '': '', '
': '
' + ctaLinks + '
', }; Object.keys(replaceText).forEach((txtorig) => { //txtorig is the key in replacetext object const txtnew = replaceText[txtorig]; //txtnew is the value of the key in replacetext object let entryFooter = document.querySelector('article .entry-footer'); if (document.querySelectorAll('.single-post').length > 0) { //console.log('Article found.'); const text = entryFooter.innerHTML; entryFooter.innerHTML = text.replace(txtorig, txtnew); } else { // console.log('Article not found.'); //removing comment 09/04/24 } }); var css = document.createElement('style'); css.type = 'text/css'; css.innerHTML = '.post-tags { display:none !important } .article-cta a { font-size: 18px; }'; document.body.appendChild(css); //Extra //This function adds some accessibility needs to the site. function addAlly() { // In this function JQuery is replaced with vanilla javascript functions const imgCont = document.querySelector('.uw-imgcont'); imgCont.setAttribute('aria-label', 'AI news, latest developments'); imgCont.title = 'AI news, latest developments'; imgCont.rel = 'noopener'; document.querySelector('.page-mobile-menu-logo a').title = 'Towards AI Home'; document.querySelector('a.social-link').rel = 'noopener'; document.querySelector('a.uw-text').rel = 'noopener'; document.querySelector('a.uw-w-branding').rel = 'noopener'; document.querySelector('.blog h2.heading').innerHTML = 'Publication'; const popupSearch = document.querySelector$('a.btn-open-popup-search'); popupSearch.setAttribute('role', 'button'); popupSearch.title = 'Search'; const searchClose = document.querySelector('a.popup-search-close'); searchClose.setAttribute('role', 'button'); searchClose.title = 'Close search page'; // document // .querySelector('a.btn-open-popup-search') // .setAttribute( // 'href', // 'https://medium.com/towards-artificial-intelligence/search' // ); } // Add external attributes to 302 sticky and editorial links function extLink() { // Sticky 302 links, this fuction opens the link we send to Medium on a new tab and adds a "noopener" rel to them var stickyLinks = document.querySelectorAll('.grid-item.sticky a'); for (var i = 0; i < stickyLinks.length; i++) { /* stickyLinks[i].setAttribute('target', '_blank'); stickyLinks[i].setAttribute('rel', 'noopener'); */ } // Editorial 302 links, same here var editLinks = document.querySelectorAll( '.grid-item.category-editorial a' ); for (var i = 0; i < editLinks.length; i++) { editLinks[i].setAttribute('target', '_blank'); editLinks[i].setAttribute('rel', 'noopener'); } } // Add current year to copyright notices document.getElementById( 'js-current-year' ).textContent = new Date().getFullYear(); // Call functions after page load extLink(); //addAlly(); setTimeout(function() { //addAlly(); //ideally we should only need to run it once ↑ }, 5000); }; function closeCookieDialog (){ document.getElementById("cookie-consent").style.display = "none"; return false; } setTimeout ( function () { closeCookieDialog(); }, 15000); console.log(`%c πŸš€πŸš€πŸš€ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Towards AI is looking for contributors! β”‚ β”‚ Join us in creating awesome AI content. β”‚ β”‚ Let's build the future of AI together β†’ β”‚ β”‚ https://towardsai.net/contribute β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ `, `background: ; color: #00adff; font-size: large`); //Remove latest category across site document.querySelectorAll('a[rel="category tag"]').forEach(function(el) { if (el.textContent.trim() === 'Latest') { // Remove the two consecutive spaces (  ) if (el.nextSibling && el.nextSibling.nodeValue.includes('\u00A0\u00A0')) { el.nextSibling.nodeValue = ''; // Remove the spaces } el.style.display = 'none'; // Hide the element } }); // Add cross-domain measurement, anonymize IPs 'use strict'; //var ga = gtag; ga('config', 'G-9D3HKKFV1Q', 'auto', { /*'allowLinker': true,*/ 'anonymize_ip': true/*, 'linker': { 'domains': [ 'medium.com/towards-artificial-intelligence', 'datasets.towardsai.net', 'rss.towardsai.net', 'feed.towardsai.net', 'contribute.towardsai.net', 'members.towardsai.net', 'pub.towardsai.net', 'news.towardsai.net' ] } */ }); ga('send', 'pageview'); -->