aditya-emergence commited on
Commit
3e5ae4a
1 Parent(s): 5f0fc31

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +109 -3
README.md CHANGED
@@ -1,3 +1,109 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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](https://huggingface.co/meta-llama/Llama-2-13b-hf) 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
+ This version is upgraded version of the [v1 model](https://huggingface.co/EmergenceAI/RAG-response-generation-model-v1) and was improved by training it with additional "negative" samples so that the model understands how to reject some of the irrelevant details in the provided context.
19
+
20
+ ## Model Date
21
+
22
+ December 5, 2023
23
+
24
+ ## Model License
25
+
26
+ Apache-2.0
27
+
28
+
29
+ ## Usage
30
+
31
+ Loading model and tokenizer:
32
+
33
+ ```python
34
+ import torch
35
+ from transformers import AutoTokenizer, AutoModelForCausalLM
36
+
37
+ model_path = "MerlynMind/Merlyn-Corpus_QA_V3_Alpha_0-llama2-13b"
38
+ device = torch.device("cuda:0") # change device id as necessary
39
+ model = AutoModelForCausalLM.from_pretrained(model_path)
40
+ tokenizer = AutoTokenizer.from_pretrained(model_path, fast_tokenizer=True)
41
+ model.to(device) # move to device
42
+
43
+ ```
44
+
45
+ Prompt example:
46
+
47
+ ```python
48
+ 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.
49
+ 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.
50
+ 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.
51
+ 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.
52
+ 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.
53
+ '''
54
+ qs = "Question:\tHow old is the Solar System?"
55
+
56
+ prompt = tokenizer.bos_token
57
+ prompt += '''Instruction:\tYou are to try to answer the following question using only the pieces of information given.
58
+ Instruction:\tYour response should be a well formed JSON object with an 'answerable' property followed by an 'answer' property.
59
+ 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.
60
+ 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.
61
+ ''' + info + qs + " Response:"
62
+
63
+ ```
64
+
65
+ We recommend using newline character for stopping criterion, as follows:
66
+
67
+ ```python
68
+ from transformers import StoppingCriteria, StoppingCriteriaList
69
+
70
+ eos_tokens = [tokenizer.eos_token,'\n']
71
+ eos_token_ids = [tokenizer.encode(token)[0] for token in eos_tokens]
72
+
73
+ class MultipleEOSTokensStoppingCriteria(StoppingCriteria):
74
+ def __init__(self, eos_token_ids):
75
+ self.eos_token_ids = set(eos_token_ids)
76
+ def __call__(self, input_ids, scores) -> bool:
77
+ if input_ids.shape[-1] <= 1:
78
+ return False
79
+ for eos_token_id in self.eos_token_ids:
80
+ if eos_token_id == input_ids[0, -1].item():
81
+ return True
82
+ return False
83
+
84
+ # Define stopping criteria
85
+ multiple_eos_tokens_processor = MultipleEOSTokensStoppingCriteria(eos_token_ids)
86
+ stopping_criteria = StoppingCriteriaList([multiple_eos_tokens_processor])
87
+ ```
88
+
89
+ Inference:
90
+
91
+ ```python
92
+ inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False).to(device)
93
+ generate_ids = model.generate(
94
+ **inputs,
95
+ max_new_tokens=1024,
96
+ temperature=0.0,
97
+ num_beams=2,
98
+ top_p=1,
99
+ stopping_criteria=stopping_criteria
100
+ )
101
+ response = tokenizer.decode(generate_ids[0],
102
+ skip_special_tokens=True,
103
+ clean_up_tokenization_spaces=True)
104
+ ```
105
+
106
+ Example output (after response processing):
107
+
108
+ ```json
109
+ {"answerable": "True", "answer": "The Solar System is about 4.6 billion years old."}