πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Domain Adaptation: Bridging Source and Target Domains

Machine LearningDomain Adaptation: Bridging Source and Target Domains🟒 Free Lesson

Advertisement

Domain Adaptation: Bridging Source and Target Domains

Module: Machine Learning | Difficulty: Advanced

Domain Adaptation Setting

Source: , Target:

H-Divergence

MMD (Maximum Mean Discrepancy)

Domain-Adversarial Neural Network (DANN)

Theory

where is the joint ideal error.

import torch
import torch.nn as nn

class DomainAdversarial(nn.Module):
    def __init__(self, feature_extractor, classifier, domain_classifier):
        super().__init__()
        self.feature = feature_extractor
        self.classifier = classifier
        self.domain = domain_classifier
        self.grl = GradientReversalLayer()
    def forward(self, x):
        features = self.feature(x)
        class_pred = self.classifier(features)
        domain_pred = self.domain(self.grl(features))
        return class_pred, domain_pred

class GradientReversalFunction(torch.autograd.Function):
    @staticmethod
    def forward(ctx, x, alpha):
        ctx.alpha = alpha
        return x.view_as(x)
    @staticmethod
    def backward(ctx, grad_output):
        return -ctx.alpha * grad_output, None

Research Insight: The key insight in domain adaptation is that features that are invariant across domains are useful for transfer. Adversarial training enforces this invariance, but can hurt performance if the domains have different label distributions.

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement