<jupyter_start><jupyter_text>Setup<jupyter_code>!pip install git+https://github.com/hafidhrendyanto/gpt2-absa.git<jupyter_output>Collecting git+https://github.com/hafidhrendyanto/gpt2-absa.git
  Cloning https://github.com/hafidhrendyanto/gpt2-absa.git to /tmp/pip-req-build-duqzyf6v
  Running command git clone -q https://github.com/hafidhrendyanto/gpt2-absa.git /tmp/pip-req-build-duqzyf6v
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from gpt2absa==0.1.0) (1.19.5)
Requirement already satisfied: tensorflow in /usr/local/lib/python3.7/dist-packages (from gpt2absa==0.1.0) (2.7.0)
Collecting transformers
  Downloading transformers-4.12.5-py3-none-any.whl (3.1 MB)
[K     |████████████████████████████████| 3.1 MB 7.1 MB/s 
[?25hRequirement already satisfied: ipywidgets in /usr/local/lib/python3.7/dist-packages (from gpt2absa==0.1.0) (7.6.5)
Requirement already satisfied: widgetsnbextension~=3.5.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets->gpt2absa==0.1.0) (3.5.2)
Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.7/dist-packages (from ipywidget[...]<jupyter_text>Code Sample<jupyter_code>from gpt2absa.constant import restaurant_aspect_categories, laptop_aspect_categories
from gpt2absa import aspect_polarity_pair
from transformers import TFAutoModelWithLMHead
model = TFAutoModelWithLMHead.from_pretrained("hafidhrendyanto/gpt2-absa")<jupyter_output>/usr/local/lib/python3.7/dist-packages/transformers/models/auto/modeling_tf_auto.py:429: FutureWarning: The class `TFAutoModelWithLMHead` is deprecated and will be removed in a future version. Please use `TFAutoModelForCausalLM` for causal language models, `TFAutoModelForMaskedLM` for masked language models and `TFAutoModelForSeq2SeqLM` for encoder-decoder models.
  FutureWarning,<jupyter_text>Restaurant domainAspect Based Sentiment Analysis (ABSA) can be devided into many sub-task. Two of which are *sentiment polarity classification* and *aspect category detection*. The samples for restaurant and laptop dommain solve both sub-task while the sample for hotel domain only solve the former (*sentiment polarity classification*).<jupyter_code>aspect_polarity_pair(model, "Excellent food, although the interior could use some help.", restaurant_aspect_categories)
aspect_polarity_pair(model, "Price is high but the food is good, so I would come back again.", restaurant_aspect_categories)
aspect_polarity_pair(model, "You can order your drinks however you like, and the bartender is very helpfull", restaurant_aspect_categories)
aspect_polarity_pair(model, "I come here at noon", restaurant_aspect_categories)<jupyter_output><empty_output><jupyter_text>Laptop domainYou can influence the amount of the selected aspect by changing the `treshold` argument of the function. Because there is more aspect candidate in the laptop domain, the optimal value for this argument is `0.35`<jupyter_code>aspect_polarity_pair(model, "Looks good, well built, and very good speed.", laptop_aspect_categories)
aspect_polarity_pair(model, "Looks good, well built, and very good speed.", laptop_aspect_categories, treshold=0.35)
aspect_polarity_pair(model, "This is the first laptop I've owned, althougth I used several at my previous job.", laptop_aspect_categories, treshold=0.35)
aspect_polarity_pair(model, "Save your money and get an android: works better, more support", laptop_aspect_categories, treshold=0.35)
aspect_polarity_pair(model, "Very fast and reliable, but the design is rather weird", laptop_aspect_categories, treshold=0.35)<jupyter_output><empty_output><jupyter_text>Hotel domainThe model is only fine-tuned using SemEval 2016 Task 5 Restaurant and Laptop domain. The samples for hotel domain below shows the solutions cross domain generalization capabilities **for sentiment classification task**. You can use this solution on many other domain by defining the aspect categories that you want to evaluate on that domain.Its must be noted that this domain generalization capability only applies to *sentiment polarity classification*. Currently, the *aspect category detection* module for this solution don't have that capability/features.<jupyter_code>from gpt2absa import sentiment_polarity_classification
aspect_categories = ['hotel#room', 'hotel#view', 'hotel#staff', 'hotel#price', 'hotel#general']
text = "The room in this hotel is very beautiful, the view is impeccable but the price is so high and the staff can be grumpy sometimes."
sentiment_polarity_classification(model, text, aspect_categories)
text = "This is the best hotel I've been, all around great!"
sentiment_polarity_classification(model, text, aspect_categories)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09199065222009772, 'fraction_numerical': 0.01997025706394731, 'mean_word_length': 6.680261011419249, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '12053', 'license': 'MIT', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1439, 'n_words': 443, 'path': 'sample.ipynb', 'repo_name': 'hafidhrendyanto/gpt2-absa', 'size': '4707'}