∑GateAndNet
PlannerSign Up

Sequence Architectures Complexity Comparison (Length nn, Hidden Dim dd, Kernel kk)

Layer TypeComplexity per LayerSequential OperationsMaximum Path LengthCaptures Long-Range Dependencies?
Self-Attention (Transformer)O(n2⋅d)\mathcal{O}(n^2 \cdot d)O(1)\mathcal{O}(1) (fully parallel!)O(1)\mathcal{O}(1)✅ Direct token-to-token attention
Recurrent (RNN / LSTM / GRU)O(n⋅d2)\mathcal{O}(n \cdot d^2)O(n)\mathcal{O}(n) (sequential)O(n)\mathcal{O}(n)⚠️ Bottlenecked by sequential path
1D Convolutional (CNN)O(k⋅n⋅d2)\mathcal{O}(k \cdot n \cdot d^2)O(1)\mathcal{O}(1)O(log⁡kn)\mathcal{O}(\log_k n) (dilated)Bounded by receptive field

Core NLP & Transformer Formulas

  • Perplexity of Language Model: PPL(W)=P(w1,…,wN)−1/N=2H(W)\text{PPL}(W) = P(w_1, \dots, w_N)^{-1/N} = 2^{H(W)} — lower perplexity   ⟺  \iff better predictive probability!
  • TF-IDF Weight: wt,d=tft,d×log⁡ ⁣(Ndft)w_{t,d} = \text{tf}_{t,d} \times \log\!\left(\frac{N}{\text{df}_t}\right); Scaled Dot-Product Attention: Attention⁡(Q,K,V)=softmax⁡ ⁣(QKTdk)V\operatorname{Attention}(Q,K,V) = \operatorname{softmax}\!\left(\frac{QK^T}{\sqrt{d_k}}\right)V.
  • BERT vs GPT: BERT = Bidirectional Encoder (Masked LM + NSP, contextual embeddings); GPT = Causal Masked Decoder (Autoregressive next-token prediction P(wt∣w<t)P(w_t \mid w_{<t})).

AI Search & Reinforcement Learning Summary

Search StrategyComplete?Optimal?Time ComplexitySpace Complexity
BFS✅ (finite bb)✅ (unit step cost)O(bd)\mathcal{O}(b^d)O(bd)\mathcal{O}(b^d)
IDDFS (Iterative Deepening)✅✅ (unit step cost)O(bd)\mathcal{O}(b^d)O(b⋅d)\mathcal{O}(b \cdot d)
Uniform Cost Search (Dijkstra)✅ (c≥ϵ>0c \ge \epsilon > 0)✅O(b1+⌊C∗/ϵ⌋)\mathcal{O}(b^{1 + \lfloor C^*/\epsilon \rfloor})O(b1+⌊C∗/ϵ⌋)\mathcal{O}(b^{1 + \lfloor C^*/\epsilon \rfloor})
A* Tree / Graph Search✅✅ (hh admissible / consistent)Exponential in heuristic errorO(bd)\mathcal{O}(b^d) (keeps frontier)
  • Bellman Optimality (V∗V^*): V∗(s)=max⁡a∑s′T(s,a,s′)[R(s,a,s′)+γV∗(s′)]V^*(s) = \max_a \sum_{s'} T(s,a,s')\big[R(s,a,s') + \gamma V^*(s')\big]
  • Model-Free Q-Learning Update: Q(s,a)←(1−α)Q(s,a)+α[r+γmax⁡a′Q(s′,a′)]Q(s,a) \leftarrow (1 - \alpha)Q(s,a) + \alpha\big[r + \gamma \max_{a'} Q(s', a')\big] (off-policy!)