|
14 | 14 |
|
15 | 15 |
|
16 | 16 | def text_summarization( |
17 | | - temperature: float, |
18 | 17 | project_id: str, |
19 | | - location: str, |
20 | 18 | ) -> str: |
21 | 19 | """Summarization Example with a Large Language Model""" |
22 | 20 | # [START aiplatform_sdk_summarization] |
23 | 21 | import vertexai |
24 | 22 | from vertexai.language_models import TextGenerationModel |
25 | 23 |
|
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 | + |
28 | 29 | 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, |
33 | 34 | } |
34 | 35 |
|
35 | 36 | model = TextGenerationModel.from_pretrained("text-bison@002") |
36 | 37 | response = model.predict( |
37 | 38 | """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:""", |
68 | 68 | **parameters, |
69 | 69 | ) |
70 | 70 | print(f"Response from Model: {response.text}") |
71 | 71 | # [END aiplatform_sdk_summarization] |
72 | 72 |
|
73 | 73 | return response.text |
74 | | - |
75 | | - |
76 | | -if __name__ == "__main__": |
77 | | - text_summarization() |
0 commit comments