/ Модель

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

Контекст
2 048 токенов
Параметры
6,6 млрд
Размер весов
13,5 ГБ
Лицензия
Llama 2
Архитектура
llama · dense
Опубликована
7 дек 2023

LlamaGuard-7b

Генерация текстаТекст → текст3 профессии

LlamaGuard-7b классифицирует текстовые запросы и ответы LLM как безопасные или небезопасные и указывает категории нарушений.

334скачиваний за 30 дней14лайковвеса обновлены7 дек 2023

Бенчмарки

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

Тесты пользователейпока нет

Никто ещё не опубликовал тест этой модели. Соберите бенчмарк из своих задач — результат появится здесь.

  1. Добавьте модель в бенчмарк

    Вместе с другими моделями категории «Текст» — сравнение идёт внутри одной категории.

  2. Опишите свои задачи

    Напишите запросы, при необходимости приложите файлы и эталонные ответы.

  3. Запустите и опубликуйте

    Модели ответят на каждую задачу, судья оценит ответы. Опубликованный результат появится на этой странице.

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

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

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

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

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

LlamaGuard-7b — модель-классификатор безопасности на основе Llama 2, опубликованная в репозитории llamas-community. Она проверяет текстовые запросы к языковым моделям и их ответы, генерируя текстовую метку safe или unsafe и, при обнаружении нарушения, указывая соответствующие категории риска. Для получения оценки вероятности небезопасного класса используют вероятность первого токена и применяют выбранный порог.

Модель предназначена для модерации содержимого LLM в реальном времени и поддерживает таксономию, включающую насилие и ненависть, сексуальный контент, незаконное оружие, контролируемые вещества, самоубийство и самоповреждение, а также планирование преступлений. Архитектура — плотная авторегрессионная LlamaForCausalLM; размер — около 6,6 млрд параметров, контекст — 2048 токенов. Указана поддержка английского языка. Веса доступны в safetensors, а карточка также описывает варианты формата Llama и Hugging Face Transformers.

В карточке приведены результаты оценки на наборах для классификации запросов и ответов; результаты зависят от таксономии и не полностью сопоставимы с другими системами модерации. Модель может ошибаться и требует выбора порога под задачу и политику модерации. Лицензия — Llama 2 Community License.

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

  • проверка пользовательских запросов перед передачей их языковой модели
  • модерация ответов чат-бота перед показом пользователю
  • выявление насилия и языка ненависти в текстах
  • обнаружение сексуального контента и опасных инструкций
  • оценка вероятности небезопасного текста с заданным порогом

Ограничения

Модель опирается на заданную таксономию рисков, а её решения зависят от выбранного порога; результаты оценки не полностью сопоставимы с другими системами из-за различий в таксономиях. Контекст ограничен 2048 токенами.

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

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

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

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

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

Открыть на Hugging Face

Model Details

This repository contains the model weights both in the vanilla Llama format and the Hugging Face transformers format

Llama-Guard is a 7B parameter Llama 2-based input-output safeguard model. It can be used for classifying content in both LLM inputs (prompt classification) and in LLM responses (response classification). It acts as an LLM: it generates text in its output that indicates whether a given prompt or response is safe/unsafe, and if unsafe based on a policy, it also lists the violating subcategories. Here is an example:

In order to produce classifier scores, we look at the probability for the first token, and turn that into an “unsafe” class probability. Model users can then make binary decisions by applying a desired threshold to the probability scores.

Training and Evaluation

Training Data

We use a mix of prompts that come from the Anthropic dataset and redteaming examples that we have collected in house, in a separate process from our production redteaming. In particular, we took the prompts only from the Anthropic dataset, and generated new responses from our in-house LLaMA models, using jailbreaking techniques to elicit violating responses. We then annotated Anthropic data (prompts & responses) in house, mapping labels according to the categories identified above. Overall we have ~13K training examples.

Taxonomy of harms and Risk Guidelines

As automated content risk mitigation relies on classifiers to make decisions about content in real time, a prerequisite to building these systems is to have the following components:

  • A taxonomy of risks that are of interest – these become the classes of a classifier.
  • A risk guideline that determines where we put the line between encouraged and discouraged outputs for each risk category in the taxonomy. Together with this model, we release an open taxonomy inspired by existing open taxonomies such as those employed by Google, Microsoft and OpenAI in the hope that it can be useful to the community. This taxonomy does not necessarily reflect Meta's own internal policies and is meant to demonstrate the value of our method to tune LLMs into classifiers that show high performance and high degrees of adaptability to different policies.

The Llama-Guard Safety Taxonomy & Risk Guidelines

Below, we provide both the harm types themselves under this taxonomy and also examples of the specific kinds of content that would be considered harmful under each category:

  • Violence & Hate encompasses statements that encourage or could help people plan or engage in violence. Similarly, statements that advocate discrimination, contain slurs, or voice hateful sentiments against people based on their sensitive personal characteristics (ex: race, color, religion, national origin, sexual orientation, gender, gender identity, or disability) would also be considered inappropriate under this category.
  • Sexual Content encompasses statements encouraging someone (who could be underage) to engage in specific sex acts. Similarly, sexually explicit (i.e., erotic) statements would also be considered inappropriate under this category.
  • Guns & Illegal Weapons encompasses statements that specifically encourage, condone, or could help people plan or execute specific crimes involving the illegal acquisition, creation, or use of guns or illegal weapons (ex: explosives, biological agents, or chemical weapons), including instructions on how to create or use them.
  • Regulated or Controlled Substances encompasses statements that specifically encourage or could help people to illegally produce, transfer, or consume regulated or controlled substances like illegal drugs, tobacco, alcohol, or cannabis.
  • Suicide & Self Harm encompasses statements that encourage, condone, or enable people to harm themselves (ex: by providing instructions or information on methods of self-harm). When people express or imply an intent to harm themselves, any response other than one that provides links to appropriate health resources would be considered inappropriate (even if entirely supportive).
  • Criminal Planning encompasses miscellaneous statements that encourage, condone, or could help people plan or execute specific criminal activities, like arson, kidnapping, or theft. Items should only be considered harmful under this category when they could not be read as violating any of the other harm types above (ex: statements that encourage violence should be considered violating under Violence & Hate rather than this category).

How to Use in transformers

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "meta-llama/LlamaGuard-7b"
device = "cuda"
dtype = torch.bfloat16

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=dtype, device_map=device)

def moderate(chat):
    input_ids = tokenizer.apply_chat_template(chat, return_tensors="pt").to(device)
    output = model.generate(input_ids=input_ids, max_new_tokens=100, pad_token_id=0)
    prompt_len = input_ids.shape[-1]
    return tokenizer.decode(output[0][prompt_len:], skip_special_tokens=True)

moderate([
    {"role": "user", "content": "I forgot how to kill a process in Linux, can you help?"},
    {"role": "assistant", "content": "Sure! To kill a process in Linux, you can use the kill command followed by the process ID (PID) of the process you want to terminate."},
])
# `safe`

You need to be logged in to the Hugging Face Hub to use the model.

For more details, see this Colab notebook.

Evaluation results

We compare the performance of the model against standard content moderation APIs in the industry, including OpenAI, Azure Content Safety,and PerspectiveAPI from Google on both public and in-house benchmarks. The public benchmarks include ToxicChat and OpenAI Moderation.

Note: comparisons are not exactly apples-to-apples due to mismatches in each taxonomy. The interested reader can find a more detailed discussion about this in our paper: [LINK TO PAPER].

Our Test Set (Prompt)OpenAI ModToxicChatOur Test Set (Response)
Llama-Guard0.9450.8470.6260.953
OpenAI API0.7640.8560.5880.769
Perspective API0.7280.7870.5320.699

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

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

GPU в ailist

Универсальный рантайм

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

Подбираем GPU…

Класс архитектуры
LlamaForCausalLM
Ревизия весов
6efebd6

0 моделей