Downloads · 30 days
4
7% of all-time downloads
bziemba/review-aspects-xlmroberta-synthetic
review-aspects-xlmroberta-synthetic is a machine learning model from bziemba. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
Model predicts aspects of 'airbnb'-like places' reviews. It returns 3 classes (positive/negative/not metioned) for 11 aspects and pos/neg for overall aspect.
Downloads · 30 days
4
7% of all-time downloads
All-time downloads
54
Public
Parameters
292M
1.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.2 GB · 98%
From the Hugging Face model README
================================================================================
ASPEKT | ACC | F1-MACRO | WYNIK
================================================================================
location | 0.8930 | 0.7557 | (Neg/None/Pos)
cleanliness | 0.9024 | 0.8588 | (Neg/None/Pos)
bed_comfort | 0.8681 | 0.7612 | (Neg/None/Pos)
size_space | 0.6978 | 0.6425 | (Neg/None/Pos)
kitchen | 0.8936 | 0.7816 | (Neg/None/Pos)
wifi | 0.9896 | 0.8144 | (Neg/None/Pos)
noise | 0.9227 | 0.8561 | (Neg/None/Pos)
safety | 0.9462 | 0.7410 | (Neg/None/Pos)
host_contact | 0.9251 | 0.8659 | (Neg/None/Pos)
value_for_money | 0.9254 | 0.7336 | (Neg/None/Pos)
food | 0.8794 | 0.5907 | (Neg/None/Pos)
--------------------------------------------------------------------------------
>>> SZCZEGÓŁY DLA location
precision recall f1-score support
Negatywny 0.37 0.64 0.47 92
Brak/OK 0.97 0.79 0.87 1301
Pozytywny 0.89 0.96 0.93 2346
accuracy 0.89 3739
macro avg 0.74 0.80 0.76 3739
weighted avg 0.91 0.89 0.90 3739
>>> SZCZEGÓŁY DLA cleanliness
precision recall f1-score support
Negatywny 0.69 0.84 0.76 302
Brak/OK 0.97 0.89 0.93 2392
Pozytywny 0.84 0.94 0.89 1045
accuracy 0.90 3739
macro avg 0.83 0.89 0.86 3739
weighted avg 0.91 0.90 0.90 3739
>>> SZCZEGÓŁY DLA bed_comfort
precision recall f1-score support
Negatywny 0.60 0.80 0.69 171
Brak/OK 0.98 0.87 0.92 3102
Pozytywny 0.54 0.88 0.67 466
accuracy 0.87 3739
macro avg 0.71 0.85 0.76 3739
weighted avg 0.91 0.87 0.88 3739
>>> SZCZEGÓŁY DLA size_space
precision recall f1-score support
Negatywny 0.47 0.83 0.60 258
Brak/OK 0.95 0.65 0.77 2801
Pozytywny 0.42 0.82 0.55 680
accuracy 0.70 3739
macro avg 0.61 0.77 0.64 3739
weighted avg 0.82 0.70 0.72 3739
>>> SZCZEGÓŁY DLA kitchen
precision recall f1-score support
Negatywny 0.62 0.83 0.71 164
Brak/OK 0.97 0.91 0.94 3109
Pozytywny 0.61 0.80 0.69 466
accuracy 0.89 3739
macro avg 0.74 0.85 0.78 3739
weighted avg 0.91 0.89 0.90 3739
>>> SZCZEGÓŁY DLA wifi
precision recall f1-score support
Negatywny 0.92 0.84 0.88 55
Brak/OK 1.00 1.00 1.00 3648
Pozytywny 0.54 0.61 0.57 36
accuracy 0.99 3739
macro avg 0.82 0.81 0.81 3739
weighted avg 0.99 0.99 0.99 3739
>>> SZCZEGÓŁY DLA noise
precision recall f1-score support
Negatywny 0.66 0.87 0.75 305
Brak/OK 0.98 0.93 0.96 2881
Pozytywny 0.84 0.89 0.86 553
accuracy 0.92 3739
macro avg 0.82 0.90 0.86 3739
weighted avg 0.93 0.92 0.93 3739
>>> SZCZEGÓŁY DLA safety
precision recall f1-score support
Negatywny 0.46 0.68 0.55 111
Brak/OK 0.98 0.96 0.97 3490
Pozytywny 0.70 0.70 0.70 138
accuracy 0.95 3739
macro avg 0.71 0.78 0.74 3739
weighted avg 0.95 0.95 0.95 3739
>>> SZCZEGÓŁY DLA host_contact
precision recall f1-score support
Negatywny 0.70 0.75 0.73 203
Brak/OK 0.95 0.90 0.92 1568
Pozytywny 0.93 0.96 0.95 1968
accuracy 0.93 3739
macro avg 0.86 0.87 0.87 3739
weighted avg 0.93 0.93 0.93 3739
>>> SZCZEGÓŁY DLA value_for_money
precision recall f1-score support
Negatywny 0.40 0.68 0.51 106
Brak/OK 0.98 0.94 0.96 3357
Pozytywny 0.67 0.80 0.73 276
accuracy 0.93 3739
macro avg 0.69 0.81 0.73 3739
weighted avg 0.94 0.93 0.93 3739
>>> SZCZEGÓŁY DLA food
precision recall f1-score support
Negatywny 0.24 0.42 0.30 19
Brak/OK 0.98 0.89 0.93 3424
Pozytywny 0.40 0.83 0.54 296
accuracy 0.88 3739
macro avg 0.54 0.71 0.59 3739
weighted avg 0.93 0.88 0.90 3739
Model predicts aspects of 'airbnb'-like places' reviews. It returns 3 classes (positive/negative/not metioned) for 11 aspects and pos/neg for overall aspect.
<!-- ## Model Details ### Model Description <!-- Provide a longer summary of what this model is. --> <!-- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated. - **Developed by:** [More Information Needed] - **Funded by [optional]:** [More Information Needed] - **Shared by [optional]:** [More Information Needed] - **Model type:** [More Information Needed] - **Language(s) (NLP):** [More Information Needed] - **License:** [More Information Needed] - **Finetuned from model [optional]:** [More Information Needed] ### Model Sources [optional] --> <!-- Provide the basic links for the model. --> <!-- - **Repository:** [More Information Needed] - **Paper [optional]:** [More Information Needed] - **Demo [optional]:** [More Information Needed] --> -->import torch
import torch.nn as nn
from dataclasses import dataclass
from typing import Dict, Optional
from transformers import XLMRobertaModel, XLMRobertaPreTrainedModel, AutoTokenizer, XLMRobertaConfig
from transformers.modeling_outputs import ModelOutput
ASPECT_COLUMNS = {
"location": "location",
"cleanliness": "cleanliness",
"bed_comfort": "bed_comfort",
"size_space": "size_space",
"kitchen": "kitchen",
"wifi": "wifi",
"noise": "noise",
"safety": "safety",
"host_contact": "host_contact",
"value_for_money": "value_for_money",
"food": "food",
}
OVERALL_COL = "overall_sentiment"
@dataclass
class MultiHeadOutput(ModelOutput):
loss: Optional[torch.FloatTensor] = None
logits: Dict[str, torch.FloatTensor] = None
class DeepClassificationHead(nn.Module):
def __init__(self, input_dim, hidden_dim, num_labels, dropout_prob=0.1):
super().__init__()
self.mlp = nn.Sequential(
nn.Linear(input_dim, hidden_dim),
nn.GELU(),
nn.Dropout(dropout_prob),
nn.Linear(hidden_dim, hidden_dim),
nn.GELU(),
nn.Dropout(dropout_prob),
nn.Linear(hidden_dim, num_labels),
)
def forward(self, x):
return self.mlp(x)
class MultiHeadXLMRoberta(XLMRobertaPreTrainedModel):
def __init__(
self,
config,
aspect_columns=None,
aspect_weights=None,
overall_weights=None,
freeze_backbone=False,
):
super().__init__(config)
self.roberta = XLMRobertaModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.aspect_columns = aspect_columns if aspect_columns is not None else ASPECT_COLUMNS
self.aspect_names = list(self.aspect_columns.keys())
head_dim = config.hidden_size
self.aspect_heads = nn.ModuleDict(
{
name: DeepClassificationHead(
config.hidden_size, head_dim, 3, config.hidden_dropout_prob
)
for name in self.aspect_names
}
)
self.overall_head = DeepClassificationHead(
config.hidden_size, head_dim, 2, config.hidden_dropout_prob
)
if aspect_weights is None:
aspect_weights = torch.ones(3, dtype=torch.float)
if overall_weights is None:
overall_weights = torch.ones(2, dtype=torch.float)
self.register_buffer("aspect_weights", aspect_weights)
self.register_buffer("overall_weights", overall_weights)
self.post_init()
if freeze_backbone:
for param in self.roberta.parameters():
param.requires_grad = False
def forward(self, input_ids=None, attention_mask=None, **kwargs):
outputs = self.roberta(input_ids, attention_mask=attention_mask)
cls_token = self.dropout(outputs.last_hidden_state[:, 0, :])
logits = {name: head(cls_token) for name, head in self.aspect_heads.items()}
logits[OVERALL_COL] = self.overall_head(cls_token)
if not self.training:
return MultiHeadOutput(loss=None, logits=logits)
total_loss = 0.0
for name in self.aspect_names:
if name in kwargs and kwargs[name] is not None:
loss_fct = nn.CrossEntropyLoss(weight=self.aspect_weights)
total_loss += loss_fct(logits[name], kwargs[name].view(-1))
if OVERALL_COL in kwargs and kwargs[OVERALL_COL] is not None:
loss_fct = nn.CrossEntropyLoss(weight=self.overall_weights)
total_loss += loss_fct(logits[OVERALL_COL], kwargs[OVERALL_COL].view(-1))
return MultiHeadOutput(loss=total_loss, logits=logits)
# config
HF_REPO_ID = "bziemba/review-aspects-xlmroberta-ium"
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(HF_REPO_ID)
config = XLMRobertaConfig.from_pretrained(HF_REPO_ID)
model = MultiHeadXLMRoberta.from_pretrained(
HF_REPO_ID,
config=config,
)
model.to(DEVICE)
model.eval()
# funkcja predykcji
@torch.no_grad()
def predict_aspects(
text: str,
max_length: int = 256,
):
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
max_length=max_length,
)
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
outputs = model(**inputs)
results = {}
for aspect, logits in outputs.logits.items():
pred = torch.argmax(logits, dim=-1).item()
if aspect == OVERALL_COL:
results[aspect] = "positive" if pred == 1 else "negative"
else:
results[aspect] = {
0: "negative",
1: "not_mentioned",
2: "positive",
}[pred]
return results
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
Use the code below to get started with the model.
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]