1
---
2
language:
3
- ru
4
tags:
5
- sentiment
6
- text-classification
7
datasets:
8
- RuSentiment
9
---
10
11
# RuBERT for Sentiment Analysis
12
13
This is a [DeepPavlov/rubert-base-cased-conversational](https://huggingface.co/DeepPavlov/rubert-base-cased-conversational) model trained on [RuSentiment](http://text-machine.cs.uml.edu/projects/rusentiment/).
14
15
## Labels
16
    0: NEUTRAL
17
    1: POSITIVE
18
    2: NEGATIVE
19
20
## How to use
21
```python
22
23
import torch
24
from transformers import AutoModelForSequenceClassification
25
from transformers import BertTokenizerFast
26
27
tokenizer = BertTokenizerFast.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment')
28
model = AutoModelForSequenceClassification.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment', return_dict=True)
29
30
@torch.no_grad()
31
def predict(text):
32
    inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
33
    outputs = model(**inputs)
34
    predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
35
    predicted = torch.argmax(predicted, dim=1).numpy()
36
    return predicted
37
```
38
39
40
## Dataset used for model training
41
42
**[RuSentiment](http://text-machine.cs.uml.edu/projects/rusentiment/)**
43
44
> A. Rogers A. Romanov A. Rumshisky S. Volkova M. Gronas A. Gribov RuSentiment: An Enriched Sentiment Analysis Dataset for Social Media in Russian. Proceedings of COLING 2018.