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

Python for Natural Language Processing: A Beginner’s Guide
Latest   Machine Learning

Python for Natural Language Processing: A Beginner’s Guide

Last Updated on July 25, 2023 by Editorial Team

Author(s): Sarang S

Originally published on Towards AI.

Python for Natural Language Processing: A Beginner’s Guide

Introduction

Natural Language Processing (NLP) is the study of making natural human language readable to computer programs. It is a fast-expanding field with important applications in banking, healthcare, and technology. Python is one of the most popular programming languages used for natural language processing (NLP) because of its ease of use, versatility, and abundance of open-source libraries.

In this beginner’s guide to NLP with Python, we will look at the fundamentals of NLP and its applications, as well as how to set up a Python environment for NLP, dive into preprocessing, and build a simple NLP application in Python. By the end of this guide, you will have a good knowledge of NLP in Python and be ready to tackle more advanced projects.

Setting up the Python environment for NLP

The first step in getting started with Natural Language Processing (NLP) in Python is to configure your development environment. Here are some fundamental steps for getting your Python environment ready for NLP:

1. Install Python:

Depending on your operating system, you can download and install Python from the official website. Be sure to download the most recent Python version. The steps for installing Python on Windows are as follows:

  1. Go to the Python official website: https://www.python.org/downloads/
  2. Click on the “Download Python” button, which will navigate you to the download page.
  3. Scroll down to the “Stable Releases” section and select the most recent Python version. You can use Python 3.x or Python 2.x, however, Python 3.x is preferred because it is the most recent stable version.
  4. Click on the download link that corresponds to your operating system. For example, if you have a 64-bit Windows operating system, you should download the “Windows x86–64 executable installer.”
  5. After downloading the installer, double-click the executable file to start the installation process.
  6. Select the “Add Python X.X to PATH” option on the first screen of the installer. This adds Python to your system’s PATH, making it easier to execute Python from the command prompt.
  7. Complete the installation by following the remaining installation steps.
  8. To check if Python is correctly installed, open the command prompt and type “python — version” and press Enter. This will display the Python version that you have installed in your system.

2. Install a package manager:

A package manager like pip will help you install and manage packages, which are the libraries used for NLP. Use the command ‘pip — version’ to see if pip is already installed. If not, you can follow the instructions below instructions to install it.

  1. Go to the official pip website: https://pip.pypa.io/en/stable/installation/
  2. Download the get-pip.py script by clicking on the “get-pip.py” link.
  3. Open a command prompt and navigate to the directory where you downloaded the get-pip.py script.
  4. Execute the following command: py get-pip.py
  5. This will download and install pip on your system. Once the installation is complete, execute the following line to see if pip is correctly installed: “pip — version”
  6. If pip is installed correctly, you will be able to see the version of pip that is installed on your system.

3. Install NLP Libraries:

Many NLP libraries are available in Python, and the installation process varies depending on the library. This feature of python makes it very useful for artificial intelligence and machine learning applications. For more information on installation and usage, check the official documentation of the library you want to install.

  • NLTK: NLTK is a powerful NLP library in Python that offers a wide range of features for text processing and analysis. To install NLTK, open a command prompt and run the following command: pip install nltk. You can find more information about NLTK and its features on the official NLTK website: https://www.nltk.org/
  • spaCy: spaCy is another well-known NLP library that offers efficient text processing and language modeling features. To install spaCy, run the following command: pip install spacy. Once spaCy is installed, use the following command to download the language model for a specified language: python -m spacy download. For example, you can run python -m spacy download en to download the English language model. You can find more information about spaCy and its features on the official spaCy website: https://spacy.io/
  • TextBlob: TextBlob is a simple and easy-to-use NLP library that provides basic NLP tasks such as sentiment analysis, part-of-speech tagging, and noun phrase extraction. To install TextBlob, run the following command: pip install textblob. You can find more information about TextBlob and its features on the official TextBlob website: https://textblob.readthedocs.io/en/dev/

4. Download language models:

Some NLP libraries require language models to be downloaded separately. For example, spaCy requires a specific language model to be installed before you can use it for a particular language. You can download the required language models using the respective libraries’ commands.

5. Set up a development environment:

It is recommended to use an integrated development environment (IDE) such as PyCharm or Visual Studio Code while working on NLP projects in Python. You can download and install an IDE of your choice.

  • Installing PyCharm
  1. Go to the official PyCharm website: https://www.jetbrains.com/pycharm/download/
  2. Select the version of PyCharm you want to download (Community or Professional) and click on the “Download” button.
  3. Once the download is complete, run the PyCharm installer.
  4. To finish the installation process, keep following the installation wizard.
  5. Once the installation is complete, you can open PyCharm and start using it.
  • Installing Visual Studio Code
  1. Go to the official Visual Studio Code website: https://code.visualstudio.com/download
  2. Click on the “Download for Windows” button to download the Visual Studio Code installer.
  3. Once the download is complete, run the Visual Studio Code installer.
  4. To finish the installation process, keep following the installation wizard.
  5. Once the installation is complete, you can open Visual Studio Code and start using it.

Working with Text Data in Python

Once you have set up your Python environment and installed the necessary packages and libraries, you can start working with text data in Python for NLP projects. Here are some basic operations you can perform on text data using Python:

Reading text Data

To read a text file in Python, you can use the built-in open() function. Here’s an example:

with open('data.txt', 'r') as f:
text = f.read()

This code reads the contents of the data.txt file and stores it in the text variable.

Cleaning text Data

Before you can perform any NLP analysis on text data, you need to clean the data by removing any unnecessary characters, punctuation, and stopwords. Here are some common operations you can perform to clean text data:

Remove punctuation: You can remove all punctuation characters using regular expressions. Here’s an example:

import re
text = re.sub(r'[^\w\s]', '', text)

This code removes all non-word and non-space characters from the text variable.

Convert to lowercase: You can convert all text to lowercase to ensure consistency. Here’s an example:

text = text.lower()

This code converts all uppercase characters in the text variable to lowercase.

Remove stopwords: You can remove common stopwords (such as “a”, “an”, “the”, “is”, “of”, etc.) using the NLTK library. Here’s an example:

from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
stop_words = set(stopwords.words('english'))
words = word_tokenize(text)
filtered_words = [word for word in words if word not in stop_words]

This code removes all stopwords from the text variable and stores the result in the filtered_words variable.

Tokenizing text Data

Tokenization is the process of splitting text into individual words or tokens. Here’s an example of how to tokenize text using the NLTK library:

from nltk.tokenize import word_tokenize
words = word_tokenize(text)

This code tokenizes the text variable and stores the result in the words variable.

Stemming and Lemmatizing text data

Stemming and lemmatization are techniques used to reduce words to their root form (or lemma) for analysis. Here’s an example of how to stem and lemmatize text using the NLTK library:

from nltk.stem import PorterStemmer, WordNetLemmatizer
from nltk.tokenize import word_tokenize
stemmer = PorterStemmer()
lemmatizer = WordNetLemmatizer()
words = word_tokenize(text)
stemmed_words = [stemmer.stem(word) for word in words]
lemmatized_words = [lemmatizer.lemmatize(word) for word in words]

This code stems and lemmatizes the text variable and stores the results in the stemmed_words and lemmatized_words variables, respectively.

Preprocessing text Data for NLP

Preprocessing text data is an important step in NLP as it prepares the data for analysis and modeling. Here are some common preprocessing techniques used in NLP:

Tokenization

Tokenization is the process of dividing a string of text into distinct tokens, typically words. This is an important stage in NLP because most analyses rely on individual words as building blocks for subsequent processing. The NLTK library includes a range of tokenizers for different languages and use cases.

import nltk
# Download the required resources
nltk.download('punkt')
# Tokenize text
text = "This is an example sentence."
tokens = nltk.word_tokenize(text)
print(tokens)

# Output:

['This', 'is', 'an', 'example', 'sentence', '.']

Stop word removal

Stop words, such as “the,” “and,” “is,” and “an,” are common words that appear frequently in a language. These terms are frequently irrelevant to the analysis and can be removed to reduce the noise in the data. The NLTK library includes a list of English stop words for this purpose.

import nltk
# Download the required resources
nltk.download('stopwords')
from nltk.corpus import stopwords
# Remove stop words
text = "This is an example sentence."
tokens = nltk.word_tokenize(text)
filtered_tokens = [word for word in tokens if word.lower() not in stopwords.words('english')]
print(filtered_tokens)

# Output:

['example', 'sentence', '.']

Stemming

Stemming is the process of reducing words to their base or stem form, by removing any prefixes or suffixes. This is a common technique for reducing the dimensionality of the data, as it groups similar words together.

import nltk
# Stem text
text = "This is an example sentence."
tokens = nltk.word_tokenize(text)
stemmer = nltk.PorterStemmer()
stemmed_tokens = [stemmer.stem(token) for token in tokens]
print(stemmed_tokens)

# Output:

['thi', 'is', 'an', 'exampl', 'sentenc', '.']

Lemmatization

Lemmatization is a similar process to stemming, but it reduces words to their base form by using a dictionary or knowledge of the language. This can result in more accurate base forms than stemming.

import nltk
# Lemmatize text
text = "This is an example sentence."
tokens = nltk.word_tokenize(text)
lemmatizer = nltk.WordNetLemmatizer()
lemmatized_tokens = [lemmatizer.lemmatize(token) for token in tokens]
print(lemmatized_tokens)

# Output:

['This', 'is', 'an', 'example', 'sentence', '.']

Building a simple NLP application with Python

Creating an NLP application is an excellent method to study NLP and apply your knowledge. Here’s an example of a simple NLP program that analyses text data using Python and some famous NLP libraries.

Problem Statement

In this example, we want to build a simple sentiment analysis application. The goal is to classify a given text into positive, negative, or neutral sentiments.

Solution

We can use the following steps to solve this problem:

  1. Load the data
  2. Preprocess the data
  3. Feature extraction and text representation
  4. Train a machine-learning model
  5. Analyze the model
  6. Use the model to make predictions on new data

Here’s the code for creating the sentiment analysis application using Python and some popular NLP libraries.

import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import accuracy_score
import nltk
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
# Load the data
df = pd.read_csv('data.csv')
# Preprocess the data
nltk.download('stopwords')
nltk.download('wordnet')
stop_words = set(stopwords.words('english'))
lemmatizer = WordNetLemmatizer()
def preprocess_text(text):
words = nltk.word_tokenize(text.lower())
words = [w for w in words if w.isalpha()]
words = [w for w in words if w not in stop_words]
words = [lemmatizer.lemmatize(w) for w in words]
return ' '.join(words)
df['text'] = df['text'].apply(preprocess_text)
# Feature extraction and text representation
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(df['text'])
y = df['sentiment']
# Train a machine learning model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf = MultinomialNB()
clf.fit(X_train, y_train)
# Evaluate the model
y_pred = clf.predict(X_test)
acc = accuracy_score(y_test, y_pred)
print('Accuracy:', acc)
# Use the model to make predictions on new data
new_text = ['I love this product!', 'This movie was terrible.', 'The weather is nice today.']
new_text = [preprocess_text(text) for text in new_text]
X_new = vectorizer.transform(new_text)
y_new = clf.predict(X_new)
print('Predictions:', y_new)

In this example, we use a dataset with text and sentiment labels. We preprocess the text by converting it to lowercase, removing stop words and punctuation, and lemmatizing the words. We then use TF-IDF for feature extraction and text representation. We train a Naive Bayes classifier on the data and evaluate the model using accuracy. Finally, we use the model to make predictions on new text data.

Conclusion

  • Python is a popular programming language used for Natural Language Processing (NLP) due to its simplicity, flexibility, and a large number of libraries and tools available.
  • Setting up a development environment with the right tools and packages is essential for efficient and effective NLP work.
  • Preprocessing text data is a crucial step in NLP and involves tasks like tokenization, stemming, lemmatization, and removing stop words and punctuation.
  • NLP applications can be built using a variety of machine-learning techniques, such as classification, clustering, and topic modeling.
  • By understanding these key concepts and tools in Python for NLP, beginners can start building their own NLP applications and exploring the vast potential of this field.

Reference :

Stackoverflow, Chegg, NLP by Gizem

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'); -->