aditya-emergence
commited on
Commit
•
4e5dbb0
1
Parent(s):
f2c1935
Create README.md (#2)
Browse files- Create README.md (6b6ee651b7abea1dbd6a63ee7a4305b82b5ddfb0)
README.md
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- RAG
|
5 |
+
- EmergenceAI
|
6 |
+
inference: false
|
7 |
+
---
|
8 |
+
|
9 |
+
# Emergence-RAG-response-generation
|
10 |
+
|
11 |
+
Emergence-RAG-response-generation is a 13b parameter decoder-style transformer model for RAG applications. It is fine-tuned from a llama2-13b base-model.
|
12 |
+
|
13 |
+
This model was trained by [Emergence AI](https://www.emergence.ai/).
|
14 |
+
|
15 |
+
Emergence-RAG-response-generation is part of the family of Emergence models designed specifically for use in RAG applications.
|
16 |
+
|
17 |
+
Emergence-RAG-response-generation is a corpus-grounded question-answering model that grounds answers in the provided information snippets. A typical use-case is as part of a larger retrieval-based corpus-grounded dialog system.
|
18 |
+
|
19 |
+
## Model Date
|
20 |
+
|
21 |
+
August 8, 2023
|
22 |
+
|
23 |
+
## Model License
|
24 |
+
|
25 |
+
Apache-2.0
|
26 |
+
|
27 |
+
|
28 |
+
## Usage
|
29 |
+
|
30 |
+
Loading model and tokenizer:
|
31 |
+
|
32 |
+
```python
|
33 |
+
import torch
|
34 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
35 |
+
|
36 |
+
model_path = "MerlynMind/Merlyn-QA_from_Corpus_Bio_History-llama2-13b"
|
37 |
+
device = torch.device("cuda:0") # change device id as necessary
|
38 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
39 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, fast_tokenizer=True)
|
40 |
+
model.to(device) # move to device
|
41 |
+
|
42 |
+
```
|
43 |
+
|
44 |
+
Prompt example:
|
45 |
+
|
46 |
+
```python
|
47 |
+
info = '''Information:\tThe Solar System is about 4.6 billion years old. The Sun formed by gravity in a large molecular cloud. It is mainly hydrogen, which it converts into helium.
|
48 |
+
Information:\tThe formation and evolution of the Solar System began 4.6 billion years ago with the gravitational collapse of a small part of a giant molecular cloud.
|
49 |
+
Information:\tAstronomers are now more or less certain that the order of the planets was not always as it is today. Knowing what we know today, we can see the Solar System is strange. All other planetary system we are able to study have their largest planet close to their star. Also we have noticed other oddities in the Solar System. Mars is smaller than it ought to be, and the asteroid belt has been disturbed.
|
50 |
+
Information:\tFor thousands of years, people had no need for a name for the "Solar System". They thought the Earth stayed still at the center of everything (geocentrism). The Greek philosopher Aristarchus of Samos suggested that there was a special order in the sky. Nicolaus Copernicus was the first to develop a mathematical system that described what we now call the "Solar System". This was called a "new system of the world". In the 17th century, Galileo Galilei, Johannes Kepler and Isaac Newton began to understand physics more clearly. People began to accept the idea that the Earth is a planet that moves around the Sun, and that the planets are worlds, and that all worlds are governed by the same same physical laws. More recently, telescopes and space probes sometimes let us see details directly. All inner planets have surface features. The gas giants (as the name suggests) have surfaces whose make-up is gradually being discovered.
|
51 |
+
Information:\tThere are eight planets in the Solar System. From closest to farthest from the Sun, they are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. The first four planets are called terrestrial planets. They are mostly made of rock and metal, and they are mostly solid. The last four planets are called gas giants. This is because they are much larger than other planets and are mostly made of gas.
|
52 |
+
'''
|
53 |
+
qs = "Question:\tHow old is the Solar System?"
|
54 |
+
|
55 |
+
prompt = tokenizer.bos_token
|
56 |
+
prompt += '''Instruction:\tYou are to try to answer the following question using only the pieces of information given.
|
57 |
+
Instruction:\tYour response should be a well formed JSON object with an 'answerable' property followed by an 'answer' property.
|
58 |
+
Instruction:\tIf you cannot answer the question given the information, the value of the 'answerable' should be 'false' and the 'answer' should be an empty string.
|
59 |
+
Instruction:\tIf you can answer the question given the information, the value of the 'answerable' should be 'true' and your answer should be the string value of the 'answer' property.
|
60 |
+
''' + info + qs + " Response:"
|
61 |
+
|
62 |
+
```
|
63 |
+
|
64 |
+
We recommend using newline character for stopping criterion, as follows:
|
65 |
+
|
66 |
+
```python
|
67 |
+
from transformers import StoppingCriteria, StoppingCriteriaList
|
68 |
+
|
69 |
+
eos_tokens = [tokenizer.eos_token,'\n']
|
70 |
+
eos_token_ids = [tokenizer.encode(token)[0] for token in eos_tokens]
|
71 |
+
|
72 |
+
class MultipleEOSTokensStoppingCriteria(StoppingCriteria):
|
73 |
+
def __init__(self, eos_token_ids):
|
74 |
+
self.eos_token_ids = set(eos_token_ids)
|
75 |
+
def __call__(self, input_ids, scores) -> bool:
|
76 |
+
if input_ids.shape[-1] <= 1:
|
77 |
+
return False
|
78 |
+
for eos_token_id in self.eos_token_ids:
|
79 |
+
if eos_token_id == input_ids[0, -1].item():
|
80 |
+
return True
|
81 |
+
return False
|
82 |
+
|
83 |
+
# Define stopping criteria
|
84 |
+
multiple_eos_tokens_processor = MultipleEOSTokensStoppingCriteria(eos_token_ids)
|
85 |
+
stopping_criteria = StoppingCriteriaList([multiple_eos_tokens_processor])
|
86 |
+
```
|
87 |
+
|
88 |
+
Inference:
|
89 |
+
|
90 |
+
```python
|
91 |
+
inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False).to(device)
|
92 |
+
generate_ids = model.generate(
|
93 |
+
**inputs,
|
94 |
+
max_new_tokens=1024,
|
95 |
+
temperature=0.0,
|
96 |
+
num_beams=2,
|
97 |
+
top_p=1,
|
98 |
+
stopping_criteria=stopping_criteria
|
99 |
+
)
|
100 |
+
response = tokenizer.decode(generate_ids[0],
|
101 |
+
skip_special_tokens=True,
|
102 |
+
clean_up_tokenization_spaces=True)
|
103 |
+
```
|
104 |
+
|
105 |
+
Example output (after response processing):
|
106 |
+
|
107 |
+
```json
|
108 |
+
[{"answerable": "true", "answer": "4.6 billion years"}]
|
109 |
+
```
|