Skip to content


Switch branches/tags


Failed to load latest commit information.
Latest commit message
Commit time
Jul 28, 2018
Dec 30, 2018

Aspect extraction from product reviews with Tensorflow

This repo has multiple sequential models for aspect extraction from product reviews.


If the code is useful in your research, please cite the following paper:

Poria, S., Cambria, E. and Gelbukh, A., 2016. Aspect extraction for opinion mining with a deep convolutional neural network. Knowledge-Based Systems, 108, pp.42-49.


Given a sentence, the task is to extract aspects. Here is an example

I like the battery life of this phone"

Converting this sentence to IOB would look like this -

like O
the O
battery B-A
life I-A
of O
this O
phone O


Similar to Ma and Hovy.

  • concatenate final states of a bi-lstm on character embeddings to get a character-based representation of each word
  • concatenate this representation to a standard word vector representation (GloVe here)
  • run a bi-lstm on each sentence to extract contextual representation of each word
  • decode with a linear chain CRF

Similar to [Collobert et al.] (

  • form a window around the word to tag
  • apply MLP on that window
  • obtain logits
  • apply viterbi (CRF) for sequence tagging

Similar to Poria et al.

  • form a window around the word to tag
  • apply CNN on that window
  • apply maxpool on that window (Caution: different from global maxpool)
  • obtain logits
  • apply CRF for sequence tagging




Download Glove embeddings (GloVe: )

  1. [DO NOT MISS THIS STEP] Build vocab from the data and extract trimmed glove vectors according to the config in model/
  1. Train the model with
  1. Evaluate and interact with the model with

Data iterators and utils are in model/ and the model with training/test procedures is in model/

Training Data

The training data must be in the following format (identical to the CoNLL2003 dataset).

A default test file is provided to help you getting started.

The	O
duck	B-A
confit	I-A
is	O
always	O
amazing	O
and	O
the	O
foie	B-A
gras	I-A
terrine	I-A
with	I-A
figs	I-A
was	O
out	O
of	O
this	O
world	O

The	O
wine	B-A
list	I-A
is	O
interesting	O
and	O
has	O
many	O
good	O
values	O

Once you have produced your data files, change the parameters in like

# dataset
filename_train = "data/ABSA16_Restaurants_Train_SB1_v2_mod.iob"
filename_dev = "data/EN_REST_SB1_TEST_2016_mod.iob"
filename_test = "data/EN_REST_SB1_TEST_2016_mod.iob"


Chunk based evaluation

Laptop 2014 -> F1 - 79.93

Restaurant 2014 -> F1 - 84.22

Partial matching based evaluation

Laptop 2014 -> F1 - 86.84
Restaurant 2014 -> F1 - 88.42


This project is licensed under the terms of the apache 2.0 license (as Tensorflow and derivatives). If used for research, citation would be appreciated.