Deep Learning Track WiSe 24/25
Deep Learning Track WiSe 24/25
Deep Learning Track WiSe 24/25
  • Welcome to the Deep Learning Track
  • Setup
  • Learning Material
  • Section 1 - The Math
    • Derivatives and Gradients
    • Vectors, Matrices and Tensors
    • The power of matrix computation
    • Exercise - Matrix Computation
  • Section 2 - The Data
    • PyTorch Datasets and Data Loaders
    • Working with Data Tables
    • Exercise - Loading Data from a CSV file
    • Working with Images
    • Exercise - Image Datasets
    • Working with Text
  • Section 3 - Neural Networks
    • Activation Functions
    • Exercise - Activation Functions
    • Exercise - The Softmax Function
    • The Neuron
    • Two type of applications: Regression and Classification
    • Loss Functions
    • Exercise - Regression Loss Functions
    • Exercise - Classification Loss Functions
    • The Gradient Descent Algorithm
    • Exercise - Implementing Gradient Descent
    • Exercise - PyTorch Autograd
    • Exercise - Regression with Neural Networks
    • Exercise - Classification with Neural Networks
    • Playground - Neural Networks
  • Section 4 - Convolutional Neural Networks
    • Convolution
    • Convolutional Neural Networks
    • Classifying handwritten digits
    • Playground - Convolutional Neural Networks
    • Transfer Learning
  • Final Project - Text Classification
  • Further Resources
    • Computer Vision Libraries
    • Image Classification with PyTorch
    • Object Detection with PyTorch
    • Deep AI Explainability
Powered by GitBook
On this page
  1. Section 2 - The Data

Working with Text

In this section we will have a look how to load texts with PyTorch.

PreviousExercise - Image DatasetsNextSection 3 - Neural Networks

Working with texts

When it comes to natural language processing (NLP) tasks, text data needs to be converted into numerical representations that can be processed by neural networks. In NLP, the process of transferring text to tensors involves several important steps.

The first step is to preprocess the raw text data. This involves removing any unnecessary characters, punctuation, and special symbols. Additionally, the text is often converted to lowercase to ensure consistency. Preprocessing also typically involves tokenization, which is the process of splitting the text into individual words or smaller units such as subwords or characters. Tokenization helps in capturing the basic units of meaning in the text.

Once the text has been tokenized, the next step is to build a vocabulary. A vocabulary is a collection of unique words or tokens that appear in the text corpus. Each word in the vocabulary is assigned a unique index. This vocabulary is then used to map each word in the text data to its corresponding index.

After the vocabulary is constructed, the text is converted into numerical form by replacing each word with its respective index. This process is known as indexing. The result is a sequence of indices that represents the original text.

To further process the text for neural network input, we often need to ensure that all sequences have the same length. This is achieved by either padding shorter sequences with special tokens (such as zeros) or truncating longer sequences. Padding ensures that all text sequences have the same length, which is necessary for efficient batch processing in neural networks.

Once the text is indexed and padded (if necessary), it can be represented as a tensor. Typically, each text sample is represented as a one-dimensional tensor, where the length of the tensor corresponds to the maximum sequence length. The tensor consists of the sequence of indices representing the words in the text.

In addition to the one-dimensional representation, more sophisticated techniques can be used to capture the meaning and context of the text. For example, word embeddings can be applied to represent each word as a dense vector in a continuous space. These vectors can be learned from large text corpora using techniques like word2vec or GloVe. Word embeddings capture semantic relationships between words and can enhance the performance of NLP models.

In summary, transferring text to tensors involves preprocessing the text data, building a vocabulary, indexing the text, and representing it as a tensor. These steps enable neural networks to process and learn from textual data effectively. Understanding this process is crucial when working with NLP tasks and developing models that can handle text-based information.