Skip to content
Query Feedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  1. Home /
  2. AI Glossaries /
  3. LLMs /
  4. What is a Feed-Forward Network in a Transformer?
LLMs

What is a Feed-Forward Network in a Transformer?

Updated September 26, 2026 Read 3 min

A feed-forward network (FFN) is the part of a transformer block that processes each token's representation independently through two linear layers with an activation in between. It holds most of a transformer's parameters.

Contents 11
  1. 01Key takeaways
  2. 02An FFN explained in simple terms
  3. 03How an FFN works
  4. 04A worked example: counting parameters
  5. 05Gated FFNs and SwiGLU
  6. 06What FFNs do inside the model
  7. 07Mixture of experts
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

A feed-forward network (FFN) is the component of a transformer block that processes each token’s representation on its own, after attention has mixed information between tokens. It typically expands the representation to a larger dimension, applies an activation function, then projects it back. FFN layers hold the majority of a transformer’s parameters.

Key takeaways

  • Attention mixes information between tokens; the FFN transforms each token.
  • The FFN usually expands to about 4 times the model dimension, then contracts.
  • It accounts for roughly two thirds of parameters in many transformer models.
  • Modern LLMs often use SwiGLU-style gated FFNs instead of a simple activation.
  • Mixture-of-experts designs replace the FFN with many expert FFNs, activating only a few per token.

An FFN explained in simple terms

Think of a transformer block as a meeting followed by private work. In the meeting (attention), everyone shares information. Afterwards, each person goes back to their desk and processes what they heard on their own (the FFN). The private step is where much of the actual thinking happens, and it is identical in structure for everyone, though the input differs.

How an FFN works

  1. Take the output vector for one token, of size d_model.
  2. Multiply by the first weight matrix to expand to a larger size, d_ff.
  3. Apply a non-linear activation, such as ReLU, GELU or SwiGLU.
  4. Multiply by a second matrix to project back to d_model.
  5. Add the result to the block’s input through a residual connection.

The same weights are applied to every position, so the FFN is like a small network run separately on each token.

A worked example: counting parameters

Take a model with d_model = 4,096 and d_ff = 16,384, a common 4× ratio.

  • First matrix: 4,096 × 16,384 = 67.1 million parameters.
  • Second matrix: 16,384 × 4,096 = 67.1 million.
  • FFN total per layer: about 134 million.

Attention in the same layer has four matrices of 4,096 × 4,096, about 67 million in total. So the FFN holds roughly twice the attention parameters, which is why FFNs dominate model size and why mixture-of-experts designs target them.

Gated FFNs and SwiGLU

Many recent LLMs use a gated variant, commonly SwiGLU, proposed by Noam Shazeer in 2020. It uses three matrices instead of two: one produces values, one produces a gate that scales them, and one projects back. Gated FFNs tend to perform better at the same parameter count, so d_ff is often reduced to keep the totals comparable.

What FFNs do inside the model

Interpretability research suggests FFN layers act somewhat like a key-value memory: certain input patterns trigger specific stored associations, contributing much of a model’s factual recall. Editing model facts often involves modifying FFN weights.

Mixture of experts

Instead of one FFN per layer, a mixture-of-experts (MoE) layer contains many expert FFNs and a router that sends each token to a small number of them. This increases total parameters while keeping compute per token low, an approach used by several large models.

Limitations

  • Dominates parameter count, memory and inference cost.
  • Processes tokens independently, so all cross-token work must happen in attention.
  • Larger d_ff improves capacity but raises cost quickly.

Common Use Cases

01

Transformer model design

Choose d_ff ratios and activation functions when building models.

02

Model compression

Target FFN layers for pruning and quantization savings.

03

Mixture-of-experts scaling

Replace dense FFNs with routed experts to grow capacity.

04

Knowledge editing

Modify FFN weights to update stored facts.

05

Efficiency research

Study where parameters and compute are spent.

06

Fine-tuning targets

Apply LoRA to FFN layers as well as attention.

Frequently Asked Questions

The layer that processes each token's representation independently, expanding then contracting it with an activation in between.

Attention mixes information between tokens but applies limited transformation. The FFN adds per-token non-linear processing.

With a 4× expansion, the FFN typically holds about twice as many parameters as attention in the same layer.

A gated feed-forward variant, proposed in 2020, that often performs better than a plain activation at similar size.

An architecture that replaces a single FFN with many expert FFNs and routes each token to only a few of them.

Related Terms

  • Transformer
  • Self-Attention
  • Activation Function
  • Mixture of Experts
  • Model Quantization
  • LoRA

Related AI Terms

What is an Attention Head?An attention head is a single attention unit inside a transformer layer, with its own query, key and…What is Prefix Tuning?Prefix tuning is a parameter-efficient fine-tuning method that learns trainable vectors inserted into the attention keys and values…What is an Attention Mechanism?An attention mechanism is a technique that lets a neural network focus on the most relevant parts of…What is Self-Attention?Self-attention is a mechanism where each position in a sequence attends to every other position in the same…What is Multi-Head Attention?Multi-head attention runs several attention operations in parallel, each with its own learned projections, so a model can…What is RoPE (Rotary Positional Embedding)?RoPE (rotary positional embedding) encodes a token's position by rotating its query and key vectors by an angle…

Contents

  1. 01Key takeaways
  2. 02An FFN explained in simple terms
  3. 03How an FFN works
  4. 04A worked example: counting parameters
  5. 05Gated FFNs and SwiGLU
  6. 06What FFNs do inside the model
  7. 07Mixture of experts
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

AI Topic

  • LLMs

Related Terms

  • What is an Attention Head?
  • What is Prefix Tuning?
  • What is an Attention Mechanism?
  • What is Self-Attention?
  • What is Multi-Head Attention?
  • What is RoPE (Rotary Positional Embedding)?

Quick Navigation

  • Common Use Cases
  • Frequently Asked Questions
  • Related Terms
  • Back to top

Details

Updated
September 26, 2026
Read
3 min
  • Forum
  • Submit a tool
  • Submit Guest Post
  • List Your Startup
  • Privacy Policy
  • Editorial Policy
  • Account
  • Contact
  • AI Productivity
  • AI Video
  • AI Coding
  • AI Chatbots
  • Sales
  • AI Business
  • View All Tools

Subscribe our Newsletter

Get weekly exclusive content - No spam.

Copyright © 2026 -  Query Feedz

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}