rubert base cased sentiment rusentiment
简介
核心亮点
- 专为俄语优化,情感识别精准度高
- 基于 RuBERT 架构,语义理解能力强
- 适配 RuSentiment 数据集,覆盖多种语境
- Apache-2.0 协议,商业集成无压力
- 通过 Transformers 库即可快速部署
使用方法
# 安装 Hugging Face transformers
pip install transformers torch
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("blanchefort/rubert-base-cased-sentiment-rusentiment")
tokenizer = AutoTokenizer.from_pretrained("blanchefort/rubert-base-cased-sentiment-rusentiment")
Hugging Face 下载
我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。
操作指引:在下载前,请先通过如下命令安装 huggingface_hub:
pip install -U huggingface_hub
命令行下载
下载完整模型库
huggingface-cli download blanchefort/rubert-base-cased-sentiment-rusentiment
下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download blanchefort/rubert-base-cased-sentiment-rusentiment config.json --local-dir ./dir
SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('blanchefort/rubert-base-cased-sentiment-rusentiment')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://huggingface.co/blanchefort/rubert-base-cased-sentiment-rusentiment
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/blanchefort/rubert-base-cased-sentiment-rusentiment
模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。
PyTorch / Transformers 使用
安装 Transformers
pip install -U transformers torch
模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment')
tokenizer = AutoTokenizer.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment')
完整文档
---
language:
- ru
tags:
- sentiment
- text-classification
datasets:
- RuSentiment
---
RuBERT for Sentiment Analysis
This is a DeepPavlov/rubert-base-cased-conversational model trained on RuSentiment.
Labels
0: NEUTRAL 1: POSITIVE 2: NEGATIVEHow to use
import torch
from transformers import AutoModelForSequenceClassification
from transformers import BertTokenizerFast
tokenizer = BertTokenizerFast.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment')
model = AutoModelForSequenceClassification.from_pretrained('blanchefort/rubert-base-cased-sentiment-rusentiment', return_dict=True)
@torch.no_grad()
def predict(text):
inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
outputs = model(inputs)
predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
predicted = torch.argmax(predicted, dim=1).numpy()
return predicted
Dataset used for model training
> 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.