Overview
Feature transformation is the core operation in LAFT that modifies image features based on a semantic concept subspace. LAFT provides two complementary projection operations:inner(): Projects features onto the concept subspace (guides toward the concept)orthogonal(): Projects features away from the concept subspace (ignores the concept)
laft/laft.py and use efficient linear algebra operations.
Inner Projection (Guide)
Theinner() function projects features onto the subspace spanned by concept vectors, amplifying the semantic concept in the feature representation.
Mathematical Formulation
Given feature vectors and concept basis (with orthonormal rows), the inner projection is: This is equivalent to: where are the rows of (basis vectors).Implementation
Fromlaft/laft.py:6-18:
Parameters
Image features to transform. Shape:
[batch_size, feature_size]Concept vectors defining the subspace. Can be:
- Single vector:
[feature_size] - Multiple vectors:
[num_vectors, feature_size]
If
True, assumes vectors are already orthonormal (from PCA). If False, computes orthonormal basis via SVD.Usage Example
When
basis=True (default), the function assumes vectors are orthonormal and skips SVD computation for efficiency. The pca() function returns orthonormal bases, so this is the recommended usage.Orthogonal Projection (Ignore)
Theorthogonal() function projects features onto the orthogonal complement of the concept subspace, removing the semantic concept from the representation.
Mathematical Formulation
The orthogonal projection removes all components in the concept subspace: This ensures for all basis vectors .Implementation
Fromlaft/laft.py:21-37:
Parameters
Image features to transform. Shape:
[batch_size, feature_size]Concept vectors defining the subspace to project away from. Can be:
- Single vector:
[feature_size] - Multiple vectors:
[num_vectors, feature_size]
If
True, normalizes the projected features to unit length. Useful when the projection significantly reduces feature magnitude.If
True, assumes vectors are already orthonormal. If False, computes orthonormal basis via SVD.Usage Example
Single Vector vs. Subspace Projection
Bothinner() and orthogonal() handle single vectors differently from multi-vector subspaces:
Single Vector (vectors.dim() == 1)
For a single concept vector :
Subspace (vectors.dim() == 2)
For multiple vectors forming a basis :
Choosing Between Inner and Orthogonal
The choice depends on your anomaly detection objective:When to use Inner Projection
When to use Inner Projection
Use
inner() when you want to emphasize a semantic concept:- Guide toward attribute: Amplify specific features (e.g., bird type, object category)
- Focus detection: Make the model more sensitive to variations in a particular concept
- Feature extraction: Extract only the components related to a concept of interest
When to use Orthogonal Projection
When to use Orthogonal Projection
Use
orthogonal() when you want to suppress a semantic concept:- Ignore spurious correlations: Remove confounding factors (e.g., background, lighting)
- Invariant features: Make detection robust to nuisance variations
- Debiasing: Remove unwanted biases from representations
Real-World Example from Scripts
Fromscripts/semantic/laft.py:42-54, here’s how projections are used in practice:
Projection Properties
Inner Projection
Applying inner projection twice gives the same result:
The effective dimensionality is reduced to (the number of basis vectors)
Maximally retains information about the concept while discarding orthogonal information
Orthogonal Projection
Applying orthogonal projection twice gives the same result
Result is orthogonal to all basis vectors:
Can significantly decrease if the concept explains high variance
Performance Considerations
Basis Assumption: Setting
basis=True (default) assumes vectors are orthonormal. If you construct vectors manually (not from pca()), either:- Orthonormalize them first, or
- Set
basis=Falseto compute SVD (slower but handles any vectors)
Subspace Dimensionality
The number of concept vectors () controls the expressiveness of the transformation:- Low (2-10): Captures only the most dominant semantic directions
- Medium (10-50): Balances concept specificity and generalization
- High (50+): Captures fine-grained variations but may include noise
See Also
Concept Subspace
Learn how to construct the concept basis using
prompt_pair() and pca()Overview
Understand the full LAFT methodology and workflow
