alirezamsh commited on
Commit
c4e8117
β€’
1 Parent(s): e4ad2e8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +67 -2
README.md CHANGED
@@ -8,9 +8,20 @@ datasets:
8
 
9
  # Leeroo Dedidcated Math Expert πŸ€—
10
 
11
- The model is built by applying [Orchestration of Expert](https://arxiv.org/abs/2401.13979) for the math domain. It either generates solutions or, when necessary, utilizes GPT-4 to fill in gaps in its knowledge base.
12
 
13
- In evaluations using the GSM8k dataset of [OpenLLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard), Leeroo Math 7B model achieved an accuracy of 84.77% in 5-shot setting, positioning it among the top performers in its class and notably surpassing the MetaMath 7B model (its base model), which scores 68.84% on the same dataset. This was accomplished while relying on GPT-4 for responses to half of the questions posed by GSM8k.
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  ## Sample Usage
16
 
@@ -41,6 +52,60 @@ print(decoded[0])
41
  # <GPT4></s>
42
  ```
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ## Learn More
45
 
46
  πŸ” To a deeper dive into our method and results, refer to [HF blog πŸ€—](https://huggingface.co/blog/alirezamsh/leeroo-multi-model-system), [publication](https://arxiv.org/abs/2401.13979), and [repository](https://github.com/Leeroo-AI/leeroo_orchestrator).
 
8
 
9
  # Leeroo Dedidcated Math Expert πŸ€—
10
 
11
+ The model is built by applying [Orchestration of Expert](https://arxiv.org/abs/2401.13979) for the math domain. The dedicated model either generates solutions or, when necessary, utilizes GPT-4 (or similar performing LLM) to fill in gaps in its knowledge base. Specifically, when given an input, the dedicated model first determines if the input question is solvable with the base model. If solvable, the orchestrator is detached, and token generation is invoked using the base LLM expert. If the problem is difficult and requires a larger model like GPT-4, it produces `<GPT4>` token (i.e., token_id=32000).
12
 
13
+ The Orchestrator is trained to estimate the knowledge of the base model, for any given query, then we marge into the base model (MetaMath7b, here).
14
+ In general for **any domain**, you can build it by:
15
+ - Choose a base LLM expert πŸ€—
16
+ - Train a domain-specific Orchestrator
17
+ - Merge Orchestrator with the base expert
18
+
19
+ <p align="center">
20
+ <img src="train_orch.png" width="300"/>
21
+ </p>
22
+
23
+
24
+ βœ… In evaluations using the [GSM8k dataset](https://huggingface.co/datasets/gsm8k) of [OpenLLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard), Leeroo Math 7b model achieves an accuracy of 84.77% in 5-shot setting, positioning it among the top performers in its class and notably surpassing its base model, which scores 68.84% on the same dataset. This was accomplished while relying on GPT-4 for responses to half of the questions posed by GSM8k.
25
 
26
  ## Sample Usage
27
 
 
52
  # <GPT4></s>
53
  ```
54
 
55
+ You can also add your OpenAI API to get the full answer when `<GPT4>` token is generated:
56
+
57
+ ```python
58
+ from openai import OpenAI
59
+ from transformers import AutoModelForCausalLM, AutoTokenizer
60
+
61
+ model = AutoModelForCausalLM.from_pretrained("leeroo/LeerooDedicated-Math-7B-OOE", trust_remote_code=True)
62
+ tokenizer = AutoTokenizer.from_pretrained("leeroo/LeerooDedicated-Math-7B-OOE")
63
+ openai_client = OpenAI(
64
+ api_key= "OPENAI_API_KEY",
65
+ base_url= "https://api.openai.com/v1"
66
+ )
67
+
68
+ def generate(prompt, tokenizer, model, openai_client, max_new_tokens=100, verbose=True):
69
+ inputs = tokenizer(prompt, return_tensors="pt")
70
+ inputs = {k:v.to(model.device) for k,v in inputs.items()}
71
+ gen_tokens = model.generate( **inputs , max_new_tokens=max_new_tokens, do_sample=False, pad_token_id= tokenizer.pad_token_id)
72
+ if gen_tokens[0, inputs['input_ids'].shape[1]] != tokenizer.unk_token_id:
73
+ if verbose: print("\033[94mGenerating using MetaMath7b.\033[0m")
74
+ gen_text = tokenizer.decode(
75
+ gen_tokens[0, inputs['input_ids'].shape[1]:].tolist() )
76
+ else:
77
+ if verbose: print("\033[94mGenerating using gpt4.\033[0m")
78
+ gen_text = openai_client.completions.create(
79
+ model = "gpt-4-1106-preview", # NOTE you can use any bigger mode here having performance similar to gpt4
80
+ prompt = prompt,
81
+ max_tokens = max_new_tokens,
82
+ temperature = 0.0
83
+ ).choices[0].text
84
+ return gen_text
85
+
86
+ # the following question is answered by the leeroo expert
87
+ prompt = "Question: Natalia sold clips to 48 of her friends in April,and then she sold half as many clips in May.How many clips did Natalia sell altogether in April and May?\nAnswer:"
88
+ generation = generate(prompt, tokenizer, model, openai_client, max_new_tokens=500)
89
+ print(generation)
90
+ #> Generating using MetaMath7b.
91
+ # Natalia sold 48 clips in April.\nIn May, she sold half as many clips as in April,
92
+ # so she sold 48/2 = 24 clips.\nAltogether, Natalia sold 48 + 24 = 72 clips in April and May.\n#### 72\nThe answer is: 72</s>
93
+
94
+ # sends the following question to GPT4
95
+ prompt = "James loves to go swimming and has to swim across a 40-mile lake. He can swim at a pace of 2 miles per hour. He swims 60% of the distance. After that, he stops on an island and rests for half as long as the swimming time. He then finishes the remaining distance while going half the speed. How many hours did it take him to get across the lake?"
96
+ generation = generate(prompt, tokenizer, model, openai_client, max_new_tokens=500)
97
+ print(generation)
98
+ #> Generating using gpt4.
99
+ # He swam 40*.6=24 miles
100
+ # So he swam for 24/2=12 hours
101
+ # He rested for 12/2=6 hours
102
+ # He had 40-24=16 miles left to swim
103
+ # He swam at 2/2=1 mile per hour
104
+ # So he swam for 16/1=16 hours
105
+ # So in total, it took him 12+6+16=34 hours
106
+ # 34
107
+ ```
108
+
109
  ## Learn More
110
 
111
  πŸ” To a deeper dive into our method and results, refer to [HF blog πŸ€—](https://huggingface.co/blog/alirezamsh/leeroo-multi-model-system), [publication](https://arxiv.org/abs/2401.13979), and [repository](https://github.com/Leeroo-AI/leeroo_orchestrator).