Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a773f80

Browse files
authored
fix(generative-ai): temperature is not defined in the sample (GoogleCloudPlatform#11790)
1 parent 5ebfde8 commit a773f80

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

generative_ai/summarization.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,60 @@
1414

1515

1616
def text_summarization(
17-
temperature: float,
1817
project_id: str,
19-
location: str,
2018
) -> str:
2119
"""Summarization Example with a Large Language Model"""
2220
# [START aiplatform_sdk_summarization]
2321
import vertexai
2422
from vertexai.language_models import TextGenerationModel
2523

26-
# TODO(developer): update project_id, location & temperature
27-
vertexai.init(project=project_id, location=location)
24+
# TODO(developer): Update and un-comment below line
25+
# project_id = "PROJECT_ID"
26+
27+
vertexai.init(project=project_id, location="us-central1")
28+
2829
parameters = {
29-
"temperature": temperature, # Temperature controls the degree of randomness in token selection.
30-
"max_output_tokens": 256, # Token limit determines the maximum amount of text output.
31-
"top_p": 0.95, # Tokens are selected from most probable to least until the sum of their probabilities equals the top_p value.
32-
"top_k": 40, # A top_k of 1 means the selected token is the most probable among all tokens.
30+
"temperature": 0,
31+
"max_output_tokens": 256,
32+
"top_p": 0.95,
33+
"top_k": 40,
3334
}
3435

3536
model = TextGenerationModel.from_pretrained("text-bison@002")
3637
response = model.predict(
3738
"""Provide a summary with about two sentences for the following article:
38-
The efficient-market hypothesis (EMH) is a hypothesis in financial \
39-
economics that states that asset prices reflect all available \
40-
information. A direct implication is that it is impossible to \
41-
"beat the market" consistently on a risk-adjusted basis since market \
42-
prices should only react to new information. Because the EMH is \
43-
formulated in terms of risk adjustment, it only makes testable \
44-
predictions when coupled with a particular model of risk. As a \
45-
result, research in financial economics since at least the 1990s has \
46-
focused on market anomalies, that is, deviations from specific \
47-
models of risk. The idea that financial market returns are difficult \
48-
to predict goes back to Bachelier, Mandelbrot, and Samuelson, but \
49-
is closely associated with Eugene Fama, in part due to his \
50-
influential 1970 review of the theoretical and empirical research. \
51-
The EMH provides the basic logic for modern risk-based theories of \
52-
asset prices, and frameworks such as consumption-based asset pricing \
53-
and intermediary asset pricing can be thought of as the combination \
54-
of a model of risk with the EMH. Many decades of empirical research \
55-
on return predictability has found mixed evidence. Research in the \
56-
1950s and 1960s often found a lack of predictability (e.g. Ball and \
57-
Brown 1968; Fama, Fisher, Jensen, and Roll 1969), yet the \
58-
1980s-2000s saw an explosion of discovered return predictors (e.g. \
59-
Rosenberg, Reid, and Lanstein 1985; Campbell and Shiller 1988; \
60-
Jegadeesh and Titman 1993). Since the 2010s, studies have often \
61-
found that return predictability has become more elusive, as \
62-
predictability fails to work out-of-sample (Goyal and Welch 2008), \
63-
or has been weakened by advances in trading technology and investor \
64-
learning (Chordia, Subrahmanyam, and Tong 2014; McLean and Pontiff \
65-
2016; Martineau 2021).
66-
Summary:
67-
""",
39+
The efficient-market hypothesis (EMH) is a hypothesis in financial \
40+
economics that states that asset prices reflect all available \
41+
information. A direct implication is that it is impossible to \
42+
"beat the market" consistently on a risk-adjusted basis since market \
43+
prices should only react to new information. Because the EMH is \
44+
formulated in terms of risk adjustment, it only makes testable \
45+
predictions when coupled with a particular model of risk. As a \
46+
result, research in financial economics since at least the 1990s has \
47+
focused on market anomalies, that is, deviations from specific \
48+
models of risk. The idea that financial market returns are difficult \
49+
to predict goes back to Bachelier, Mandelbrot, and Samuelson, but \
50+
is closely associated with Eugene Fama, in part due to his \
51+
influential 1970 review of the theoretical and empirical research. \
52+
The EMH provides the basic logic for modern risk-based theories of \
53+
asset prices, and frameworks such as consumption-based asset pricing \
54+
and intermediary asset pricing can be thought of as the combination \
55+
of a model of risk with the EMH. Many decades of empirical research \
56+
on return predictability has found mixed evidence. Research in the \
57+
1950s and 1960s often found a lack of predictability (e.g. Ball and \
58+
Brown 1968; Fama, Fisher, Jensen, and Roll 1969), yet the \
59+
1980s-2000s saw an explosion of discovered return predictors (e.g. \
60+
Rosenberg, Reid, and Lanstein 1985; Campbell and Shiller 1988; \
61+
Jegadeesh and Titman 1993). Since the 2010s, studies have often \
62+
found that return predictability has become more elusive, as \
63+
predictability fails to work out-of-sample (Goyal and Welch 2008), \
64+
or has been weakened by advances in trading technology and investor \
65+
learning (Chordia, Subrahmanyam, and Tong 2014; McLean and Pontiff \
66+
2016; Martineau 2021).
67+
Summary:""",
6868
**parameters,
6969
)
7070
print(f"Response from Model: {response.text}")
7171
# [END aiplatform_sdk_summarization]
7272

7373
return response.text
74-
75-
76-
if __name__ == "__main__":
77-
text_summarization()

generative_ai/summarization_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121

2222

2323
_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
24-
_LOCATION = "us-central1"
2524

2625

2726
expected_response = """The efficient-market hypothesis"""
2827

2928

3029
@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10)
3130
def test_text_summarization() -> None:
32-
content = summarization.text_summarization(
33-
temperature=0, project_id=_PROJECT_ID, location=_LOCATION
34-
)
31+
content = summarization.text_summarization(project_id=_PROJECT_ID)
3532
assert expected_response in content

0 commit comments

Comments
 (0)