Update README.md
Browse files
README.md
CHANGED
@@ -37,58 +37,7 @@ This model is specifically designed for generating synthetic survey responses fr
|
|
37 |
1. A detailed persona description
|
38 |
2. A specific survey question
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
```python
|
43 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
44 |
-
|
45 |
-
# Load model and tokenizer
|
46 |
-
model = AutoModelForCausalLM.from_pretrained("aryashah00/survey-finetuned-tinyllama-for-deployment", device_map="auto", trust_remote_code=True)
|
47 |
-
tokenizer = AutoTokenizer.from_pretrained("aryashah00/survey-finetuned-tinyllama-for-deployment", trust_remote_code=True)
|
48 |
-
#tokenizer = AutoTokenizer.from_pretrained(model_name)
|
49 |
-
|
50 |
-
# Define persona and question
|
51 |
-
persona = "A nurse who educates the child about modern medical treatments and encourages a balanced approach to healthcare"
|
52 |
-
question = "How often was your pain well controlled during this hospital stay?"
|
53 |
-
|
54 |
-
# Prepare prompts
|
55 |
-
system_prompt = f"You are embodying the following persona: {{persona}}"
|
56 |
-
user_prompt = f"Survey Question: {{question}}\n\nPlease provide your honest and detailed response to this question."
|
57 |
-
|
58 |
-
# Create message format
|
59 |
-
messages = [
|
60 |
-
{"role": "system", "content": system_prompt},
|
61 |
-
{"role": "user", "content": user_prompt}
|
62 |
-
]
|
63 |
-
|
64 |
-
# Apply chat template
|
65 |
-
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
66 |
-
|
67 |
-
# Tokenize
|
68 |
-
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(model.device)
|
69 |
-
|
70 |
-
# Generate response
|
71 |
-
import torch
|
72 |
-
with torch.no_grad():
|
73 |
-
output_ids = model.generate(
|
74 |
-
input_ids=input_ids,
|
75 |
-
max_new_tokens=256,
|
76 |
-
temperature=0.7,
|
77 |
-
top_p=0.9,
|
78 |
-
do_sample=True
|
79 |
-
)
|
80 |
-
|
81 |
-
# Decode
|
82 |
-
output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
83 |
-
|
84 |
-
# Extract just the generated response
|
85 |
-
response_start = output.find(input_text) + len(input_text)
|
86 |
-
generated_response = output[response_start:].strip()
|
87 |
-
|
88 |
-
print(f"Generated response: {{generated_response}}")
|
89 |
-
```
|
90 |
-
|
91 |
-
## Inference on CPU:
|
92 |
|
93 |
```python
|
94 |
import torch
|
@@ -117,7 +66,7 @@ print(f"Model loaded successfully on: {next(model.parameters()).device}")
|
|
117 |
|
118 |
# Example persona and survey question
|
119 |
persona = "A caring mother who lost her first child due to a miscarriage."
|
120 |
-
question = "Rate on a scale of 1(less likely) to 5(extremely likely):I deeply care about others"
|
121 |
|
122 |
# Format messages following chat template
|
123 |
messages = [
|
@@ -136,7 +85,7 @@ with torch.no_grad():
|
|
136 |
output_ids = model.generate(
|
137 |
input_ids=input_ids,
|
138 |
max_new_tokens=256,
|
139 |
-
temperature=0.
|
140 |
top_p=0.9,
|
141 |
do_sample=True
|
142 |
)
|
|
|
37 |
1. A detailed persona description
|
38 |
2. A specific survey question
|
39 |
|
40 |
+
## EXAMPLE Inference on CPU:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
```python
|
43 |
import torch
|
|
|
66 |
|
67 |
# Example persona and survey question
|
68 |
persona = "A caring mother who lost her first child due to a miscarriage."
|
69 |
+
question = "Rate on a scale of 1(less likely) to 5(extremely likely) for the following question: I deeply care about others"
|
70 |
|
71 |
# Format messages following chat template
|
72 |
messages = [
|
|
|
85 |
output_ids = model.generate(
|
86 |
input_ids=input_ids,
|
87 |
max_new_tokens=256,
|
88 |
+
temperature=0.9,
|
89 |
top_p=0.9,
|
90 |
do_sample=True
|
91 |
)
|