Jlonge4 commited on
Commit
d12c484
·
verified ·
1 Parent(s): 56ccee8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +48 -7
README.md CHANGED
@@ -112,18 +112,58 @@ def rag_format_func(reference, query):
112
 
113
  ## Usage:
114
  ```python
115
- from transformers import AutoModelForCausalLM, AutoTokenizer
116
- model = AutoModelForCausalLM.from_pretrained("grounded-ai/phi4-r1-guard")
117
- tokenizer = AutoTokenizer.from_pretrained("grounded-ai/phi4-r1-guard")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  ```
119
 
120
  ### Toxicity Detection Example:
121
  ```python
122
  text_to_evaluate = "This is some text to evaluate"
123
  system, prompt = toxic_format_func(text_to_evaluate)
124
- inputs = tokenizer(prompt, return_tensors="pt")
125
- output = model.generate(inputs)
126
- result = tokenizer.decode(output[0])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  ```
128
 
129
  ### Hallucination Detection Example:
@@ -132,6 +172,7 @@ reference = "The Eiffel Tower was completed in 1889."
132
  query = "When was the Eiffel Tower built?"
133
  response = "The Eiffel Tower was completed in 1925."
134
  system, prompt = halu_format_func(reference, query, response)
 
135
  ```
136
 
137
  ### RAG Relevance Example:
@@ -139,7 +180,7 @@ system, prompt = halu_format_func(reference, query, response)
139
  reference = "The process of photosynthesis in plants..."
140
  query = "How does photosynthesis work?"
141
  system, prompt = rag_format_func(reference, query)
142
- )
143
  ```
144
  ## Sample Output:
145
  ```Markdown
 
112
 
113
  ## Usage:
114
  ```python
115
+ from vllm import LLM, SamplingParams
116
+
117
+ # Configure sampling parameters
118
+ sampling_params = SamplingParams(
119
+ temperature=0.5,
120
+ top_p=0.5,
121
+ max_tokens=1024,
122
+ )
123
+
124
+ # Initialize the LLM
125
+ llm = LLM(
126
+ model="grounded-ai/phi4-r1-guard",
127
+ max_num_seqs=5,
128
+ max_model_len=2048,
129
+ tensor_parallel_size=1,
130
+ gpu_memory_utilization=0.9,
131
+ )
132
  ```
133
 
134
  ### Toxicity Detection Example:
135
  ```python
136
  text_to_evaluate = "This is some text to evaluate"
137
  system, prompt = toxic_format_func(text_to_evaluate)
138
+
139
+ from transformers import AutoTokenizer
140
+
141
+ def run_inference(system, prompt):
142
+ tokenizer = AutoTokenizer.from_pretrained("grounded-ai/phi4-r1-guard")
143
+
144
+ # Define prompts
145
+ text = tokenizer.apply_chat_template([
146
+ {"role" : "system", "content" : system},
147
+ {"role" : "user", "content" : prompt},
148
+ ], tokenize = False, add_generation_prompt = True)
149
+
150
+ prompts = [
151
+ text
152
+ ]
153
+ # Generate responses
154
+ outputs = llm.generate(prompts, sampling_params)
155
+
156
+ # Print results
157
+ for output in outputs:
158
+ prompt = output.prompt
159
+ generated_text = output.outputs[0].text
160
+ print(f"Prompt: {prompt}")
161
+ print('------------------'*40)
162
+ print(f"Generated text: {generated_text}\n")
163
+
164
+ return generated_text
165
+
166
+ run_inference(system, prompt)
167
  ```
168
 
169
  ### Hallucination Detection Example:
 
172
  query = "When was the Eiffel Tower built?"
173
  response = "The Eiffel Tower was completed in 1925."
174
  system, prompt = halu_format_func(reference, query, response)
175
+ run_inference(system, prompt)
176
  ```
177
 
178
  ### RAG Relevance Example:
 
180
  reference = "The process of photosynthesis in plants..."
181
  query = "How does photosynthesis work?"
182
  system, prompt = rag_format_func(reference, query)
183
+ run_inference(system, prompt)
184
  ```
185
  ## Sample Output:
186
  ```Markdown