GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: Add evaluation section to Gemini docs. Update SDK doc generati… · hamgor/python-aiplatform@9cb0819

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • conf.py
  • gemini_docs
    • README.md
    • conf.py
    • vertexai
      • services.rst
  • noxfile.py
  • setup.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/conf.py‎

Copy file name to clipboardExpand all lines: docs/conf.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def setup(*args, **kwargs):
416416
# 2. Giving pretty class names to the preview classes
417417
# 3. Making Sphinx automodule render the class members instead of
418418
# dismissing the exported private classes as "Alias of".
419+
from vertexai import evaluation
419420
from vertexai import language_models
420421
from vertexai import vision_models
421422
from vertexai.preview import (
@@ -429,6 +430,7 @@ def setup(*args, **kwargs):
429430
# We select the publicly exported members that have an internal module ("*._*").
430431

431432
# Setting the modules of the GA classes
433+
adopt_members_reexported_from_private_modules(evaluation)
432434
adopt_members_reexported_from_private_modules(language_models)
433435
adopt_members_reexported_from_private_modules(vision_models)
434436

Collapse file

‎gemini_docs/README.md‎

Copy file name to clipboardExpand all lines: gemini_docs/README.md
+131Lines changed: 131 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,137 @@ chat = model.start_chat(responder=afc_responder)
175175
print(chat.send_message("What is the weather like in Boston?"))
176176
```
177177

178+
#### Evaluation
179+
180+
- To perform bring-your-own-response(BYOR) evaluation, provide the model responses in the `response` column in the dataset. If a pairwise metric is used for BYOR evaluation, provide the baseline model responses in the `baseline_model_response` column.
181+
182+
```
183+
import pandas as pd
184+
from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples
185+
186+
eval_dataset = pd.DataFrame({
187+
"prompt" : [...],
188+
"reference": [...],
189+
"response" : [...],
190+
"baseline_model_response": [...],
191+
})
192+
eval_task = EvalTask(
193+
dataset=eval_dataset,
194+
metrics=[
195+
"bleu",
196+
"rouge_l_sum",
197+
MetricPromptTemplateExamples.Pointwise.FLUENCY,
198+
MetricPromptTemplateExamples.Pairwise.SAFETY
199+
],
200+
experiment="my-experiment",
201+
)
202+
eval_result = eval_task.evaluate(experiment_run_name="eval-experiment-run")
203+
```
204+
- To perform evaluation with Gemini model inference, specify the `model` parameter with a `GenerativeModel` instance. The input column name to the model is `prompt` and must be present in the dataset.
205+
206+
```
207+
from vertexai.evaluation import EvalTask
208+
from vertexai.generative_models import GenerativeModel
209+
210+
eval_dataset = pd.DataFrame({
211+
"reference": [...],
212+
"prompt" : [...],
213+
})
214+
result = EvalTask(
215+
dataset=eval_dataset,
216+
metrics=["exact_match", "bleu", "rouge_1", "rouge_l_sum"],
217+
experiment="my-experiment",
218+
).evaluate(
219+
model=GenerativeModel("gemini-1.5-pro"),
220+
experiment_run_name="gemini-eval-run"
221+
)
222+
```
223+
224+
- If a `prompt_template` is specified, the `prompt` column is not required. Prompts can be assembled from the evaluation dataset, and all prompt template variable names must be present in the dataset columns.
225+
226+
```
227+
import pandas as pd
228+
from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples
229+
from vertexai.generative_models import GenerativeModel
230+
231+
eval_dataset = pd.DataFrame({
232+
"context" : [...],
233+
"instruction": [...],
234+
})
235+
result = EvalTask(
236+
dataset=eval_dataset,
237+
metrics=[MetricPromptTemplateExamples.Pointwise.SUMMARIZATION_QUALITY],
238+
).evaluate(
239+
model=GenerativeModel("gemini-1.5-pro"),
240+
prompt_template="{instruction}. Article: {context}. Summary:",
241+
)
242+
```
243+
244+
- To perform evaluation with custom model inference, specify the `model`
245+
parameter with a custom inference function. The input column name to the
246+
custom inference function is `prompt` and must be present in the dataset.
247+
248+
```
249+
from openai import OpenAI
250+
from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples
251+
252+
253+
client = OpenAI()
254+
def custom_model_fn(input: str) -> str:
255+
response = client.chat.completions.create(
256+
model="gpt-3.5-turbo",
257+
messages=[
258+
{"role": "user", "content": input}
259+
]
260+
)
261+
return response.choices[0].message.content
262+
263+
eval_dataset = pd.DataFrame({
264+
"prompt" : [...],
265+
"reference": [...],
266+
})
267+
result = EvalTask(
268+
dataset=eval_dataset,
269+
metrics=[MetricPromptTemplateExamples.Pointwise.SAFETY],
270+
experiment="my-experiment",
271+
).evaluate(
272+
model=custom_model_fn,
273+
experiment_run_name="gpt-eval-run"
274+
)
275+
```
276+
277+
- To perform pairwise metric evaluation with model inference step, specify
278+
the `baseline_model` input to a `PairwiseMetric` instance and the candidate
279+
`model` input to the `EvalTask.evaluate()` function. The input column name
280+
to both models is `prompt` and must be present in the dataset.
281+
282+
```
283+
import pandas as pd
284+
from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples, PairwiseMetric
285+
from vertexai.generative_models import GenerativeModel
286+
287+
baseline_model = GenerativeModel("gemini-1.0-pro")
288+
candidate_model = GenerativeModel("gemini-1.5-pro")
289+
290+
pairwise_groundedness = PairwiseMetric(
291+
metric_prompt_template=MetricPromptTemplateExamples.get_prompt_template(
292+
"pairwise_groundedness"
293+
),
294+
baseline_model=baseline_model,
295+
)
296+
eval_dataset = pd.DataFrame({
297+
"prompt" : [...],
298+
})
299+
result = EvalTask(
300+
dataset=eval_dataset,
301+
metrics=[pairwise_groundedness],
302+
experiment="my-pairwise-experiment",
303+
).evaluate(
304+
model=candidate_model,
305+
experiment_run_name="gemini-pairwise-eval-run",
306+
)
307+
```
308+
178309
## Documentation
179310

180311
You can find complete documentation for the Vertex AI SDKs and the Gemini model in the Google Cloud [documentation](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview)
Collapse file

‎gemini_docs/conf.py‎

Copy file name to clipboardExpand all lines: gemini_docs/conf.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def setup(*args, **kwargs):
416416
# 2. Giving pretty class names to the preview classes
417417
# 3. Making Sphinx automodule render the class members instead of
418418
# dismissing the exported private classes as "Alias of".
419+
from vertexai import evaluation
419420
from vertexai import language_models
420421
from vertexai import vision_models
421422
from vertexai.preview import (
@@ -429,6 +430,7 @@ def setup(*args, **kwargs):
429430
# We select the publicly exported members that have an internal module ("*._*").
430431

431432
# Setting the modules of the GA classes
433+
adopt_members_reexported_from_private_modules(evaluation)
432434
adopt_members_reexported_from_private_modules(language_models)
433435
adopt_members_reexported_from_private_modules(vision_models)
434436

Collapse file

‎gemini_docs/vertexai/services.rst‎

Copy file name to clipboardExpand all lines: gemini_docs/vertexai/services.rst
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Vertex AI SDK
4545
:show-inheritance:
4646
:inherited-members:
4747

48-
.. automodule:: vertexai.preview.evaluation
48+
.. automodule:: vertexai.evaluation
4949
:members:
5050
:show-inheritance:
5151
:inherited-members:
Collapse file

‎noxfile.py‎

Copy file name to clipboardExpand all lines: noxfile.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ def docs(session):
351351
session.install(
352352
"sphinx==5.0.2",
353353
"alabaster",
354+
"immutabledict",
355+
"google-cloud-aiplatform[evaluation]",
354356
"google-cloud-aiplatform[prediction]",
355357
"recommonmark",
356358
)
@@ -420,6 +422,8 @@ def gemini_docs(session):
420422
session.install(
421423
"sphinx==5.0.2",
422424
"alabaster",
425+
"immutabledict",
426+
"google-cloud-aiplatform[evaluation]",
423427
"google-cloud-aiplatform[prediction]",
424428
"recommonmark",
425429
)
Collapse file

‎setup.py‎

Copy file name to clipboardExpand all lines: setup.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
evaluation_extra_require = [
153153
"pandas >= 1.0.0, < 2.2.0",
154154
"tqdm>=4.23.0",
155+
"immutabledict",
155156
]
156157

157158
langchain_extra_require = [

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.