[Paper Review] How recurrent networks implement contextual processing in sentiment analysis
This paper proposes a reverse engineering framework to interpret how recurrent neural networks (RNNs) implement contextual processing in sentiment analysis, using input Jacobians and state dynamics analysis to identify contextual modifiers, quantify their strength and timescale, and model their effects. The key contribution is demonstrating that simple, interpretable models enhanced with these insights recover over 90% of the performance gain from complex RNNs.
Neural networks have a remarkable capacity for contextual processing--using recent or nearby inputs to modify processing of current input. For example, in natural language, contextual processing is necessary to correctly interpret negation (e.g. phrases such as "not bad"). However, our ability to understand how networks process context is limited. Here, we propose general methods for reverse engineering recurrent neural networks (RNNs) to identify and elucidate contextual processing. We apply these methods to understand RNNs trained on sentiment classification. This analysis reveals inputs that induce contextual effects, quantifies the strength and timescale of these effects, and identifies sets of these inputs with similar properties. Additionally, we analyze contextual effects related to differential processing of the beginning and end of documents. Using the insights learned from the RNNs we improve baseline Bag-of-Words models with simple extensions that incorporate contextual modification, recovering greater than 90% of the RNN's performance increase over the baseline. This work yields a new understanding of how RNNs process contextual information, and provides tools that should provide similar insight more broadly.
Motivation & Objective
- To develop generalizable tools for interpreting contextual processing in recurrent neural networks (RNNs), particularly in sentiment classification.
- To identify and characterize inputs that induce contextual effects—such as negation and intensification—by analyzing gradients and dynamics.
- To quantify the strength, duration, and functional roles of contextual modifiers in RNNs using data-driven methods.
- To bridge the gap between complex RNN behavior and interpretable, lightweight models by extracting core mechanisms of contextual processing.
- To validate that simple models incorporating identified contextual rules can closely match RNN performance, demonstrating the practical utility of interpretability tools.
Proposed method
- Use input Jacobians (sensitivity of network output to input perturbations) to identify inputs that trigger contextual effects, such as negation or intensification.
- Analyze recurrent state dynamics using state Jacobians to understand transient, time-dependent responses to contextual inputs.
- Visualize RNN trajectories via PCA to identify approximate line attractors where sentiment predictions are encoded along a 1D manifold.
- Cluster contextual inputs based on shared dynamical response patterns to classify types of modifiers (e.g., negators, intensifiers).
- Construct interpretable baseline models by incorporating identified contextual rules—such as BOD/EOD tokens and modifier-specific weights—into Bag-of-Words frameworks.
- Train and evaluate these enhanced baselines on Yelp and IMDB datasets to compare performance against RNNs and standard BoW models.
Experimental results
Research questions
- RQ1What types of inputs induce contextual processing in RNNs trained on sentiment classification?
- RQ2How strong and over what timescale do contextual effects operate in trained RNNs?
- RQ3Can we model the dynamics of contextual processing using a mathematical framework based on input and state Jacobians?
- RQ4To what extent can simple, interpretable models replicate the performance of complex RNNs by incorporating identified contextual mechanisms?
- RQ5How do the properties of learned contextual effects compare to known linguistic patterns of modifiers (e.g., negation, intensification)?
Key findings
- RNNs trained on sentiment classification learn to store sentiment predictions along a 1D line attractor in hidden state space, with valence words driving state along this manifold.
- The RNN’s performance drops by approximately 4% on shuffled inputs, indicating that contextual phrase structure (e.g., 'not bad', 'extremely awesome') contributes significantly beyond simple word valence.
- The method successfully identifies and quantifies contextual modifiers, including negators and intensifiers, with effects lasting up to a few words and exhibiting asymmetric strength (e.g., negators stronger than intensifiers).
- A simple convolutional baseline model enhanced with BOD/EOD tokens and modifier-specific weights (β_mod) achieves 95.63% accuracy on Yelp, recovering 90% of the performance gain from the best RNN (GRU: 95.84%).
- The RNN’s contextual dynamics closely mirror known linguistic properties: negation acts additively rather than multiplicatively, and modifier scope is limited to a few words.
- The reverse-engineered model of contextual processing explains over 90% of the performance gain of nonlinear RNNs over standard Bag-of-Words baselines, demonstrating the power of interpretable feature engineering guided by RNN analysis.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.