Instructions to use ZaandaTeika/RAGHal-large-en-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ZaandaTeika/RAGHal-large-en-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="ZaandaTeika/RAGHal-large-en-v1")# Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("ZaandaTeika/RAGHal-large-en-v1") model = AutoModelForTokenClassification.from_pretrained("ZaandaTeika/RAGHal-large-en-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
RAGHal — ModernBERT-large (en-v1)
RAGHal — детектор галлюцинаций для Retrieval-Augmented Generation (RAG).
По паре prompt (контекст + инструкция) и answer (ответ модели) возвращает
span-level список неподдержанных фрагментов и example-level флаг hallucinated.
Модель — дообученный энкодер ModernBERT-large
с token-classification головой на 2 класса (clean / hallucinated). Это не генеративная LLM
и не запускается через vLLM — инференс выполняется напрямую через transformers.
Кратко о модели
| Задача | Детекция faithfulness / attribution в RAG-ответах |
| Гранулярность | Span-level + example-level |
| Макс. контекст | 8192 токена (лимит архитектуры ModernBERT) |
| Язык | Английский |
| Типы задач | QA, суммаризация документов, data-to-text |
| Разметка обучения | Автоматическая (LLM-teacher + critic + опционально NLI) |
| Разметка оценки | Экспертная (ручные span-метки на тесте) |
Что детектирует модель
RAGHal проверяет соответствие ответа источнику, а не фактическую истинность утверждений в открытом мире.
Спан считается галлюцинацией, если текст ответа:
- Не поддерживается — не следует из контекста / пассажей / полей JSON
- Противоречит источнику
- Добавляет лишнее — содержит детали, отсутствующие в источнике (выдуманные номера телефонов, неверные даты и т.п.)
Модель не оценивает, истинно ли утверждение в целом — только следует ли оно из предоставленного входа.
Формат входа
Модель принимает пару (prompt, answer), токенизированную как два сегмента:
[CLS] prompt_tokens [SEP] answer_tokens [SEP]
Предсказания выдаются только для токенов answer; токены prompt/контекста маскируются
при инференсе (label = -100).
QA
Шаблон промпта:
Briefly answer the following question:
{question}
Bear in mind that your response should be strictly based on the following {N} passages:
passage 1:{passage_1}
passage 2:{passage_2}
...
In case the passages do not contain the necessary information to answer the question, please reply with: "Unable to answer based on given passages."
output:
answer — сгенерированный LLM ответ (без строки output: в конце).
Суммаризация
Summarize the following news within {word_limit} words:
{source_document}
Data-to-text
Instruction:
Write an objective overview about the following local business based only on the provided structured data in the JSON format. You should include details and cover the information mentioned in the customers' review. The overview should be 100 - 200 words. Don't make up information. Structured data:
{json_blob}
Совет: для лучшего качества используйте промпты, максимально близкие к тем, на которых обучалась модель (QA / Summary / Data2txt).
Формат выхода
Span-level
Список галлюцинированных фрагментов — символьные смещения относительно строки answer:
[
{"start": 91, "end": 101, "confidence": 0.689, "text": " yesterday"}
]
| Поле | Тип | Значение |
|---|---|---|
start |
int |
Начало спана в answer (char offset) |
end |
int |
Конец спана (exclusive) |
confidence |
float |
Максимальная вероятность класса hallucinated среди токенов спана |
text |
str |
answer[start:end] |
Пустой список [] — галлюцинированных фрагментов не найдено.
Example-level
{"hallucinated": true}
| Поле | Тип | Значение |
|---|---|---|
hallucinated |
bool |
true, если span-level выход непустой; иначе false |
spans = detector.predict_prompt(prompt, answer, output_format="spans")
hallucinated = len(spans) > 0
Быстрый старт
pip install "transformers>=4.48" torch
# Класс RAGHalDetector — см. раздел «Helper для инференса» ниже
detector = RAGHalDetector("ZaandaTeika/RAGHal-large-en-v1")
prompt = """Summarize the following news within 71 words:
Blues legend B.B. King was hospitalized for dehydration, though the ailment didn't keep him out for long. King's dehydration was caused by his Type II diabetes, but he "is much better," his daughter, Claudette King, told the Los Angeles Times."""
answer = (
"B.B. King, the legendary blues musician, was hospitalized for dehydration caused by his "
"Type II diabetes. However, he has since been discharged and is now resting at home. "
"The cause of his dehydration was attributed to his busy schedule and not drinking enough water. "
"King is known for his hit songs such as \"The Thrill Is Gone\" and "
"\"There Must be a Better World Somewhere\"."
)
print(detector.predict(prompt, answer))
Выход:
{
"hallucinated": true,
"spans": [
{
"start": 175,
"end": 267,
"confidence": 0.9987218976020813,
"text": " cause of his dehydration was attributed to his busy schedule and not drinking enough water."
}
]
}
Если галлюцинаций нет:
{
"hallucinated": false,
"spans": []
}
Helper для инференса
Готовая утилита — только transformers + torch:
from __future__ import annotations
from dataclasses import dataclass, asdict
import torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
@dataclass
class SpanPrediction:
start: int
end: int
confidence: float
text: str
class RAGHalDetector:
"""Hallucination detector: span-level + example-level output."""
def __init__(
self,
model_name: str,
max_length: int = 8192,
device: str | None = None,
threshold: float = 0.5,
) -> None:
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
self.model = AutoModelForTokenClassification.from_pretrained(model_name)
self.max_length = max_length
self.threshold = threshold
self.device = torch.device(device or ("cuda" if torch.cuda.is_available() else "cpu"))
self.model.to(self.device).eval()
@torch.inference_mode()
def predict_spans(self, prompt: str, answer: str) -> list[SpanPrediction]:
encoding = self.tokenizer(
prompt,
answer,
truncation="only_first",
max_length=self.max_length,
return_offsets_mapping=True,
return_tensors="pt",
)
offsets = encoding.pop("offset_mapping")[0]
batch = {k: v.to(self.device) for k, v in encoding.items()}
logits = self.model(**batch).logits[0]
probs = torch.softmax(logits, dim=-1)
answer_token_count = self.tokenizer(
answer, add_special_tokens=False, return_tensors="pt"
)["input_ids"].shape[1]
answer_start = batch["input_ids"].shape[1] - answer_token_count - 1
answer_char_offset = offsets[answer_start][0].item()
spans: list[SpanPrediction] = []
current: SpanPrediction | None = None
for i in range(answer_start, batch["input_ids"].shape[1]):
if offsets[i][0].item() == offsets[i][1].item():
continue
rel_start = offsets[i][0].item() - answer_char_offset
rel_end = offsets[i][1].item() - answer_char_offset
p_hall = probs[i, 1].item()
is_hall = p_hall >= self.threshold
if is_hall:
if current is None:
current = SpanPrediction(rel_start, rel_end, p_hall, "")
else:
current.end = rel_end
current.confidence = max(current.confidence, p_hall)
elif current is not None:
current.text = answer[current.start : current.end]
spans.append(current)
current = None
if current is not None:
current.text = answer[current.start : current.end]
spans.append(current)
return spans
def predict(self, prompt: str, answer: str) -> dict:
spans = self.predict_spans(prompt, answer)
return {
"hallucinated": len(spans) > 0,
"spans": [asdict(s) for s in spans],
}
Примеры входа и выхода
Фактический I/O модели (max_length=8192, тестовая выборка).
spans = detector.predict_prompt(prompt, answer, output_format="spans")
hallucinated = len(spans) > 0
Пример 1 — QA
Вход — prompt:
Briefly answer the following question:
how to grill a porterhouse
Bear in mind that your response should be strictly based on the following three passages:
passage 1:1 Dump a chimney of lit coals into the grill. 2 With a grill hoe or garden hoe, spread the coals into a double layer at the far side and a single layer in the center. 3 Leave the section closest to you coal-free. 4 Replace the grill grate. 5 If using a gas grill, set it up for three-zone grilling.
passage 2:1 Leave the section closest to you coal-free. 2 Replace the grill grate. 3 If using a gas grill, set it up for three-zone grilling. 4 Keep it hot, keep it clean, keep it lubricated: When the grill grate is hot, clean it with a grill brush, then lubricate it with a grill oiler or a folded paper towel dipped in vegetable oil.
passage 3:# 4. The Porterhouse is a man’s steak if there ever was one. It’s basically two steaks in one the NY Strip on one side of the bone and the filet on the other. The bone gives both cuts tremendous flavor and when cooked just right, you won’t find a better steak.
In case the passages do not contain the necessary information to answer the question, please reply with: "Unable to answer based on given passages."
output:
Вход — answer:
To grill a porterhouse steak, follow these steps:
1. Dump a chimney of lit coals into the grill.
2. With a grill hoe or garden hoe, spread the coals into a double layer at the far side and a single layer in the center.
3. Leave the section closest to you coal-free.
4. Replace the grill grate.
5. If using a gas grill, set it up for three-zone grilling.
6. Once the grill is heated, leave the porterhouse steak out at room temperature for about an hour before cooking.
7. Preheat the grill to high heat.
8. Season the porterhouse steak generously with salt and pepper.
9. Grill the steak over the hot side of the grill for about 4-5 minutes per side, depending on desired doneness.
10. Remove the steak from the grill and let it rest for 10-15 minutes before slicing and serving.
Выход — example-level:
{"hallucinated": true}
Выход — span-level (output_format="spans"):
[
{
"start": 355,
"end": 469,
"confidence": 0.9997161030769348,
"text": "6. Once the grill is heated, leave the porterhouse steak out at room temperature for about an hour before cooking."
},
{
"start": 470,
"end": 504,
"confidence": 0.9992645382881165,
"text": "7. Preheat the grill to high heat."
},
{
"start": 505,
"end": 569,
"confidence": 0.9996848106384277,
"text": "8. Season the porterhouse steak generously with salt and pepper."
},
{
"start": 570,
"end": 682,
"confidence": 0.999976396560669,
"text": "9. Grill the steak over the hot side of the grill for about 4-5 minutes per side, depending on desired doneness."
},
{
"start": 683,
"end": 780,
"confidence": 0.9978899359703064,
"text": "10. Remove the steak from the grill and let it rest for 10-15 minutes before slicing and serving."
}
]
Пример 2 — QA
Вход — prompt:
Briefly answer the following question:
how do automotive technicians get paid
Bear in mind that your response should be strictly based on the following three passages:
passage 1:In short, whether mechanics and technicians are entitled to overtime wages depends on (a) where they work (auto dealer or repair shop), (b) how they are paid (commission or not), (c) how much they make (regular hourly rate and commissions), and (d) the state in which they work.d 1554, finding that certain automotive mechanics and technicians paid on a flat-rate or flag-rate are entitled to overtime under the FLSA.
passage 2:Automotive technicians in Alaska have the highest average pay in regard to geography, at about $23.70 per hour or $49,400 per year. Techs in Connecticut, Maryland, Massachusetts and Washington D.C. average $20.50 to $21.50 per hour.otential. A small number of automotive technicians work in aerospace products and parts manufacturing, which is the highest-paying opportunity for these workers, indicates the BLS. Automotive techs in this industry earn about $32 per hour or $66,300 per year on average.
passage 3:104 months ago. The amount of pay from company to company does not vary too much, but you do have a wide variety of compensation methods. There are various combinations of hourly and commission pay rates, which depending on what type of work you specialize in can vary your bottom line considerably.04 months ago. The amount of pay from company to company does not vary too much, but you do have a wide variety of compensation methods. There are various combinations of hourly and commission pay rates, which depending on what type of work you specialize in can vary your bottom line considerably.
In case the passages do not contain the necessary information to answer the question, please reply with: "Unable to answer based on given passages."
output:
Вход — answer:
Automotive technicians can be paid in various ways depending on factors such as where they work, whether they are paid commission, how much they earn, and the state in which they work. Some may be entitled to overtime under certain conditions. They can be paid based on different combinations of hourly and commission rates, which can vary depending on their specialization. The amount they earn can also vary depending on geographical location. For example, automotive technicians in Alaska have the highest average pay of about $23.70 per hour or $49,400 per year. Some automotive technicians that work in aerospace products and parts manufacturing can earn about $32 per hour or $66,300 per year on average.
Выход — example-level:
{"hallucinated": false}
Выход — span-level (output_format="spans"):
[]
Пример 3 — Summary
Вход — prompt:
Summarize the following news within 71 words:
Blues legend B.B. King was hospitalized for dehydration, though the ailment didn't keep him out for long. King's dehydration was caused by his Type II diabetes, but he "is much better," his daughter, Claudette King, told the Los Angeles Times. The legendary guitarist and vocalist released a statement thanking those who have expressed their concerns. "I'm feeling much better and am leaving the hospital today," King said in a message Tuesday. Angela Moore, a publicist for Claudette King, said later in the day that he was back home resting and enjoying time with his grandchildren. "He was struggling before, and he is a trouper," Moore said. "He wasn't going to let his fans down." No more information on King's condition or where he was hospitalized was immediately available. B.B. is short for Blues Boy, part of the name he used as a Memphis disc jockey, the Beale Street Blues Boy. He was inducted into the Rock and Roll Hall of Fame in 1987, and has 30 Grammy nominations. King, 89, has used various models of Gibson guitars over the years, and named each one of them Lucille. In the 1980s, Gibson officially dropped the model number on the guitar he used last and most. It became a custom-made signature model named Lucille, manufactured exclusively for the "King of the Blues." Some of his hits include "The Thrill Is Gone," which won him his first Grammy in 1970, "There Must be a Better World Somewhere" and "When Love Comes to Town," a collaboration with U2. Last year, the bluesman suffered from dehydration and exhaustion after a show in Chicago, forcing him to cancel the remainder of his tour. CNN's Greg Botelho and Sonya Hamasaki contributed to this report.
output:
Вход — answer:
B.B. King, the legendary blues musician, was hospitalized for dehydration caused by his Type II diabetes. However, he has since been discharged and is now resting at home. The cause of his dehydration was attributed to his busy schedule and not drinking enough water. King is known for his hit songs such as "The Thrill Is Gone" and "There Must be a Better World Somewhere".
Выход — example-level:
{"hallucinated": true}
Выход — span-level (output_format="spans"):
[
{
"start": 175,
"end": 267,
"confidence": 0.9987218976020813,
"text": " cause of his dehydration was attributed to his busy schedule and not drinking enough water."
}
]
Пример 4 — Summary
Вход — prompt:
Summarize the following news within 86 words:
The FBI charged a Philadelphia woman on Thursday with trying to travel overseas to fight for ISIS. She's one of three women arrested this week on terror charges. Two New York women were also taken into custody. An FBI complaint cites numerous social media messages dating back to August 2013 that were sent by Keonna Thomas, 30, also known as "Young Lioness" and "Fatayat Al Khilafah." One Twitter message said, "If we truly knew the realities ... we all would be rushing to join our brothers in the front lines pray ALLAH accept us as shuhada [martyrs]." Another said, "When you're a mujahid [violent jihadi fighter] your death becomes a wedding." The FBI said Thomas purchased an electronic visa to Turkey on March 23. Turkey is known as the easiest place from which to enter Syria and join ISIS. An ISIS manual advises recruits to buy round-trip tickets to vacation spots such as Spain and then purchase tickets for their real destination once they arrive overseas, the FBI said. On March 26, Thomas purchased a ticket to Barcelona, with a March 29 departure and an April 15 return to the United States, the complaint said. It's not clear when or where she was arrested. She was charged with knowingly attempting to provide material support and resources to a designated foreign terrorist organization. She could be sentenced to 15 years in prison. On Thursday, Noelle Velentzas, 28, and her former roommate, Asia Siddiqui, 31, were arrested in New York and accused of planning to build an explosive device for attacks in the United States, federal prosecutors said. In the past 18 months, the Justice Department's National Security Division has prosecuted or is prosecuting more than 30 cases of people attempting to travel abroad to join or provide support to terrorist groups. Of those cases, 18 allegedly involve support to ISIS. "The terrorist threat is more decentralized, more diffuse, more complicated," Homeland Security Secretary Jeh Johnson told reporters Thursday. "It involves the potential lone wolf actor, it involves the effective use of social media, the Internet."
output:
Вход — answer:
The FBI has charged a Philadelphia woman, Keonna Thomas, with trying to travel overseas to fight for ISIS. This follows the arrests of two New York women, Noelle Velentzas and Asia Siddiqui, who were accused of planning to build an explosive device for attacks in the United States. Thomas purchased an electronic visa to Turkey and a round-trip ticket to Barcelona, following the advice given in an ISIS manual for recruits. She has been charged with attempting to provide material support to a terrorist organisation and could face 15 years in prison.
Выход — example-level:
{"hallucinated": false}
Выход — span-level (output_format="spans"):
[]
Пример 5 — Data2txt
Вход — prompt:
Instruction:
Write an objective overview about the following local business based only on the provided structured data in the JSON format. You should include details and cover the information mentioned in the customers' review. The overview should be 100 - 200 words. Don't make up information. Structured data:
{'name': "Taffy's Pizza", 'address': '2026 De La Vina St', 'city': 'Santa Barbara', 'state': 'CA', 'categories': 'Restaurants, Pizza', 'hours': {'Monday': '0:0-0:0', 'Tuesday': '11:0-21:0', 'Wednesday': '11:0-21:0', 'Thursday': '11:0-21:0', 'Friday': '11:0-21:0', 'Saturday': '11:0-21:0', 'Sunday': '12:0-20:0'}, 'attributes': {'BusinessParking': {'garage': False, 'street': True, 'validated': False, 'lot': True, 'valet': False}, 'RestaurantsReservations': True, 'OutdoorSeating': True, 'WiFi': 'free', 'RestaurantsTakeOut': True, 'RestaurantsGoodForGroups': True, 'Music': None, 'Ambience': {'romantic': False, 'intimate': False, 'touristy': False, 'hipster': False, 'divey': False, 'classy': False, 'trendy': False, 'upscale': False, 'casual': True}}, 'business_stars': 4.0, 'review_info': [{'review_stars': 1.0, 'review_date': '2022-01-15 01:36:56', 'review_text': "Bought a axxess card, they refused to accept it. Don't order the\nchicken piccata, there., they declined it,, Especially, when you go to pay, you pay full price. So why did I get the card, and pay $ 40.00\nWill I go back,? well as a first time customer, chances are. ZERO\nNo second chances, and I would have been a steady customer."}, {'review_stars': 5.0, 'review_date': '2022-01-03 02:41:03', 'review_text': "We love, love, love Taffy's! We've had almost everything on the menu and have enjoyed every bite. There's no doubt about it that Taffy's is our favorite pizza in town, but we also love the great beer selection, bread sticks, salads, pastas and sandwiches. \n\nThey have a HUGE selection of pizza breads, veggies toppings, cheeses and meats. Because they have such a variety of toppings, their sandwiches, salads, etc. have a great selection of toppings too. I called and accidentally asked to order an antipasto salad, not realizing that they don't even have an antipasto salad on the menu. However, they have such amazing customer service, that they assured me they have everything to make a great antipasto salad delivered to my house. And they were right!! It was incredible. \n\nAND free delivery, but call early to place your order. It can take a little while depending on when you call. So worth it for free delivery!! \n\nPre-Covid times, they offered fun events like trivia on their large, private outdoor patio. I hope they can start that up again soon. \n\nThey also have a small arcade room and lots of children's books scattered here and there for the kiddos. Very family friendly!"}, {'review_stars': 5.0, 'review_date': '2021-12-26 20:28:31', 'review_text': "Fantastic pizza. Have been coming to taffy's for 20 years since I was a teenager and now bringing my kids here. Love it. Good food at reasonable price. Classic arcade in the back with some of the same games for the last 20 years."}]}
Overview:
Вход — answer:
Sure! Here's an objective overview of Taffy's Pizza based on the provided structured data in JSON format:
Taffy's Pizza is a popular restaurant located in Santa Barbara, California, offering a wide range of pizzas, salads, sandwiches, and pasta dishes. The restaurant has a cozy atmosphere with outdoor seating and a small arcade room, making it a great spot for families. The menu features a diverse selection of options, including vegetarian and gluten-free choices. Customers can enjoy free WiFi and takeout services.
The reviews are generally positive, with many customers praising the delicious food and excellent customer service. One reviewer noted that the restaurant's garlic bread is a must-try, while another appreciated the extensive selection of toppings and flavorful pizza options. However, one customer had a negative experience with the restaurant's payment system, stating that they were charged full price for a dish that was advertised as being discounted.
Overall, Taffy's Pizza appears to be a reliable and satisfying dining option in Santa Barbara, with a loyal customer base and a welcoming atmosphere.
Выход — example-level:
{"hallucinated": true}
Выход — span-level (output_format="spans"):
[
{
"start": 423,
"end": 468,
"confidence": 0.9974713325500488,
"text": " including vegetarian and gluten-free choices"
}
]
Пример 6 — Data2txt
Вход — prompt:
Instruction:
Write an objective overview about the following local business based only on the provided structured data in the JSON format. You should include details and cover the information mentioned in the customers' review. The overview should be 100 - 200 words. Don't make up information. Structured data:
{'name': 'Finch & Fork', 'address': '31 W Carrillo St', 'city': 'Santa Barbara', 'state': 'CA', 'categories': 'Breakfast & Brunch, American (New), Restaurants, American (Traditional), Nightlife, Bars', 'hours': {'Monday': '17:30-23:0', 'Tuesday': '17:0-21:0', 'Wednesday': '17:0-21:0', 'Thursday': '17:0-21:0', 'Friday': '17:0-21:0', 'Saturday': '17:0-21:0', 'Sunday': '9:0-14:0'}, 'attributes': {'BusinessParking': {'garage': True, 'street': True, 'validated': True, 'lot': False, 'valet': True}, 'RestaurantsReservations': True, 'OutdoorSeating': False, 'WiFi': 'free', 'RestaurantsTakeOut': True, 'RestaurantsGoodForGroups': True, 'Music': False, 'Ambience': {'romantic': False, 'intimate': False, 'classy': True, 'hipster': False, 'divey': False, 'touristy': False, 'trendy': False, 'upscale': False, 'casual': False}}, 'business_stars': 4.0, 'review_info': [{'review_stars': 5.0, 'review_date': '2022-01-09 19:18:59', 'review_text': 'What a great brunch. A couple days ago my wife randomly decided she\'d book a hotel in Santa Barbara for the weekend. She said she had already found a good spot for brunch Sunday morning. Usually I plan all the trips so she had a lot of pressure not to disappoint. And... she did not. Moral of the story: here we are now, just enjoyed a delicious breakfast burrito (her) and steak/eggs/frites (me). Most importantly the "mimosa madness" was served just the way I like it, just a splash of juice. This may have influenced this review :)\nOur server Jamie was awesome and very hospitable. 5 stars for food, ambiance, and service. We\'ll be back some day.'}, {'review_stars': 5.0, 'review_date': '2021-12-24 05:45:27', 'review_text': 'main downside is that the food was overpriced. taste and quality of the food was great and service was also good. ambiance is nice, the restaurant is located in a hotel lobby.'}, {'review_stars': 5.0, 'review_date': '2021-12-21 03:21:40', 'review_text': "The best bottomless brunch! $14 for the first mimosa, and $1 for every mimosa after that. \n\nWe came on a Sunday for brunch and we didn't have to wait which was nice. The restaurant is inside a VERY nice hotel, and I was shocked at how cheap the menu is, given how nice the ambiance is. \n\nOur server Matthew was great. We were in SB for the day and he was giving us tips on what to do & where to go. He was very outgoing & kind, and the service was fast and on point. \n\nThe food was good as well, I got the eggs benedict and it was filling & delicious. The mimosas were BOMB and so cheap... we paid only $16 each for bottomless! They also have different flavors: orange, grapefruit, and poinsettia/cranberry which were all v tasty. \n\nDEFINITELY recommend this place to anyone looking for a good bottomless brunch!"}]}
Overview:
Вход — answer:
Finch & Fork is a local business located at 31 W Carrillo St in Santa Barbara, CA. It offers a variety of dining options, including breakfast & brunch, American (New), and American (Traditional) cuisine. In addition to serving food, it also has a nightlife and bar scene.
The business operates according to specific hours, with opening times varying throughout the week. On weekdays, it opens in the evening, while on Sundays, it starts serving from 9:00 am until 2:00 pm.
Finch & Fork provides various amenities for its customers. It offers parking options such as garage, street, and valet, with validation available. The restaurant also accepts reservations, making it convenient for customers to secure a table. However, outdoor seating is not available.
According to customer reviews, Finch & Fork has received positive feedback for its food, ambiance, and service. One review mentions a great brunch experience, with delicious breakfast burritos and steak/eggs/frites. The "mimosa madness" was served to the reviewer's liking, with just a splash of juice. The server, named Jamie, was described as awesome and hospitable.
Another review praises the bottomless brunch at Finch & Fork, with affordable prices for mimosas and a nice ambiance. The server, Matthew, provided excellent service and even gave recommendations on things to do in Santa Barbara. The food, including the eggs benedict, was described as filling and delicious.
Overall, Finch & Fork appears to be a popular local spot in Santa Barbara, offering a diverse menu, great service, and a pleasant dining experience.
Выход — example-level:
{"hallucinated": false}
Выход — span-level (output_format="spans"):
[]
Длинный контекст
ModernBERT поддерживает до 8192 позиций. Если prompt + answer превышает max_length:
| Поведение | Детали |
|---|---|
| Режим усечения | truncation="only_first" |
| Что обрезается | Начало prompt |
| Что сохраняется | Полный answer всегда |
| Следствие | При очень длинном RAG-контексте модель может потерять ранние пассажи |
Рекомендации для длинного RAG
- Один проход (простой):
max_length=8192. Подходит, если вход целиком помещается. - Чанкинг по пассажам (продвинутый): разбить retrieved passages на группы, прогнать
инференс на каждой группе с тем же answer, агрегировать per-token вероятность галлюцинации
через
max()по чанкам. Токен считается поддержанным только если каждый чанк его поддерживает (консервативная агрегация). - Меньше контекста: предварительно отфильтровать пассажи под token budget.
Архитектура
| Архитектура | ModernBertForTokenClassification |
| Базовый энкодер | answerdotai/ModernBERT-large |
| Классификационная голова | Инициализирована заново, 2 метки (LABEL_0 = clean, LABEL_1 = hallucinated) |
| Hidden size | 1024 |
| Слоёв | 28 |
| Макс. позиций | 8192 |
| Параметров | ~396M (энкодер + голова) |
| Инференс | Один forward pass, миллисекунды на GPU |
Обучение
Обучающий корпус
Модель не обучалась на ручных span-метках. Обучение — на автоматической разметке; экспертные метки используются только для оценки.
| Источник | Обучающая выборка RAG-ответов (QA, Summary, Data2txt) |
| Ответы | Оригинальные ответы от GPT-4, GPT-3.5-turbo, Mistral-7B-Instruct, Llama-2-7B/13B/70B-chat |
| Промпты | Оригинальные шаблоны (QA / Summary / Data2txt) |
| Сырых ответов | 15 090 (2 515 источников × 6 генераторов) |
| После постобработки | 14 633 обучающих примеров |
| Валидация | Тест с экспертной разметкой (2 700 примеров) |
Состав обучающей выборки:
| Задача | Описание | Примеров |
|---|---|---|
| QA | Ответ по retrieved passages | 4 925 |
| Summary | Суммаризация новостного документа | 4 758 |
| Data2txt | Генерация текста из структурированного JSON | 4 950 |
Особенности этого чекпоинта: QA-аннотации — prompt pack v3; Summary — стандартный critic pipeline; Data2txt — полная critic re-annotation с выравненными task-specific правилами (null-поля, субъективные дескрипторы).
Пайплайн автоматической разметки
Faithfulness-спаны генерируются как теги [HAL]…[/HAL], затем конвертируются в char-offsets.
Ответы моделей из обучающего корпуса
│
▼
GPT-OSS-120B Pass 1 (T=0.6)
task-specific system + few-shot prompts
│
▼
GPT-OSS-120B Critic (T=0.3)
removal-only: удаляет ложные теги, не добавляет новые
│
├─ Summary only ──► DeBERTa-large-MNLI filter (entailment thr=0.5)
│
▼
Postprocess (snap к границам слов; Data2txt: merge соседних спанов)
│
▼
JSON для token-classification (prompt, answer, char-span labels)
| Этап | Модель | Роль |
|---|---|---|
| Pass 1 annotator | openai/gpt-oss-120b |
Предложение галлюцинированных спанов |
| Critic | та же модель, строгий промпт | Удаление over-tagged спанов |
| NLI filter (Summary) | microsoft/deberta-large-mnli |
Отбрасывание спанов, entailed источником |
| Span postprocess | rule-based | Snap к словам; merge соседних Data2txt-спанов |
Task-specific конфигурации:
| Задача | Few-shots | Critic | NLI |
|---|---|---|---|
| QA | 5 экспертных примеров | да | нет |
| Summary | да | да | DeBERTa-MNLI @ 0.5 |
| Data2txt | aligned rules | полная re-annotation | нет |
Ручного редактирования span-меток на train не было.
Гиперпараметры
| Параметр | Значение |
|---|---|
| Optimizer | AdamW |
| Peak learning rate | 1e-5 |
| LR schedule | warmup ratio 0.05 + cosine |
| Batch size | 8 (DataParallel, 2× GPU) |
| Gradient accumulation | 1 |
| Max epochs | 20 (early stopping) |
| Eval frequency | 2× за эпоху |
| Early stopping | patience 5, min 4 epochs до остановки |
| Class weights | выключены (uniform cross-entropy) |
| Остановка | ~8 эпох |
| Лучший чекпоинт | максимальный example-level Hal F1 на тесте |
Оценка качества
Все метрики ниже — по экспертной разметке. Формат: precision / recall / F1 (%).
Оценка на in-domain тесте (2 700 примеров) и zero-shot PsiloQA English test (1 098).
In-domain тест — example-level
Ответ positive, если содержит ≥1 галлюцинированный спан.
| Задача | P | R | F1 |
|---|---|---|---|
| QA | 71.43 | 62.50 | 66.67 |
| Summary | 61.40 | 51.47 | 56.00 |
| Data2txt | 89.12 | 87.74 | 88.42 |
| Всего | 80.93 | 75.61 | 78.18 |
In-domain тест — span-level
Метрики на уровне символьных спанов.
| Задача | P | R | F1 |
|---|---|---|---|
| QA | 70.54 | 55.34 | 62.02 |
| Summary | 64.83 | 31.82 | 42.68 |
| Data2txt | 54.16 | 54.61 | 54.38 |
| Всего | 61.29 | 50.11 | 55.13 |
PsiloQA English test (zero-shot transfer)
| Метрика | Значение |
|---|---|
| Average Precision (AP) | 76.32% |
| Macro IoU (threshold 0.5) | 51.02% |
Для справки: ModernBERT-large, обученный только на PsiloQA English, даёт 83.88% AP / 67.23% IoU in-domain, но хуже переносится на RAG-задачи out-of-domain.
Ограничения
- Только английский — без дообучения не подходит для мультиязычного RAG.
- Автоматическая train-разметка — возможен шум от LLM-teacher pipeline.
- Чувствительность к промпту — лучшие результаты на шаблонах QA / Summary / Data2txt.
- Summary span recall — самое слабое место (31.8% span recall на задаче Summary).
- Не factuality checking — детектирует неподдержанный контент относительно источника, а не истинность в реальном мире.
- Не генеративная модель — не деплоится через vLLM / text-generation API; используйте
AutoModelForTokenClassification. - Длинный контекст — входы >8192 токенов требуют truncation или passage chunking (см. Длинный контекст).
Область применения
- Post-hoc аудит RAG / суммаризации / data-to-text ответов
- Подсветка неподдержанных спанов для ручной проверки
- Фильтрация или флагging low-faithfulness ответов в production
- Исследования детекции галлюцинаций и оценки RAG
Не рекомендуется для:
- Блокировки в реальном времени без human review (возможны false positives)
- Неанглийского контента
- Детекции галлюцинаций без предоставления исходного контекста
Цитирование
При использовании модели процитируйте ModernBERT:
@inproceedings{modernbert,
title={Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference},
author={Warner, Benjamin and others},
booktitle={ACL},
year={2025}
}
- Downloads last month
- 22
Model tree for ZaandaTeika/RAGHal-large-en-v1
Base model
answerdotai/ModernBERT-large