pytorch bert en arxiv:2302.07452 license:other region:us
---
language:
- en
license:
- other
tag:
- doc-chat
- DocChat
- dragon
- retriever
- conversation
- multi-turn
- conversational query
---

# Model Information

We are excited to announce the release of Cerebras DocChat, our first iteration of models designed for document-based conversational question answering. This series includes two models: Cerebras Llama3-DocChat, a large language model (LLM), and Cerebras Dragon-DocChat, a multi-turn retriever model.

This model – Cerebras Dragon-DocChat – was built on top of Dragon+ and finetuned using ChatQA’s conversational Q&A dataset. The finetuning process took *minutes* on one Cerebras system (yes you read that correctly), and yields 8.9% and 3.5% absolute improvements in recall over Dragon+ and ChatQA Dragon-Multiturn (top-1).

**Note that like its predecessors, Cerebras Dragon-DocChat is a dual-encoder embedding model. This model card is for the question encoder. You can find the context encoder's model card here.**

You can find more information about DocChat at the following locations:
* [Blog post](https://www.cerebras.net/blog/train-a-gpt-4-level-conversational-qa-in-a-few-hours)
* [LLM model weights on HuggingFace](https://huggingface.co/cerebras/Llama3-DocChat-1.0-8B)
* Embedding model weights on HuggingFace: [Query Encoder](https://huggingface.co/cerebras/Dragon-DocChat-Query-Encoder), [Context Encoder](https://huggingface.co/cerebras/Dragon-DocChat-Context-Encoder)
* [Data preparation, training, and evaluation code](https://github.com/Cerebras/DocChat)

## Results

DocChat Retriever was evaluated on five multi-turn QA datasets.

<style>
   table {
      border: none;
      border-collapse: collapse;
      border-spacing: 0;
   }

   table td {
      border-style: solid;
      border-width: 1px;
      padding: 2px 5px;
      text-align: center;
      border-color: #7f8c8d;
   }
</style>
<table>
   <tbody>
      <tr>
         <td rowspan="1" colspan="1">
            <div data-align="center">
               <strong data-renderer-mark="true">Benchmark</strong>
            </div>
         </td>
         <td rowspan="1" colspan="1">
            <strong data-renderer-mark="true">Metric</strong>
         </td>
         <td rowspan="1" colspan="1">
            <strong data-renderer-mark="true">Facebook Dragon+</strong>
         </td>
         <td rowspan="1" colspan="1">
            <strong data-renderer-mark="true">Nvidia Dragon-Multiturn</strong>
         </td>
         <td rowspan="1" colspan="1">
            <strong data-renderer-mark="true">Cerebras Dragon-DocChat</strong>
         </td>
      </tr>
      <tr>
         <td rowspan="3" colspan="1">
            Doc2Dial
         </td>
         <td rowspan="1" colspan="1">
            Recall@1
         </td>
         <td rowspan="1" colspan="1">
            43.95
         </td>
         <td rowspan="1" colspan="1">
            50.11
         </td>
         <td rowspan="1" colspan="1">
            51.54
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@5
         </td>
         <td rowspan="1" colspan="1">
            77.61
         </td>
         <td rowspan="1" colspan="1">
            83.85
         </td>
         <td rowspan="1" colspan="1">
            83.12
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@20
         </td>
         <td rowspan="1" colspan="1">
            92.05
         </td>
         <td rowspan="1" colspan="1">
            95.33
         </td>
         <td rowspan="1" colspan="1">
            95.25
         </td>
      </tr>
      <tr>
         <td rowspan="3" colspan="1">
            QuAC
         </td>
         <td rowspan="1" colspan="1">
            Recall@1
         </td>
         <td rowspan="1" colspan="1">
            62.09
         </td>
         <td rowspan="1" colspan="1">
            60.02
         </td>
         <td rowspan="1" colspan="1">
            61.30
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@5
         </td>
         <td rowspan="1" colspan="1">
            86.01
         </td>
         <td rowspan="1" colspan="1">
            86.51
         </td>
         <td rowspan="1" colspan="1">
            87.69
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@20
         </td>
         <td rowspan="1" colspan="1">
            96.48
         </td>
         <td rowspan="1" colspan="1">
            96.60
         </td>
         <td rowspan="1" colspan="1">
            97.25
         </td>
      </tr>
      <tr>
         <td rowspan="3" colspan="1">
            QReCC
         </td>
         <td rowspan="1" colspan="1">
            Recall@1
         </td>
         <td rowspan="1" colspan="1">
            49.00
         </td>
         <td rowspan="1" colspan="1">
            49.43
         </td>
         <td rowspan="1" colspan="1">
            55.41
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@5
         </td>
         <td rowspan="1" colspan="1">
            85.14
         </td>
         <td rowspan="1" colspan="1">
            86.6
         </td>
         <td rowspan="1" colspan="1">
            90.11
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@20
         </td>
         <td rowspan="1" colspan="1">
            97.21
         </td>
         <td rowspan="1" colspan="1">
            98.28
         </td>
         <td rowspan="1" colspan="1">
            98.39
         </td>
      </tr>
      <tr>
         <td rowspan="3" colspan="1">
            INSCIT*
         </td>
         <td rowspan="1" colspan="1">
            Recall@1
         </td>
         <td rowspan="1" colspan="1">
            11.13
         </td>
         <td rowspan="1" colspan="1">
            18.35
         </td>
         <td rowspan="1" colspan="1">
            21.65
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@5
         </td>
         <td rowspan="1" colspan="1">
            29.27
         </td>
         <td rowspan="1" colspan="1">
            48.45
         </td>
         <td rowspan="1" colspan="1">
            50.72
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@20
         </td>
         <td rowspan="1" colspan="1">
            49.07
         </td>
         <td rowspan="1" colspan="1">
            66.19
         </td>
         <td rowspan="1" colspan="1">
            72.78
         </td>
      </tr>
      <tr>
         <td rowspan="3" colspan="1">
            Topiocqa*
         </td>
         <td rowspan="1" colspan="1">
            Recall@1
         </td>
         <td rowspan="1" colspan="1">
            29.19
         </td>
         <td rowspan="1" colspan="1">
            31.34
         </td>
         <td rowspan="1" colspan="1">
            38.19
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@5
         </td>
         <td rowspan="1" colspan="1">
            62.52
         </td>
         <td rowspan="1" colspan="1">
            65.79
         </td>
         <td rowspan="1" colspan="1">
            72.47
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Recall@20
         </td>
         <td rowspan="1" colspan="1">
            83.69
         </td>
         <td rowspan="1" colspan="1">
            84.37
         </td>
         <td rowspan="1" colspan="1">
            87.23
         </td>
      </tr>
      <tr>
         <td rowspan="2" colspan="1">
            Average**
         </td>
         <td rowspan="1" colspan="1">
            Avg top 1
         </td>
         <td rowspan="1" colspan="1">
            49.36
         </td>
         <td rowspan="1" colspan="1">
            54.76
         </td>
         <td rowspan="1" colspan="1">
            58.29
         </td>
      </tr>
      <tr>
         <td rowspan="1" colspan="1">
            Avg top 5
         </td>
         <td rowspan="1" colspan="1">
            76.30
         </td>
         <td rowspan="1" colspan="1">
            81.50
         </td>
         <td rowspan="1" colspan="1">
            84.19
         </td>
      </tr>
   </tbody>
</table>


\*Evaluated on a subset of the wikipedia corpus that was available to us. All models use the same evaluation strategy to ensure apples-to-apples comparisons.

\*\* We follow the same convention as in ChatQA, where we compare top-5 and top-20 of TopiOCQA and INSCIT to top-1 and top-5, respectively, of the other datasets, in order match differences in average context length.

## Prompt Format

In order to maintain consistency, we follow the same format as ChatQA. The chat history should be concatenated into a single query, as follows:


```
user: {user turn 1}
agent: {agent turn 1}
...
user: {current user turn}
```
## Example Usages


```python
# Demonstration of DocChat retriever in a multi-turn setting
# The sample documents are from a spec sheet about the Cerebras system & supercomputers

from transformers import AutoTokenizer, AutoModel
import torch

tokenizer = AutoTokenizer.from_pretrained("cerebras/Dragon-DocChat-Query-Encoder")
query_encoder = AutoModel.from_pretrained("cerebras/Dragon-DocChat-Query-Encoder")
context_encoder = AutoModel.from_pretrained("cerebras/Dragon-DocChat-Context-Encoder")

documents = []
documents.append("""
# Cerebras Wafer-Scale Cluster

The Cerebras Wafer-Scale Cluster (WSC) is a revolutionary technology suite that efficiently handles the enormous computational needs of AI model training. It centers around the CS-3 system, powered by the 3rd generation Wafer-Scale Engine (WSE-3)—the world’s largest AI-optimized processor. The WSC integrates MemoryX for high-capacity, off-chip model weight storage, and SwarmX for effective weight broadcasting and gradient reduction across the cluster. This setup allows the WSC to adeptly train multi-trillion parameter models, achieving near perfect linear-scaled performance and simplifying the complexity seen in traditional distributed computing.

The Cerebras WSE-3 is 46,250 square millimeters of silicon, 4 trillion transistors, 900K cores, 44 GB on-chip memory, and delivers an unparalleled 125 petaFLOPS of AI compute. It surpasses all other processors in AI-optimized cores, memory speed, and on-chip fabric bandwidth.
""")
documents.append("""
## AI Supercomputers

Condor Galaxy (CG), the supercomputer built by G42 and Cerebras, is the simplest and fastest way to build AI models in the cloud. With over 16 ExaFLOPs of AI compute, Condor Galaxy trains the most demanding models in hours rather than days. The terabyte scale MemoryX system natively accommodates 100 billion+ parameter models, making large scale training simple and efficient.

| Cluster  | ExaFLOPs | Systems  | Memory |
| -------- | -------- | -------- | ------ |
| CG1      | 4        | 64 CS-2s | 82 TB  |
| CG2      | 4        | 64 CS-2s | 82 TB  |
| CG3      | 8        | 64 CS-3s | 108 TB |
""")


query = [
    {"role": "user", "content": "How many cores does a WSE-3 have?"},
    {"role": "agent", "content": "WSE-3 has 900k cores."},
    {"role": "user", "content": "What is Condor Galaxy?"}
]

formatted_query = "\n".join([turn["role"] + ": " + turn["content"] for turn in query]).strip()

query_input = tokenizer(formatted_query, return_tensors='pt')
ctx_input = tokenizer(documents, padding=True, truncation=True, max_length=512, return_tensors='pt')
query_emb = query_encoder(**query_input).last_hidden_state[:, 0, :]
ctx_emb = context_encoder(**ctx_input).last_hidden_state[:, 0, :]

## Compute similarity scores:
similarities = query_emb.matmul(ctx_emb.transpose(0, 1)) # (1, num_ctx)

## Rank the similarity from highest to lowest
ranked_results = torch.argsort(similarities, dim=-1, descending=True) # (1, num_ctx)

for i, doc_idx in enumerate(ranked_results[0].tolist()):
    print(f"Rank {i}th document:")
    print("-" * 80)
    print(documents[doc_idx])
    print()

```

## License

This model was trained from Dragon+, and therefore is subject to [its license](https://github.com/facebookresearch/dpr-scale/blob/main/LICENSE). Furthermore, it is trained on ChatQA's synthetic conversational QA dataset which was generated using GPT-4. As a result this model can be used for non-commercial purposes only, and is subject to [Terms of Use](https://openai.com/policies/terms-of-use) of the data generated by OpenAI.

## Acknowledgements

DocChat was built on top of a large body of ML work, spanning training datasets, recipes, and evaluation. We want to thank each of these resources.

```
@article{lin_dragon_2023,
	title = How to Train Your DRAGON: Diverse Augmentation Towards Generalizable Dense Retrieval,
	url = {https://arxiv.org/abs/2302.07452},
	publisher = {arXiv},
	journal = {arXiv e-print 2302.07452},
	author = {Sheng-Chieh Lin, Akari Asai, Minghan Li, Barlas Oguz, Jimmy Lin, Yashar Mehdad, Wen-tau Yih, Xilun Chen},
	year = {2023},
}
@inproceedings{feng2020doc2dial,
  title={doc2dial: A Goal-Oriented Document-Grounded Dialogue Dataset},
  author={Feng, Song and Wan, Hui and Gunasekara, Chulaka and Patel, Siva and Joshi, Sachindra and Lastras, Luis},
  booktitle={Proceedings of the 2020 Conference on EMNLP},
  year={2020}
}
@inproceedings{choi2018quac,
  title={QuAC: Question Answering in Context},
  author={Choi, Eunsol and He, He and Iyyer, Mohit and Yatskar, Mark and Yih, Wen-tau and Choi, Yejin and Liang, Percy and Zettlemoyer, Luke},
  booktitle={Proceedings of the 2018 Conference on EMNLP},
  year={2018}
}
@inproceedings{anantha2021open,
  title={Open-Domain Question Answering Goes Conversational via Question Rewriting},
  author={Anantha, Raviteja and Vakulenko, Svitlana and Tu, Zhucheng and Longpre, Shayne and Pulman, Stephen and Chappidi, Srinivas},
  booktitle={Proceedings of the 2021 Conference on NAACL},
  year={2021}
}
@article{adlakha2022topiocqa,
  title={TopiOCQA: Open-domain Conversational Question Answering with Topic Switching},
  author={Adlakha, Vaibhav and Dhuliawala, Shehzaad and Suleman, Kaheer and de Vries, Harm and Reddy, Siva},
  journal={Transactions of the Association for Computational Linguistics},
  year={2022}
}
@article{wu2023inscit,
  title={InSCIt: Information-Seeking Conversations with Mixed-Initiative Interactions},
  author={Wu, Zeqiu and Parish, Ryu and Cheng, Hao and Min, Sewon and Ammanabrolu, Prithviraj and Ostendorf, Mari and Hajishirzi, Hannaneh},
  journal={Transactions of the Association for Computational Linguistics},
  year={2023}
}
```
