Yolo Tầm nhìn Thâm Quyến
Thâm Quyến
Tham gia ngay
Bảng chú giải thuật ngữ

Mô Hình Dãy-Sang-Dãy

Explore Sequence-to-Sequence (Seq2Seq) models. Learn how encoder-decoder architectures and Transformers power translation, NLP, and multi-modal AI tasks.

Sequence-to-Sequence (Seq2Seq) models are a powerful class of machine learning architectures designed to convert sequences from one domain into sequences in another. Unlike standard image classification tasks where the input and output sizes are fixed, Seq2Seq models excel at handling inputs and outputs of variable lengths. This flexibility makes them the backbone of many modern natural language processing (NLP) applications, such as translation and summarization, where the length of the input sentence does not necessarily dictate the length of the output sentence.

Kiến trúc và chức năng cốt lõi

The fundamental structure of a Seq2Seq model relies on the encoder-decoder framework. This architecture splits the model into two primary components that work in tandem to process sequential data.

  • The Encoder: This component processes the input sequence (e.g., a sentence in English or a sequence of audio frames) one element at a time. It compresses the information into a fixed-length context vector, also known as the hidden state. In traditional architectures, the encoder is often built using Recurrent Neural Networks (RNN) or Long Short-Term Memory (LSTM) networks, which are designed to retain information over time steps.
  • The Decoder: Once the input is encoded, the decoder takes the context vector and predicts the output sequence (e.g., the corresponding sentence in French) step-by-step. It uses the previous prediction to influence the next one, ensuring grammatical and contextual continuity.

While early versions relied heavily on RNNs, modern Seq2Seq models predominantly use the Transformer architecture. Transformers utilize the attention mechanism, which allows the model to "pay attention" to specific parts of the input sequence regardless of their distance from the current step, significantly improving performance on long sequences as detailed in the seminal paper Attention Is All You Need.

Các Ứng dụng Thực tế

The versatility of Seq2Seq models allows them to bridge the gap between text analysis and computer vision, enabling complex multi-modal interactions.

  • Machine Translation: Perhaps the most famous application, Seq2Seq models power tools like Google Translate. The model accepts a sentence in a source language and outputs a sentence in a target language, handling differences in grammar and sentence structure fluently.
  • Tóm tắt văn bản : Các mô hình này có thể tiếp nhận các tài liệu hoặc bài viết dài và tạo ra các bản tóm tắt ngắn gọn. Bằng cách hiểu được ý nghĩa cốt lõi của văn bản đầu vào, bộ giải mã tạo ra một chuỗi ngắn hơn nhưng vẫn giữ được thông tin chính, một kỹ thuật thiết yếu cho việc tổng hợp tin tức tự động.
  • Chú thích ảnh: Bằng cách kết hợp thị giác và ngôn ngữ, mô hình Seq2Seq có thể mô tả nội dung của một hình ảnh. Mạng nơ-ron tích chập (CNN) đóng vai trò là bộ mã hóa để trích xuất các đặc điểm hình ảnh, trong khi mạng nơ -ron hồi quy (RNN) đóng vai trò là bộ giải mã để tạo ra câu mô tả. Đây là một ví dụ điển hình của mô hình đa phương thức .
  • Nhận dạng giọng nói : Trong các hệ thống này, đầu vào là một chuỗi các khung tín hiệu âm thanh và đầu ra là một chuỗi các ký tự văn bản hoặc từ. Công nghệ này hỗ trợ các trợ lý ảo như Siri và Alexa.

Code Example: Basic Building Block

While high-level frameworks abstract much of the complexity, understanding the underlying mechanism is helpful. The following code demonstrates a basic LSTM layer in PyTorch, which often serves as the recurrent unit within the encoder or decoder of a traditional Seq2Seq model.

import torch
import torch.nn as nn

# Initialize an LSTM layer (common in Seq2Seq encoders)
# input_size: number of features per time step (e.g., word embedding size)
# hidden_size: size of the context vector/hidden state
lstm_layer = nn.LSTM(input_size=10, hidden_size=20, batch_first=True)

# Create a dummy input sequence: Batch size 3, Sequence length 5, Features 10
input_seq = torch.randn(3, 5, 10)

# Pass the sequence through the LSTM
# output contains features for each time step; hn is the final hidden state
output, (hn, cn) = lstm_layer(input_seq)

print(f"Output shape: {output.shape}")  # Shape: [3, 5, 20]
print(f"Final Hidden State shape: {hn.shape}")  # Shape: [1, 3, 20]

So sánh với các khái niệm liên quan

Điều quan trọng là phải phân biệt các mô hình Seq2Seq với các kiến trúc khác để hiểu được tiện ích cụ thể của chúng.

  • So với Phân loại Chuẩn: Các bộ phân loại chuẩn, chẳng hạn như các bộ phân loại được sử dụng trong phân loại hình ảnh cơ bản, ánh xạ một đầu vào duy nhất (như hình ảnh) thành một nhãn lớp duy nhất. Ngược lại, các mô hình Seq2Seq ánh xạ các chuỗi thành các chuỗi, cho phép độ dài đầu ra thay đổi.
  • So với phát hiện đối tượng: Các mô hình như Ultralytics YOLO26 tập trung vào phát hiện không gian trong một khung hình duy nhất, xác định các đối tượng và vị trí của chúng. Trong khi đó, YOLO Mô hình Seq2Seq xử lý hình ảnh theo cấu trúc, trong khi mô hình Seq2Seq xử lý dữ liệu theo thời gian. Tuy nhiên, hai lĩnh vực này chồng chéo nhau trong các tác vụ như theo dõi đối tượng , nơi việc xác định quỹ đạo của đối tượng trên các khung hình video liên quan đến phân tích dữ liệu tuần tự.
  • So với Transformer: Kiến trúc Transformer là sự phát triển hiện đại của Seq2Seq. Trong khi các mô hình Seq2Seq ban đầu chủ yếu dựa vào RNN và Gated Recurrent Unit (GRU) , Transformer sử dụng khả năng tự động xử lý các chuỗi song song, mang lại những cải tiến đáng kể về tốc độ và độ chính xác.

Importance in the AI Ecosystem

Seq2Seq models have fundamentally changed how machines interact with human language and temporal data. Their ability to handle sequence-dependent data has enabled the creation of sophisticated chatbots, automated translators, and code generation tools. For developers working with large datasets required to train these models, using the Ultralytics Platform can streamline data management and model deployment workflows. As research progresses into Generative AI, the principles of sequence modeling remain central to the development of Large Language Models (LLMs) and advanced video understanding systems.

Tham gia Ultralytics cộng đồng

Tham gia vào tương lai của AI. Kết nối, hợp tác và phát triển cùng với những nhà đổi mới toàn cầu

Tham gia ngay