Views
No views yet
| Task | # Filt. Traj. | Avg # Filt. Traj. Turns |
|---|---|---|
| ALFWorld | 336 | 13.52 |
| WebShop | 351 | 3.68 |
| Mind2Web | 122 | 1.00 |
| Knowledge Graph | 324 | 6.04 |
| Operating System | 195 | 3.85 |
| Database | 538 | 2.06 |
| AgentInstruct | 1866 | 5.24 |
1from transformers import AutoTokenizer, AutoModelForCausalLM, StoppingCriteria
2import torch
3
4# Load tokenizer and model
5tokenizer = AutoTokenizer.from_pretrained("mrm8488/mistral-7b-ft-AgentInstruct")
6model = AutoModelForCausalLM.from_pretrained("mrm8488/mistral-7b-ft-AgentInstruct").to("cuda")
7
8class MyStoppingCriteria(StoppingCriteria):
9 def __init__(self, target_sequence, prompt):
10 self.target_sequence = target_sequence
11 self.prompt = prompt
12
13 def __call__(self, input_ids, scores, **kwargs):
14 # Decode without prompt and check for target sequence
15 generated_text = tokenizer.decode(input_ids[0]).replace(self.prompt, '')
16 return self.target_sequence in generated_text
17
18 def __len__(self):
19 return 1
20
21def generate(context, max_new_tokens=256, min_new_tokens=64, temperature=0.3, top_p=0.75, top_k=40, do_sample=True, num_beams=2):
22 # Prepare input data
23 inputs = tokenizer(context, return_tensors="pt")
24 input_ids = inputs["input_ids"].to("cuda")
25 attention_mask = inputs["attention_mask"].to("cuda")
26
27 # Generation settings
28 generation_settings = {
29 "max_new_tokens": max_new_tokens,
30 "min_new_tokens": min_new_tokens,
31 "temperature": temperature,
32 "top_p": top_p,
33 "top_k": top_k,
34 "do_sample": do_sample,
35 "num_beams": num_beams,
36 "early_stopping": False,
37 "use_cache": True,
38 "stopping_criteria": MyStoppingCriteria("### human:", context)
39 }
40
41 # Generate response
42 with torch.no_grad():
43 generation_output = model.generate(input_ids, attention_mask, **generation_settings)
44
45 output = tokenizer.decode(generation_output.sequences[0])
46 return output
47
48# Example usage
49context = ""
50human = """### human: Among the reference ID of under 10 who got response by marketing department, compare their education status.
51There are 2 tables involved with this task. The name of the 1st table is Customers, and the headers of this table are ID,SEX,MARITAL_STATUS,GEOID,EDUCATIONNUM,OCCUPATION,age. The name of the 2nd table is Mailings1_2, and the headers of this table are REFID,REF_DATE,RESPONSE."""
52context = human
53
54solution = generate(context)
55print(solution)1@misc {manuel_romero_2024,
2 author = { {Manuel Romero} },
3 title = { mistral-7b-ft-AgentInstruct (Revision 463b96d) },
4 year = 2024,
5 url = { https://huggingface.co/mrm8488/mistral-7b-ft-AgentInstruct },
6 doi = { 10.57967/hf/1650 },
7 publisher = { Hugging Face }
8}