This repository contains code to run a joint topic and sentiment model on text reviews. A Gibbs sampling based inferencer is implemented for a joint topic and sentiment model. For details, see [Sentiment Analysis with Global Topics and Local Dependency] (https://www.aaai.org/ocs/index.php/AAAI/AAAI10/paper/viewFile/1913/2215).
Run the code with
$ python amazon_demo.py
This script downloads amazon reviews (from here) for 4 categories -- books, dvd, electronics, kitchen -- and runs the SentimentLDAGibbsSampler on the DVD data.
- Each topic-sentiment pair
(t,s)
has an associated latent word distributionphi(t,s)
-- words like delicious have high probability for positive sentiment for topic food, as opposed to negative sentiment for topic movies. - For each document
d
:- Sample a topic distribution
theta(d) ~ Dirichlet(alpha)
. - For each topic
t
, sample a distribution of sentimentspi(d,t) ~ Dirichlet(gamma)
. - For every word
w
ind
:- Sample a topic
t ~ theta(d)
- Sample a sentiment
s ~ pi(d,t)
- Sample a word
w ~ phi(t,s)
- Sample a topic
- Sample a topic distribution
['movi', 'like', 'dvd', 'watch', 'good', 'time', 'great', 'realli', 'love', 'think', 'want', 'know', 'thing', 'best', 'better', 'make', 'look', 'stori', 'year', 'say', 'film', 've', 'seen', 'music', 'enjoy']
['film', 'charact', 'make', 'bad', 'life', 'scene', 'play', 'actual', 'stori', 'man', 'long', 'work', 'end', 'need', 'peopl', 'director', 'act', 'perform', 'come', 'hard', 'role', 'young', 'happen', 'way', 'view']