File size: 5,528 Bytes
1162a81
 
 
 
 
 
a1ff880
1162a81
 
 
 
 
 
36808c1
 
1162a81
 
36808c1
 
 
 
 
1162a81
 
 
 
 
 
 
 
 
 
41bbbd3
 
 
 
1162a81
41bbbd3
 
 
 
1162a81
 
 
 
 
 
41bbbd3
 
 
 
 
 
1162a81
41bbbd3
36808c1
 
 
 
 
 
8c6b842
36808c1
 
 
8c6b842
 
36808c1
 
 
 
 
8c6b842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
license: apache-2.0
datasets:
- neural-bridge/rag-full-20000
language:
- en
pipeline_tag: text-generation
tags:
- retrieval-augmented-generation
---
# **Rago v2 13B**
**Rago v2 13B is a [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf)-based retrieval-augmented generation-optimized model built by [Neural Bridge AI](https://www.neuralbridge.ai/) and trained on [RAG Full Dataset 20000](https://huggingface.co/datasets/neural-bridge/rag-full-20000). It is available under [Apache license 2.0](https://www.apache.org/licenses/LICENSE-2.0.html).**

## **Model Description**
Rago v2 13B model is a retrieval-augmented generation-optimized (RAGO) model, which enhances large language models by integrating an external authoritative knowledge base (context) for generating responses. This integration significantly improves the model's ability to produce relevant, accurate, and context-specific output across specialized domains or internal data without necessitating retraining. It addresses key challenges of large language models (LLMs), such as unpredictability, reliance on potentially outdated data, and the propagation of incorrect information, thereby improving user trust in AI applications. Rago v2 13B, specifically, is an advancement built upon the [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf) model, optimized for retrieval-augmented generation, making it particularly effective in contextually aware response generation.

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import torch

model = "neural-bridge/Rago-v2-13b"

tokenizer = AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="auto",
)

def create_prompt(context, question):
  return f"""##CONTEXT## {context} ##QUESTION## {question} ##ANSWER##"""

sequences = pipeline(
   create_prompt(
       context="Neural Bridge AI is a software company developing artificial intelligence (AI) solutions. It is founded in New York in the USA.",
       question="What solutions does Neural Bridge AI develop for its clients?"
   ),
    max_length=200,
    do_sample=True,
    top_k=10,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id,
)

def print_result(generated_text):
  result_start = "##ANSWER##"
  answer_start = generated_text.find(result_start)
  print(generated_text[answer_start + len(result_start) :].strip())

for seq in sequences:
    print_result(seq["generated_text"])
```

## **Model Details**

### Training Data

Rago v2 13B has been trained using the [Neural Bridge's RAG Full 20000](https://huggingface.co/datasets/neural-bridge/rag-full-20000) dataset, which comprises a blend of [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb), [gms8k](https://huggingface.co/datasets/gsm8k), and [RAG Hallucination Dataset 1000](https://huggingface.co/datasets/neural-bridge/rag-hallucination-dataset-1000).

### Training Details

In terms of training specifics, Rago v2 13B is built upon [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf) employing [LoRA](https://arxiv.org/abs/2106.09685) to enhance the model's capability to deliver relevant, precise, and context-specific output across specialized domains or internal datasets. This approach aims to tackle significant challenges faced by LLMs, such as unpredictability, reliance on potentially outdated information, and the spread of incorrect data. The architecture of Rago v2 13B mirrors that of [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf), augmented with [LoRA](https://arxiv.org/abs/2106.09685) adapters. The model is trained on a single NVIDIA A100 GPU for approximately two days, utilizing a learning rate of *1e-5* with cosine scheduler, alongside the following LoRA parameters:

* LoRA Rank (R): 64
* LoRA Alpha: 16
* LoRA Dropout: 0.1
* Target Modules: *q_proj, k_proj, v_proj, o_proj*

Rago v2 13B benefits from a custom data collator designed to boost model performance significantly. Employing a masked language modeling (MLM) strategy, the model is fine-tuned to generate more accurate responses by exclusively masking the answer portion of the training data. This custom data collator has led to noticeable improvements in the model's factuality performance.

## **Neural Bridge AI Rago Models Index**

| Model       |  Link                                                     | Base Model
| -----       | ------                                                    | ----------
| Rago v1 1B  |  [link](https://huggingface.co/neural-bridge/Rago-v1-1b)  | [Falcon-RW-1B](https://huggingface.co/tiiuae/falcon-rw-1b)
| Rago v1 7B  |  [link](https://huggingface.co/neural-bridge/Rago-v1-7b)  | [Falcon-7B](https://huggingface.co/tiiuae/falcon-7b)
| Rago v1 40B |  [link](https://huggingface.co/neural-bridge/Rago-v1-40b) |[Falcon-40B](https://huggingface.co/tiiuae/falcon-40b)
| Rago v2 7B  |  [link](https://huggingface.co/neural-bridge/Rago-v2-7b)  | [Llama 2 7B](https://huggingface.co/meta-llama/Llama-2-7b-hf)
| Rago v2 13B |  [link](https://huggingface.co/neural-bridge/Rago-v2-13b) | [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf)

## **Licence**

This public extract is made available under [Apache licence 2.0](https://www.apache.org/licenses/LICENSE-2.0.html). Users should also abide to the [Llama 2 13B](https://huggingface.co/meta-llama/Llama-2-13b-hf) ToU.