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:
- Syntax: Format and structural arrangement.
- Semantics: Meaning and interpretation.
- Pragmatics: Contextual usage.
For communication between artificial intelligence agents and humans, Natural Language Processing (NLP) comprises two core components:
- NLU (Natural Language Understanding): Comprehension and analysis.
- NLG (Natural Language Generation): Production and synthesis.
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:
- Parsing: analyzing the syntactic structure of each sentence into a tree, according to a given grammar.
- Interpreting: mapping a parsing tree to an internal representation, according to given definitions of the words.
- Enhancing: augmenting the representation with background knowledge to get the intended meaning.
- Using: supporting multiple usages of the represented sentences, according to given algorithms.
Typical stages of NLG:
- Content determination
- Document structuring
- Aggregation
- Lexical choice
- Referring expression generation
- 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:
- Corpus Foundation: Beginning with a text corpus (collections of raw or annotated text).
- Probability Learning: Learning relevant statistical probability distributions.
- Pattern Prediction: Treating NLU and NLG as probabilistic pattern association and prediction.
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.
- Attention Mechanisms: Compute a probability distribution over input tokens or regions to generate an expected embedding conditioned on context.
- Transformers: Utilize self-attention mechanisms to evaluate the influence of each input token on output tokens, estimating token probabilities conditioned on preceding context.
- Large Language Models (LLMs): Massive neural networks pretrained on vast linguistic datasets. While their primary objective is next-token prediction, this training equips them with rich syntactic, semantic, and ontological knowledge, alongside powerful "emergent abilities".
Though LLMs have successfully accomplished many NLP functions, they still have serious issues, such as
- Hallucinations, misinformation, and lack of reliability
- Bias, fairness, and representation
- Privacy, ownership, and data security
- Economic and social impacts