# 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: https://autonlu.com/installation.html).

## Include libs¶

The first step is to include all necessary libs.

[1]:

import autonlu
from autonlu import Model, list_models
from pprint import pprint

[2]:

autonlu.login()

User name/Email: admin


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

[3]:

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

34 pretrained models are availabe!

'DeepOpinion/insurance_base_en',
'DeepOpinion/telco_base_en',
'DeepOpinion/utility_base_en',
'DeepOpinion/banking_base_en',
'DeepOpinion/base_xx',
'DeepOpinion/base_de',
'DeepOpinion/automotive_base_en',
'DeepOpinion/household-electronics_base_de',
'DeepOpinion/consumer-electronics_base_en',
'DeepOpinion/consumer-packaged-goods_base_en',
'DeepOpinion/hotels_base_de',
'DeepOpinion/employee-experience_base_en',
'DeepOpinion/sights_base_en',
'DeepOpinion/household-electronics_base_en',
'DeepOpinion/hotels_base_en',
'DeepOpinion/household-electronics_absa_de',
'DeepOpinion/utility_absa_en',
'DeepOpinion/telco_absa_en',
'DeepOpinion/banking_absa_en',
'DeepOpinion/insurance_absa_en',
'DeepOpinion/base_en',
'DeepOpinion/vacuum-cleaners_absa_en',
'DeepOpinion/sights-activities_absa_en',
'DeepOpinion/alpine-hotels_absa_en',
'DeepOpinion/alpine-hotels_absa_de',
'DeepOpinion/hotels_absa_en',
'DeepOpinion/employee-experience_absa_en',
'DeepOpinion/automotive_absa_en',
'DeepOpinion/conversational-demo_absa_en',
'DeepOpinion/household-electronics_absa_en',
'DeepOpinion/laptops_absa_en',
'DeepOpinion/consumer-electronics_absa_en',
'DeepOpinion/consumer-packaged-goods_absa_en']


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.

[4]:

model = Model("DeepOpinion/hotels_absa_en")


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

[5]:

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

Model is running on the GPU


## Predict¶

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.

[6]:

# 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):
print(f"\n{sentence}")
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 :)