/ Модель

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

Контекст
16 384 токена
Параметры
14,1 млрд
Размер весов
29,3 ГБ
Лицензия
Apache 2.0
Архитектура
llama · dense
Базовая модель
phi-4-bnb-4bit
Опубликована
16 фев 2025

phi4-r1-guard

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

Дообученная языковая модель для выявления токсичности, проверки галлюцинаций и оценки релевантности контекста RAG.

17скачиваний за 30 дней5лайковвеса обновлены4 мар 2025

Бенчмарки

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

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

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

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

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

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

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

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

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

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

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

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

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

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

grounded-ai/phi4-r1-guard — языковая модель, разработанная Jlonge4 и дообученная на unsloth/phi-4-bnb-4bit с использованием Unsloth и TRL. Она предназначена для оценки текстов: выявляет токсичность, проверяет ответы на галлюцинации по эталонному материалу и оценивает релевантность найденного контекста запросу в RAG-сценариях.

Модель имеет 14,1 млрд параметров, архитектуру LlamaForCausalLM и контекстное окно 16 384 токена. Принимает текст и выдаёт объяснение решения с бинарной классификацией: toxic/non-toxic, yes/no или relevant/unrelated. В карточке заявлена поддержка английского языка.

Модель выпущена под лицензией Apache-2.0. Её оценки и объяснения могут ошибаться; проверки галлюцинаций зависят от качества эталонного материала, а классификацию следует валидировать на данных целевого применения.

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

  • проверка пользовательских сообщений на токсичность
  • выявление оскорблений и языка ненависти
  • сверка ответа ИИ с эталонным материалом для поиска галлюцинаций
  • оценка релевантности найденных документов запросу в RAG
  • получение объяснения к бинарной оценке текстового ответа

Ограничения

Выводы модели могут быть ошибочными, а обнаружение галлюцинаций зависит от качества предоставленного эталонного материала. Для целевого применения точность классификации следует проверять на собственных данных.

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

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

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

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

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

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

Открыть на Hugging Face

Reasoning Model for Content Evaluation

  • Developed by: Jlonge4
  • License: apache-2.0
  • Finetuned from model: unsloth/phi-4-bnb-4bit

This Llama model was trained 2x faster with Unsloth and Huggingface's TRL library. It specializes in three key reasoning tasks:

  1. Toxicity Detection: Evaluates whether text content contains toxic elements such as hate speech, harassment, or inappropriate language.
  2. Hallucination Detection: Determines if an AI model's response contains factual inaccuracies or fabricated information when compared to a reference.
  3. RAG Relevance Assessment: Analyzes whether retrieved context is relevant to answering a specific query.

Model Capabilities

The model provides structured reasoning and binary classification for each task:

  • Toxicity: toxic vs non-toxic
  • Hallucination: yes vs no
  • RAG Relevance: relevant vs unrelated

All outputs follow a consistent format:

<reasoning>
Detailed explanation of the decision
</reasoning>
<answer>
Classification result
</answer>

Functions:

Toxicity

def toxic_format_func(text):
  system = """Your job is to evaluate whether a human text is toxic or non-toxic.
  Respond in the following format:
  <reasoning>
  ...
  </reasoning>
  <answer>
  ...
  </answer>
  """
  prompt = f"""You are examining written text content. Here is the text:
  <info>
  [Text]: {text}
  </info>
  Examine the text and determine whether the text is toxic or not. Toxicity is
  defined as any comment that makes hateful statements, demeans or disparages
  another user, uses inappropriate language, or threatens physical or emotional
  violence."""
  return system, prompt

Hallucinations

def halu_format_func(reference, query, response):
  system = """Your job is to evaluate whether a machine learning model has hallucinated or not. A hallucination occurs when the response is coherent but factually incorrect or nonsensical outputs that are not grounded in the provided context.
  Respond in the following format:
  <reasoning>
  ...
  </reasoning>
  <answer>
  ...
  </answer>
  """
  prompt = f"""You are given the following information:
  <info>
  [Knowledge]: {reference}
  [User Input]: {query}
  [Model Response]: {response}
  </info>
  Based on the information provided is the model output a hallucination?"""
  return system, prompt

Rag Relevance

def rag_format_func(reference, query):
  system = """Your job is to evaluate whether a retrieved context is relevant, or unrelated to a user query.
  Respond in the following format:
  <reasoning>
  ...
  </reasoning>
  <answer>
  ...
  </answer>
  """
  prompt = f"""You are comparing a reference text to a question and trying to determine if the reference text
  contains information relevant to answering the question. Here is the info:
  <info>
  [Question]: {query}
  [Reference text]: {reference}
  </info>
  Compare the Question above to the Reference text. Your response must be single word,
  either "relevant" or "unrelated"."""
  return system, prompt

Usage:

from vllm import LLM, SamplingParams

# Configure sampling parameters
sampling_params = SamplingParams(
    temperature=0.5,
    top_p=0.5,
    max_tokens=1024,
)

# Initialize the LLM
llm = LLM(
    model="grounded-ai/phi4-r1-guard",
    max_num_seqs=5,
    max_model_len=2048,
    tensor_parallel_size=1,
    gpu_memory_utilization=0.9,
)

Toxicity Detection Example:

from transformers import AutoTokenizer

def run_inference(system, prompt):
  tokenizer = AutoTokenizer.from_pretrained("grounded-ai/phi4-r1-guard")

  # Define prompts
  text = tokenizer.apply_chat_template([
      {"role" : "system", "content" : system},
      {"role" : "user", "content" : prompt},
    ], tokenize = False, add_generation_prompt = True)

  prompts = [
      text
  ]
  # Generate responses
  outputs = llm.generate(prompts, sampling_params)

  # Print results
  for output in outputs:
      prompt = output.prompt
      generated_text = output.outputs[0].text
      print(f"Prompt: {prompt}")
      print('------------------'*40)
      print(f"Generated text: {generated_text}\n")

  return generated_text

text_to_evaluate = "This is some text to evaluate"
system, prompt = toxic_format_func(text_to_evaluate)
run_inference(system, prompt)

Hallucination Detection Example:

reference = "The Eiffel Tower was completed in 1889."
query = "When was the Eiffel Tower built?"
response = "The Eiffel Tower was completed in 1925."
system, prompt = halu_format_func(reference, query, response)
run_inference(system, prompt)

RAG Relevance Example:

reference = "The process of photosynthesis in plants..."
query = "How does photosynthesis work?"
system, prompt = rag_format_func(reference, query)
run_inference(system, prompt)

Sample Output:

HALLUCINATION - YES CASE:
System: Your job is to evaluate whether a machine learning model has hallucinated or not. A hallucination occurs when the response is coherent but factually incorrect or nonsensical outputs that are not grounded in the provided context.

Respond in the following format:
<reasoning>
...
</reasoning>
<answer>
...
</answer>

Prompt: You are given the following information:
        <info>
        [Knowledge]: The Eiffel Tower was completed in 1889 and stands 324 meters tall. It was built for the World's Fair in Paris.
        [User Input]: When was the Eiffel Tower built and how tall is it?
        [Model Response]: The Eiffel Tower was completed in 1925 and stands 450 meters tall. It was built to celebrate France's victory in World War I.
        </info>
        Based on the information provided is the model output a hallucination?
        
##############################################################################
Result: <reasoning>
The model's response contains several factual inaccuracies when compared to the provided knowledge. According to the information given, the Eiffel Tower was completed in 1889, not 1925, and it stands 324 meters tall, not 450 meters. Additionally, the Eiffel Tower was built for the World's Fair in Paris, not to celebrate France's victory in World War I. These discrepancies indicate that the model's response is not grounded in the provided context and includes factually incorrect information. Therefore, the model's output can be classified as a hallucination.
</reasoning>
<answer>
Yes, the model output is a hallucination.
</answer>

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

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

GPU в ailist

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

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

Подбираем GPU…

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

0 моделей