Aspect-Based Sentiment Analysis: A TensorFlow Pipeline With a Professor in the Loop
💭 Aspect-Based-Sentiment-Analysis: Transformer & Explainable ML (TensorFlow)
At a glance
- What is it?
- ScalaConsultants packages BERT-based aspect sentiment classification with an explanation layer called the professor. The README documents the pipeline stages and the BasicPatternRecognizer, but not the accuracy numbers or the training recipe.
- Who is it for?
- Adopt this package if you need per-aspect sentiment on long documents and you want a review step between the model output and the final label, and if you are prepared to fine-tune on your own data because the README states that custom models are more accurate and stable than the pretrained ones. Do not adopt it if you need a published accuracy figure, a training script, or a non-English pipeline, since none of those appear in the supplied material.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 9 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
The problem: sentiment per aspect, not per document
A single review can praise one thing and complain about another. The README's own example makes the point: "We are great fans of Slack, but we wish the subscriptions were more accessible to small startups." A document-level classifier has to pick one label for that sentence, and either choice loses information. This package classifies sentiment per aspect instead, so the same text yields a positive label for slack and a negative label for price. The README states three assumptions behind the design: the text being processed might be a full-length document, the aspects could contain several words, and the service should provide an approximate explanation of any decision made. That third assumption is what separates the project from the roughly 100 other sentiment repositories the README says exist on GitHub. The stated audience is engineers who need to reuse an open-source research project in a product, which the README frames as the gap: research code that is "hard to commercialize and reuse." The package is standalone and, per the README, can be freely extended.
The pipeline: preprocess, tokenize, encode, predict, review, postprocess
The pipeline is the interface, and the README exposes it both as a one-liner and as its constituent calls. Calling nlp(text, aspects=[...]) runs the whole chain. Underneath, the README shows the same work broken out: nlp.preprocess(text=..., aspects=...) converts the text and aspects into a task holding examples, which are pairs of a text and an aspect. Those examples are tokenized, encoded into an input batch, and passed to the model for prediction. The interesting stage is review. Instead of post-processing model outputs directly, a separate component called the professor supervises and explains the prediction, and the README states it might dismiss a model prediction if the model internal states or outputs seem suspicious. Only after review does nlp.postprocess(task, predictions) produce a completed task. The text_splitter sits before all of this: the README uses absa.sentencizer(), described as the English CNN model from SpaCy, which splits a document into single sentences so each sentence is processed independently. The README notes the trade-off directly: longer spans carry richer context, so a model has more to consider, while sentence-level splitting keeps the sentiment from going fuzzy and neutral on long inputs.
The professor and the BasicPatternRecognizer
The explanation mechanism is framed as a separate task rather than a post-hoc chart. An auxiliary model, the pattern recognizer, predicts patterns (the README defines these as weighted compositions of tokens) given the model inputs, outputs, and internal states. The README is candid about the origin of the shipped implementation: due to time constraints the authors did not initially want to research and build a trainable pattern recognizer, so they started with one derived from their own observations and prior knowledge. That is BasicPatternRecognizer, documented in aspect_based_sentiment_analysis/aux_models.py. The reasoning behind using attention at all is stated as a proxy argument: the classifier is a transformer, self-attention layers hold the most parameters, so understanding those layers is treated as a reasonable proxy for understanding the model. The README points to an accompanying article, "Do You Trust in Aspect-Based Sentiment Analysis? Testing and Explaining Model Behaviors," for the full treatment. What the README does not give is a quantitative evaluation of the explanations themselves, so how often the professor's dismissal is correct is not something a reader can check from this material.
Getting it running: absa.load, from_pretrained, and the manual Pipeline
The shortest path is three lines plus a call. import aspect_based_sentiment_analysis as absa, then nlp = absa.load(), then nlp(text, aspects=['slack', 'price']). The README says load sets up a ready-to-use pipeline and that you can pass a model name explicitly or a path to your own model. The named model in the manual example is absa/classifier-rest-0.2, loaded through absa.BertABSClassifier.from_pretrained(name) and absa.BertTokenizer.from_pretrained(name). Building the pipeline by hand takes five constructor arguments: model, tokenizer, professor, and text_splitter, where the README writes professor = absa.Professor(...) and text_splitter = absa.sentencizer(). The README defers the professor's constructor arguments to a later section that the supplied text does not contain, so the exact configuration keys for Professor are not verifiable here. Two practical notes follow from the code shown. First, the SpaCy sentencizer is a separate dependency from the TensorFlow model, so an environment that only installs the package may still need SpaCy's English CNN model. Second, the aspect strings are matched from the text you pass, so the aspect vocabulary is your responsibility, not the model's. The README recommends building a custom model on your own data, stating that predictions will be more accurate and stable, but it does not include a training script or a command for that step in the supplied material.
Where the documentation runs out
The README is a tour, not a reference. There is no accuracy table, no F1 score, no comparison against the other repositories it links to, and no dataset description. The only model name that appears is absa/classifier-rest-0.2, and the README does not say what data it was trained on or what domain "rest" covers, though the name suggests restaurant reviews. The Professor class is shown with an ellipsis in its argument list and the explanation is deferred to a section not present in the supplied text, so anyone building a pipeline by hand will need to read aspect_based_sentiment_analysis/pipelines.py and aux_models.py directly. The text_splitter is English-only by the README's own description, which makes the pipeline English-only in practice. There is also a structural limitation worth naming: the pattern recognizer is not trainable in the version described, so explanations come from heuristics over attention values rather than from a model fitted to your data. If your inputs differ from the training distribution, the professor's supervision is the least validated part of the chain. Finally, the README's request for stars as a way to "keep this project alive" is a signal about maintenance expectations, not a quality claim, and should be read as such.
The alternative: ABSExtract and the extract-then-classify split
The README itself links ABSExtract (github.com/yardstick17/AspectBasedSentimentAnalysis) among the other ABSA repositories, and the difference in approach is architectural. This project takes the aspects as input: you pass aspects=['slack', 'price'] and the pipeline classifies each one. ABSExtract, by contrast, is built around extracting aspect terms from the text as a separate step, so the pipeline is typically two models in sequence, one to find the aspect mentions and one to classify sentiment for each. That matters when you do not know in advance which aspects a document discusses, which is the common case for open-ended review streams. The cost of the extract-then-classify design is error propagation: a missed aspect never reaches the classifier, and the two models have to be trained and maintained separately. This project's design avoids that failure mode at the price of requiring the caller to supply the aspect vocabulary, which is fine for a fixed set of product attributes and awkward for free-form text. Neither design is strictly better; they fail on different inputs.
Licence, maintenance, and what an upgrade costs
The repository is Apache-2.0, which permits commercial use and modification and includes an explicit patent grant, with the usual requirements around preserving notices and stating changes. That is a permissive licence and is consistent with the README's stated goal of making research code reusable in products. This is not legal advice; check the full licence text and your own obligations. On maintenance, the supplied material gives no release history ("Recent releases: (none retrieved)"), so there is no versioned changelog to reason about. The last push is dated 2026-09-07, so the repository is not archived and has seen activity, but the absence of releases means upgrades are likely to be tracked by commit rather than by version number. Practically, the pinned model name absa/classifier-rest-0.2 is the thing most likely to move under you, since from_pretrained resolves it remotely. If you build a custom model, your own artifacts become the upgrade surface. The dependency chain is the other cost: TensorFlow plus a transformer implementation plus SpaCy plus its English CNN model is a heavy environment for what is, at call time, a text-in, labels-out function.
The judgement: who should pick this up
This package fits a specific shape of problem. You have long documents, a known and stable set of aspects, English text, and a requirement that a human can look at a prediction and see why the model reached it. In that setting the review stage is the reason to choose this over a plain classifier, because a dismissed prediction is more useful to a downstream system than a confident wrong label. The README's own advice to fine-tune on your own data should be taken literally: the pretrained absa/classifier-rest-0.2 is a starting point, and the README states custom models are more accurate and stable. If you cannot invest in that training step, or if you need aspect extraction rather than aspect classification, or if you need a published benchmark before you can justify the dependency, this is the wrong tool. The honest summary is that the pipeline and the professor are the product, and the training story is left to you.
Editorial conclusion
Adopt this package if you need per-aspect sentiment on long documents and you want a review step between the model output and the final label, and if you are prepared to fine-tune on your own data because the README states that custom models are more accurate and stable than the pretrained ones. Do not adopt it if you need a published accuracy figure, a training script, or a non-English pipeline, since none of those appear in the supplied material. Before committing, verify three things against the repository: whether absa.load() pulls a model that matches your domain, whether the Professor must be constructed explicitly when you build a Pipeline by hand, and whether the SpaCy sentencizer is already installed as a dependency or has to be added separately.
Community notes