/ Модель

Характеристики

Контекст
514 токенов
Параметры
305 млн
Лицензия
MIT
Архитектура
xlm-roberta · dense
Опубликована
14 авг 2023

zero-shot-classify-SSTuning-XLM-R

Классификация текстаТекст → label9 профессий

Многоязычная модель XLM-RoBERTa для классификации текста по заданным меткам без дополнительного дообучения.

58скачиваний за 30 дней10лайковвеса обновлены19 ноя 2023

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

DAMO-NLP-SG разработала zero-shot-модель классификации текста на основе XLM-RoBERTa. Модель дообучена методом SSTuning: на неразмеченных англоязычных данных она учится предсказывать индекс метки с помощью задачи First Sentence Prediction. В архитектуре XLMRobertaForSequenceClassification около 305,2 млн параметров; модель принимает текст и названия классов и выдаёт оценки классов. Контекст составляет до 514 токенов.

Модель предназначена для классификации без дополнительного дообучения, например для анализа тональности и определения тематики. В README указано, что она обучалась на 20,48 млн примеров на английском языке, но может применяться и на других языках, поддерживаемых XLM-RoBERTa. Рекомендуемое число меток — от 2 до 20. Распространяется по лицензии MIT.

Сценарии применения

  • определение тональности отзывов
  • классификация текста по темам
  • распределение обращений по категориям
  • отнесение новостей к заданным классам

Ограничения

Обучение проводилось только на англоязычных примерах, поэтому качество на других языках может быть ниже. README рекомендует использовать от 2 до 20 меток; контекст ограничен 514 токенами.

Для каких профессий подходит9

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Также подходит для

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

Zero-shot text classification (multilingual version) trained with self-supervised tuning

Zero-shot text classification model trained with self-supervised tuning (SSTuning). It was introduced in the paper Zero-Shot Text Classification via Self-Supervised Tuning by Chaoqun Liu, Wenxuan Zhang, Guizhen Chen, Xiaobao Wu, Anh Tuan Luu, Chip Hong Chang, Lidong Bing and first released in this repository.

The model backbone is xlm-roberta-base.

Model description

The model is tuned with unlabeled data using a first sentence prediction (FSP) learning objective. The FSP task is designed by considering both the nature of the unlabeled corpus and the input/output format of classification tasks.

The training and validation sets are constructed from the unlabeled corpus using FSP.

During tuning, BERT-like pre-trained masked language models such as RoBERTa and ALBERT are employed as the backbone, and an output layer for classification is added. The learning objective for FSP is to predict the index of the correct label. A cross-entropy loss is used for tuning the model.

Model variations

There are four versions of models released. The details are:

ModelBackbone#paramslangaccSpeed#Train
zero-shot-classify-SSTuning-baseroberta-base125MEnLowHigh20.48M
zero-shot-classify-SSTuning-largeroberta-large355MEnMediumMedium5.12M
zero-shot-classify-SSTuning-ALBERTalbert-xxlarge-v2235MEnHighLow5.12M
zero-shot-classify-SSTuning-XLM-Rxlm-roberta-base278MMulti--20.48M

Please note that zero-shot-classify-SSTuning-XLM-R is trained with 20.48M English samples only. However, it can also be used in other languages as long as xlm-roberta supports. Please check this repository for the performance of each model.

Intended uses & limitations

The model can be used for zero-shot text classification such as sentiment analysis and topic classification. No further finetuning is needed.

The number of labels should be 2 ~ 20.

How to use

You can try the model with the Colab Notebook.

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch, string, random

tokenizer = AutoTokenizer.from_pretrained("DAMO-NLP-SG/zero-shot-classify-SSTuning-XLM-R")
model = AutoModelForSequenceClassification.from_pretrained("DAMO-NLP-SG/zero-shot-classify-SSTuning-XLM-R")

text = "I love this place! The food is always so fresh and delicious."
list_label = ["negative", "positive"]

device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
list_ABC = [x for x in string.ascii_uppercase]

def check_text(model, text, list_label, shuffle=False): 
    list_label = [x+'.' if x[-1] != '.' else x for x in list_label]
    list_label_new = list_label + [tokenizer.pad_token]* (20 - len(list_label))
    if shuffle: 
        random.shuffle(list_label_new)
    s_option = ' '.join(['('+list_ABC[i]+') '+list_label_new[i] for i in range(len(list_label_new))])
    text = f'{s_option} {tokenizer.sep_token} {text}'

    model.to(device).eval()
    encoding = tokenizer([text],truncation=True, max_length=512,return_tensors='pt')
    item = {key: val.to(device) for key, val in encoding.items()}
    logits = model(**item).logits
    
    logits = logits if shuffle else logits[:,0:len(list_label)]
    probs = torch.nn.functional.softmax(logits, dim = -1).tolist()
    predictions = torch.argmax(logits, dim=-1).item() 
    probabilities = [round(x,5) for x in probs[0]]

    print(f'prediction:    {predictions} => ({list_ABC[predictions]}) {list_label_new[predictions]}')
    print(f'probability:   {round(probabilities[predictions]*100,2)}%')

check_text(model, text, list_label)
# prediction:    1 => (B) positive.
# probability:   99.92%

BibTeX entry and citation info

@inproceedings{acl23/SSTuning,
  author    = {Chaoqun Liu and
               Wenxuan Zhang and
               Guizhen Chen and
               Xiaobao Wu and
               Anh Tuan Luu and
               Chip Hong Chang and 
               Lidong Bing},
  title     = {Zero-Shot Text Classification via Self-Supervised Tuning},
  booktitle = {Findings of the Association for Computational Linguistics: ACL 2023},
  year      = {2023},
  url       = {https://arxiv.org/abs/2305.11442},
}

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · text-classification

Можно запустить

Подбираем GPU…

Класс архитектуры
XLMRobertaForSequenceClassification
Ревизия весов
8e8aa4d

0 моделей