bert base multilingual uncased sentiment

提供商nlptown
分类text-classification
许可证mit
下载量786.6K
星标0

简介

这是一个基于 BERT 多语言预训练模型微调而成的情感分析工具,由 nlptown 提供。它最大的特点是支持多语言识别,能够直接对多种语言的文本进行星级评分(1-5星)预测。对于中国开发者来说,它非常适合用于快速搭建多语言评论分析系统或电商反馈监控,无需为每种语言单独训练模型。由于是基于 BERT 架构,上手门槛较低,可以通过 Hugging Face 等主流框架快速调用,是处理跨语言文本情感极性分析的轻量级高效方案。

核心亮点

  • 支持多语言文本,无需翻译即可直接分析情感
  • 输出 1-5 星级细粒度评分,比正负二分类更精准
  • 基于 BERT 架构,兼容主流 NLP 框架,部署简单
  • 适用于电商评论分析、用户反馈监控等实际场景

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
tokenizer = AutoTokenizer.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download nlptown/bert-base-multilingual-uncased-sentiment

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download nlptown/bert-base-multilingual-uncased-sentiment config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('nlptown/bert-base-multilingual-uncased-sentiment')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/nlptown/bert-base-multilingual-uncased-sentiment

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/nlptown/bert-base-multilingual-uncased-sentiment

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')
tokenizer = AutoTokenizer.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')

完整文档

来源: HuggingFace

---
language:

  • en

  • nl

  • de

  • fr

  • it

  • es

license: mit
---

bert-base-multilingual-uncased-sentiment

Visit the NLP Town website for an updated version of this model, with a 40% error reduction on product reviews.

This is a bert-base-multilingual-uncased model finetuned for sentiment analysis on product reviews in six languages: English, Dutch, German, French, Spanish, and Italian. It predicts the sentiment of the review as a number of stars (between 1 and 5).

This model is intended for direct use as a sentiment analysis model for product reviews in any of the six languages above or for further finetuning on related sentiment analysis tasks.

Training data

Here is the number of product reviews we used for finetuning the model:

| Language | Number of reviews |
| -------- | ----------------- |
| English | 150k |
| Dutch | 80k |
| German | 137k |
| French | 140k |
| Italian | 72k |
| Spanish | 50k |

Accuracy

The fine-tuned model obtained the following accuracy on 5,000 held-out product reviews in each of the languages:

  • Accuracy (exact) is the exact match for the number of stars.
  • Accuracy (off-by-1) is the percentage of reviews where the number of stars the model predicts differs by a maximum of 1 from the number given by the human reviewer.

| Language | Accuracy (exact) | Accuracy (off-by-1) |
| -------- | ---------------------- | ------------------- |
| English | 67% | 95%
| Dutch | 57% | 93%
| German | 61% | 94%
| French | 59% | 94%
| Italian | 59% | 95%
| Spanish | 58% | 95%

Contact

In addition to this model, NLP Town offers custom models for many languages and NLP tasks.

If you found this model useful, you can buy us a coffee.

Feel free to contact us for questions, feedback and/or requests for similar models.