Predict sentences using the pretrained DeepOpinion ABSA model

In this tutorial, we show how you can use an already pre-trained model from DeepOpinion to predict sentences within the hotel domain. No training is required as an already pre-trained model is automatically downloaded from the DeepOpinion database. Since no training is involved, this example can easily be executed locally on your CPU. Please note that we assume that you installed all dependencies (see the Installation section of the documentation:

Include libs

The first step is to include all necessary libs.

import autonlu
from autonlu import Model, list_models
from pprint import pprint
User name/Email: admin
Password: ········

Load model

We successfully imported the AutoNLU. So our next step is to check which pre-trained models are available:

pretrained_models = list_models()
print(f"{len(pretrained_models)} pretrained models are availabe!\n")
34 pretrained models are availabe!


Wow, 34 different models with different tasks are available! In this tutorial we are interested to predict sentences within the hotel’s domain, therefore we use the hotels_absa_en model.

model = Model("DeepOpinion/hotels_absa_en")

Check what device the model was loaded to. (cpu or cuda if it will run on the GPU)

print("Model is running on the", "CPU" if model.device == "cpu" else "GPU")
Model is running on the GPU


Finally, we want to use this model to predict some sentences. Simply specify an array, or load your sentences from a file and feed the information into your model.

# Show results
X = ["The room was very clean.",
     "The food was good, but the guys at the reception were bad."]
res = model.predict(X)

for i, sentence in enumerate(X):
    for pred in res[i]:
        print(f"  {pred[0]}: {pred[1]}")

The room was very clean.
  Cleanliness: POS
  Room: POS

The food was good, but the guys at the reception were bad.
  Food: POS
  Reception: NEG
  Staff: NEG

That’s it - quite easy to predict with AutoNLU right? In the next tutorial, we will show how you can easily train your own model using your own dataset :)