log.moon

ABSA Pipeline

Python

NLP

Deep Learning

BERT

HuggingFace


Links

  • Github (Source Code)
  • ASE Model
  • ABSA Model


  • Project Description

    A two-stage NLP pipeline that identifies what aspects are discussed in a review and determines how the author feels about each one.

    Why

    For a deep learning class, we had a group project to build a smart ecommerce shop that uses AI to drive a better experience for users. My task was to handle product reviews; take em, and get a sentiment score out.

    This sounded generic to me, even though I had never really done anything like this, I was familiar with the approach, get a pre-trained encoder model like bert, fine-tune it if needed and run it for each review, get a sentiment score and average all of em.

    But as I said that felt too simple and I wasn't going to learn much doing that. So I looked at other ways this could be done and found out about Aspect-Based Sentiment Analysis. Instead of just asking "is this review positive or negative?", ABSA asks "what is the reviewer talking about, and how do they feel about each thing specifically?". I liked the approach a lot more, so I went for it.

    How It Works

    It's a two stage pipeline, each stage is its own fine-tuned bert-base-uncased model.

    Both models were fine-tuned on the MAMS dataset with extra training examples pulled from SemEval-2014 Task 4 (laptops + restaurants).

    Stage 1 — Aspect Span Extraction

    The first model is a token classifier. It reads the review and tags every single token with one of three labels: B-ASP for the beginning of an aspect term, I-ASP for the continuation of one, and O for everything else. This is called the BIO scheme. Contiguous B and I tokens get merged into a single aspect term, so something like ["battery", "life"] becomes "battery life".

    Stage 2 — Sentiment Classification

    The second model takes each extracted aspect and classifies the sentiment toward it, and the trick here is rather than feeding just the review, you feed it as a sentence pair: [CLS] review text [SEP] aspect term [SEP]. This lets the model attend to the review in the context of a specific aspect.