This work is based on Grid Tagging Scheme for Aspect-oriented Fine-grained Opinion Extraction.The code from their github repository was also utilized along with their dataset.
This model requires custom code as it uses GridTaggingScheme to predict the labels on the input. For the convenience, the custom code and model architecture has been included with the model.
Example Code for inferencing
STEP 1 (Installing huggingface lib)
pip install --upgrade huggingface_hub
STEP 2 (Download the custom code and model to predict opinion target, opinion span and sentiment polarity)
from huggingface_hub import hf_hub_download
import sys
# Download the custom model code
bert_gts_pretrained = hf_hub_download(repo_id="gauneg/bert-gts-absa-triple", filename="bert_gts_pretrained.py")
post = hf_hub_download(repo_id="gauneg/bert-gts-absa-triple", filename="post.py")
sys.path.append(bert_gts_pretrained.rsplit("/", 1)[0])
sys.path.append(post.rsplit("/", 1)[0])
from bert_gts_pretrained import GTSBertBaseABSATriple
from post import DecodeAndEvaluate
from transformers import AutoTokenizer
model_id = 'gauneg/bert-gts-absa-triple'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = GTSBertBaseABSATriple.from_pretrained(model_id)
dec_and_infer = DecodeAndEvaluate(tokenizer)
test_sentence0 = """I charge it at night and skip taking the cord with me because of the good battery life ."""
test_sentence = "The Dell Inspiron 14 Plus is the most well-rounded laptop with great display and battery life that money can buy."
# prediction
print(dec_and_infer.decode_predict_string_one(test_sentence, model))
Expected output
[['display', 'well - rounded', 'positive'],
['display', 'great', 'positive'],
['battery life', 'great', 'positive']]
DETAILS
The model has been trained to use Grid Tagging Scheme (GTS) to predict Opinion Target
, Opinion Span
and Sentiment Polarity
. The grid tagging example is shown
in the following diagram:
In the above sentence there are two absa triples. Each triple is expressed in the following order:
[Aspect Term/Opinion Target, opinion span, sentiment polarity]
The model and sample code as shown in the snippet with extract opinion triplets as: [ [hot dogs, top notch, positive], [coffee, avergae, neutral] ]
Definitions (Wu et al., Findings 2020):
- Aspect Term/Opinion Target: Aspect term, also known as opinion target, is the word or phrase in a sentence representing feature or entity of products or services.
- Opinion Term : Opinion Term refers to the term in a sentence used to express attitudes or opinions explicitly.
- Sentiment Polarity: This is the sentiment expressed.
- Downloads last month
- 2
Model tree for gauneg/bert-gts-absa-triple-laptop
Base model
google-bert/bert-base-uncased