3203. Introduction to Artificial Intelligence

Natural Language Processing

1. Natural Language

A language functions as a symbol system that enables agents to map commonly used symbols to their internal representations. Linguistic analysis spans three major levels: For communication between artificial intelligence agents and humans, Natural Language Processing (NLP) comprises two core components:

Human natural languages are significantly harder to process than formal or programming languages. Unlike formal languages with rigid specifications, human languages evolved historically. Consequently, their syntactic, semantic, and pragmatic mappings are never fully well-specified, evolve over time, and rely heavily on context and user intent.

2. Symbolic (Rule-Based) Approaches

Typical stages of symbolic NLU:
  1. Parsing: analyzing the syntactic structure of each sentence into a tree, according to a given grammar.
  2. Interpreting: mapping a parsing tree to an internal representation, according to given definitions of the words.
  3. Enhancing: augmenting the representation with background knowledge to get the intended meaning.
  4. Using: supporting multiple usages of the represented sentences, according to given algorithms.
Typical stages of NLG:
  1. Content determination
  2. Document structuring
  3. Aggregation
  4. Lexical choice
  5. Referring expression generation
  6. Realization
Traditional rule-based approaches rely on established linguistic rules, though they often lack flexibility and naturalness.

3. Statistical and Neural Approaches

Statistical NLP views natural language as an observable random process that can be modeled using sample data: Modern deep neural networks extend this by learning end-to-end probabilistic mappings between linguistic materials directly from data.

4. Word Embeddings

Word Embeddings models (such as Word2vec) is shown in Figure 8.10, which operate by taking a single word and predicting which words are likely to appear near it in context.

The input layer utilizes one-hot vectors where each dictionary word corresponds to an input unit (valued 1 for the active word and 0 for all others). The input layer feeds into a hidden encoder layer that represents the word as a vector, which a decoder maps to an output layer representing vocabulary words.

This neural network can be trained by backpropagation to learn the context of a word, i.e., the words appearing around it, such as predicting the next word (Example 8.9).

Vector addition and subtraction capture semantic relations, enabling the model to solve analogical reasoning tasks of the form "A:B = C:X".

5. Recurrent Neural Networks

Recurrent Neural Networks explicitly model sequential data by introducing feedback connections that feed each node's previous state back into the network (Figure 8.11).

Figure 8.13 shows a RNN used for sequence-to-sequence mapping when input and output lengths do not match one-to-one. The final hidden state of the encoder serves as a context vector containing all information from the input sequence, which the decoder uses as a generative language model to emit the output sequence element by element.

For a given input size, recurrent neural networks are feedforward networks with shared parameters. Stochastic gradient descent and related methods work, with the proviso that during backpropagation, the (shared) weights are updated whenever they were used in the prediction.

A Long Short-Term Memory is a specialized RNN architecture designed to preserve memory over longer horizons and capture long-term dependencies unless superseded by new information.

6. Transformers and Large Language Models (LLMs)

To overcome the sequential bottlenecks of RNNs, modern architectures leverage attention mechanisms. Though LLMs have successfully accomplished many NLP functions, they still have serious issues, such as