Stance Detection: Identifying Author Position
Module: Natural Language Processing | Difficulty: Advanced
Stance Detection
Target-Dependent
Cross-Target Transfer
Train on , test on .
Results
| Model | In-Domain | Cross-Target |
|---|---|---|
| BiLSTM | 72.3 | 58.1 |
| BERT | 78.5 | 65.2 |
| Multi-task | 80.1 | 71.3 |
import torch
import torch.nn as nn
class StanceDetector(nn.Module):
def __init__(self, bert_model, n_classes=3):
super().__init__()
self.bert = bert_model
self.target_attention = nn.Linear(768, 1)
self.classifier = nn.Linear(768*2, n_classes)
def forward(self, input_ids, attention_mask, target_ids):
text_out = self.bert(input_ids, attention_mask=attention_mask)
target_out = self.bert(target_ids)
text_cls = text_out.last_hidden_state[:, 0]
target_cls = target_out.last_hidden_state[:, 0]
combined = torch.cat([text_cls, target_cls], dim=-1)
return self.classifier(combined)
Research Insight: Stance detection is harder than sentiment analysis because it requires understanding the relationship between text and target. Cross-target transfer is challenging because different targets have different linguistic patterns.