wangkevin02 commited on
Commit
d7ebba9
·
verified ·
1 Parent(s): ed6d82d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +90 -82
README.md CHANGED
@@ -1,82 +1,90 @@
1
- # User Simulator Model
2
-
3
- ## Overview
4
-
5
- Our User Simulator with Implicit Profiles (USP) replicates human-like conversational behavior in interactions with large language models (LLMs). By emulating diverse user dynamics based on predefined profiles, it reconstructs realistic user-LLM dialogues, leveraging the LLaMA-3-base-8B architecture with **Conditional Supervised Fine-Tuning (SFT)** and **Reinforcement Learning with Cycle Consistency (RLCC)**. For a detailed methodology and insights, refer to [Our Paper](#).
6
-
7
- ## Constraints
8
-
9
- 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.
10
-
11
- 1. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.
12
-
13
-
14
- ## Sample Implementation
15
-
16
- Below is a concise example of using the User Simulator to generate user utterances, ideal for recreating scenarios or evaluating multi-turn dialogues based on specific profiles.
17
-
18
- ```python
19
- import torch
20
- from transformers import AutoTokenizer, AutoModelForCausalLM
21
- # Define the model path
22
- model_path = "/your/path/to/USP"
23
-
24
- # Initialize tokenizer with specific configurations
25
- tokenizer = AutoTokenizer.from_pretrained(model_path, padding_side="left", trust_remote_code=True)
26
- tokenizer.pad_token = tokenizer.eos_token
27
-
28
- # Define model configuration
29
- model_config = {
30
- "pretrained_model_name_or_path": model_path,
31
- "trust_remote_code": True,
32
- "torch_dtype": torch.bfloat16,
33
- "device_map": "cuda",
34
- "attn_implementation": "flash_attention_2"
35
- }
36
-
37
- # Load the pre-trained model with specified configurations
38
- model = AutoModelForCausalLM.from_pretrained(**model_config)
39
- model.eval()
40
-
41
- # Define conversation messages
42
- messages = [
43
- [
44
- {"role": "system", "content": "You are engaging in a conversation with an AI assistant. Your profile is: \nYou have a knack for planning exciting adventures, particularly when it comes to exploring new destinations on a budget. Your current focus is on organizing a cost-effective vacation to a warm, beach-filled location. You're actively seeking recommendations for such a getaway, with a particular interest in places like Phuket, Thailand. You're keen on discovering the must-visit spots in Phuket without breaking the bank, and you're looking for advice on how to make the most of your trip within your budget constraints. Your love for travel is evident in your habit of meticulously planning vacations in advance, ensuring you maximize both the experience and the value for money.\n\nYour personality shines through in your conscientious approach to planning, where every detail is considered and nothing is left to chance. You're open-minded and adventurous, always eager to dive into new experiences and embrace what each destination has to offer. Your inquisitive nature means you're always asking questions, seeking out the best advice to enhance your journeys. You communicate with an informal and friendly style, making it easy for others to share their knowledge and insights with you. This combination of traits makes you not only a savvy traveler but also a delightful companion on any adventure.\n You can say anything you want, either based on the profile or something brand new.\n\n"},
45
- ],
46
- [
47
- {"role": "system", "content": "You are engaging in a conversation with an AI assistant. Your profile is: \nYou have a knack for planning exciting adventures, particularly when it comes to exploring new destinations on a budget. Your current focus is on organizing a cost-effective vacation to a warm, beach-filled location. You're actively seeking recommendations for such a getaway, with a particular interest in places like Phuket, Thailand. You're keen on discovering the must-visit spots in Phuket without breaking the bank, and you're looking for advice on how to make the most of your trip within your budget constraints. Your love for travel is evident in your habit of meticulously planning vacations in advance, ensuring you maximize both the experience and the value for money.\n\nYour personality shines through in your conscientious approach to planning, where every detail is considered and nothing is left to chance. You're open-minded and adventurous, always eager to dive into new experiences and embrace what each destination has to offer. Your inquisitive nature means you're always asking questions, seeking out the best advice to enhance your journeys. You communicate with an informal and friendly style, making it easy for others to share their knowledge and insights with you. This combination of traits makes you not only a savvy traveler but also a delightful companion on any adventure.\n You can say anything you want, either based on the profile or something brand new.\n\n"},
48
- {"role": "user", "content": "I want to go on vacation to a warm place. Do you have any recommendations?"},
49
- {"role": "assistant", "content": "Sure! If you like beaches, Maldives or Bali are great options. If you're into culture, consider Tuscany in Italy or Santorini in Greece. Which type of destination do you prefer?"},
50
- ]
51
-
52
- ]
53
-
54
-
55
- def generated_user_utt(msgs, model, tokenizer):
56
- with torch.no_grad():
57
- input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
58
- inputs = tokenizer.batch_encode_plus(input_text, return_tensors="pt", truncation=True, padding=True, max_length=4096).to(model.device)
59
- input_ids = inputs["input_ids"]
60
- outputs = model.generate(
61
- **inputs,
62
- pad_token_id=tokenizer.eos_token_id,
63
- eos_token_id=tokenizer.eos_token_id,
64
- max_new_tokens=4096,
65
- repetition_penalty=1.2)
66
- generated_ids = [
67
- output[len(input_):]
68
- for input_, output in zip(input_ids, outputs)
69
- ]
70
- response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
71
- return response
72
-
73
- # Generate responses for the provided messages
74
- responses = generated_user_utt(messages, model, tokenizer)
75
- print(f"Generated response: {responses}")
76
-
77
- # >>> Expected Output:
78
- # >>> ['I am thinking about going away for vacation', 'How about phucket thailand']
79
- # >>> The first output initiates a topic based on the system-defined user profile.
80
- # >>> The second output extends the conversation based on the given profile and context to mimic the user's behavior.
81
- ```
82
-
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - wangkevin02/LMSYS-USP
5
+ language:
6
+ - en
7
+ base_model:
8
+ - meta-llama/Meta-Llama-3-8B
9
+ ---
10
+ # User Simulator Model
11
+
12
+ ## Overview
13
+
14
+ Our User Simulator with Implicit Profiles (USP) replicates human-like conversational behavior in interactions with large language models (LLMs). By emulating diverse user dynamics based on predefined profiles, it reconstructs realistic user-LLM dialogues, leveraging the LLaMA-3-base-8B architecture with **Conditional Supervised Fine-Tuning (SFT)** and **Reinforcement Learning with Cycle Consistency (RLCC)**. For a detailed methodology and insights, refer to [Our Paper](#).
15
+
16
+ ## Constraints
17
+
18
+ 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.
19
+
20
+ 1. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.
21
+
22
+
23
+ ## Sample Implementation
24
+
25
+ Below is a concise example of using the User Simulator to generate user utterances, ideal for recreating scenarios or evaluating multi-turn dialogues based on specific profiles.
26
+
27
+ ```python
28
+ import torch
29
+ from transformers import AutoTokenizer, AutoModelForCausalLM
30
+ # Define the model path
31
+ model_path = "/your/path/to/USP"
32
+
33
+ # Initialize tokenizer with specific configurations
34
+ tokenizer = AutoTokenizer.from_pretrained(model_path, padding_side="left", trust_remote_code=True)
35
+ tokenizer.pad_token = tokenizer.eos_token
36
+
37
+ # Define model configuration
38
+ model_config = {
39
+ "pretrained_model_name_or_path": model_path,
40
+ "trust_remote_code": True,
41
+ "torch_dtype": torch.bfloat16,
42
+ "device_map": "cuda",
43
+ "attn_implementation": "flash_attention_2"
44
+ }
45
+
46
+ # Load the pre-trained model with specified configurations
47
+ model = AutoModelForCausalLM.from_pretrained(**model_config)
48
+ model.eval()
49
+
50
+ # Define conversation messages
51
+ messages = [
52
+ [
53
+ {"role": "system", "content": "You are engaging in a conversation with an AI assistant. Your profile is: \nYou have a knack for planning exciting adventures, particularly when it comes to exploring new destinations on a budget. Your current focus is on organizing a cost-effective vacation to a warm, beach-filled location. You're actively seeking recommendations for such a getaway, with a particular interest in places like Phuket, Thailand. You're keen on discovering the must-visit spots in Phuket without breaking the bank, and you're looking for advice on how to make the most of your trip within your budget constraints. Your love for travel is evident in your habit of meticulously planning vacations in advance, ensuring you maximize both the experience and the value for money.\n\nYour personality shines through in your conscientious approach to planning, where every detail is considered and nothing is left to chance. You're open-minded and adventurous, always eager to dive into new experiences and embrace what each destination has to offer. Your inquisitive nature means you're always asking questions, seeking out the best advice to enhance your journeys. You communicate with an informal and friendly style, making it easy for others to share their knowledge and insights with you. This combination of traits makes you not only a savvy traveler but also a delightful companion on any adventure.\n You can say anything you want, either based on the profile or something brand new.\n\n"},
54
+ ],
55
+ [
56
+ {"role": "system", "content": "You are engaging in a conversation with an AI assistant. Your profile is: \nYou have a knack for planning exciting adventures, particularly when it comes to exploring new destinations on a budget. Your current focus is on organizing a cost-effective vacation to a warm, beach-filled location. You're actively seeking recommendations for such a getaway, with a particular interest in places like Phuket, Thailand. You're keen on discovering the must-visit spots in Phuket without breaking the bank, and you're looking for advice on how to make the most of your trip within your budget constraints. Your love for travel is evident in your habit of meticulously planning vacations in advance, ensuring you maximize both the experience and the value for money.\n\nYour personality shines through in your conscientious approach to planning, where every detail is considered and nothing is left to chance. You're open-minded and adventurous, always eager to dive into new experiences and embrace what each destination has to offer. Your inquisitive nature means you're always asking questions, seeking out the best advice to enhance your journeys. You communicate with an informal and friendly style, making it easy for others to share their knowledge and insights with you. This combination of traits makes you not only a savvy traveler but also a delightful companion on any adventure.\n You can say anything you want, either based on the profile or something brand new.\n\n"},
57
+ {"role": "user", "content": "I want to go on vacation to a warm place. Do you have any recommendations?"},
58
+ {"role": "assistant", "content": "Sure! If you like beaches, Maldives or Bali are great options. If you're into culture, consider Tuscany in Italy or Santorini in Greece. Which type of destination do you prefer?"},
59
+ ]
60
+
61
+ ]
62
+
63
+
64
+ def generated_user_utt(msgs, model, tokenizer):
65
+ with torch.no_grad():
66
+ input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67
+ inputs = tokenizer.batch_encode_plus(input_text, return_tensors="pt", truncation=True, padding=True, max_length=4096).to(model.device)
68
+ input_ids = inputs["input_ids"]
69
+ outputs = model.generate(
70
+ **inputs,
71
+ pad_token_id=tokenizer.eos_token_id,
72
+ eos_token_id=tokenizer.eos_token_id,
73
+ max_new_tokens=4096,
74
+ repetition_penalty=1.2)
75
+ generated_ids = [
76
+ output[len(input_):]
77
+ for input_, output in zip(input_ids, outputs)
78
+ ]
79
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
80
+ return response
81
+
82
+ # Generate responses for the provided messages
83
+ responses = generated_user_utt(messages, model, tokenizer)
84
+ print(f"Generated response: {responses}")
85
+
86
+ # >>> Expected Output:
87
+ # >>> ['I am thinking about going away for vacation', 'How about phucket thailand']
88
+ # >>> The first output initiates a topic based on the system-defined user profile.
89
+ # >>> The second output extends the conversation based on the given profile and context to mimic the user's behavior.
90
+ ```