Views
No views yet
1# load dataset
2dataset_1 = load_dataset("gbharti/finance-alpaca")
3dataset_2 = load_dataset("PaulAdversarial/all_news_finance_sm_1h2023")
4dataset_3 = load_dataset("winddude/reddit_finance_43_250k")
5dataset_4 = load_dataset("causal-lm/finance")
6
7# create a column called text
8dataset_1 = dataset_1.map(
9 lambda example: {"text": example["instruction"] + " " + example["output"]},
10 num_proc=4,
11)
12dataset_1 = dataset_1.remove_columns(["input", "instruction", "output"])
13
14dataset_2 = dataset_2.map(
15 lambda example: {"text": example["title"] + " " + example["description"]},
16 num_proc=4,
17)
18dataset_2 = dataset_2.remove_columns(
19 ["_id", "main_domain", "title", "description", "created_at"]
20)
21
22dataset_3 = dataset_3.map(
23 lambda example: {
24 "text": example["title"] + " " + example["selftext"] + " " + example["body"]
25 },
26 num_proc=4,
27)
28dataset_3 = dataset_3.remove_columns(
29 [
30 "id",
31 "title",
32 "selftext",
33 "z_score",
34 "normalized_score",
35 "subreddit",
36 "body",
37 "comment_normalized_score",
38 "combined_score",
39 ]
40)
41
42dataset_4 = dataset_4.map(
43 lambda example: {"text": example["instruction"] + " " + example["output"]},
44 num_proc=4,
45)
46dataset_4 = dataset_4.remove_columns(["input", "instruction", "output"])
47
48# combine and split train test sets
49combined_dataset = concatenate_datasets(
50 [
51 dataset_1["train"],
52 dataset_2["train"],
53 dataset_3["train"],
54 dataset_4["train"],
55 dataset_4["validation"],
56 ]
57)
58
59datasets = combined_dataset.train_test_split(test_size=0.2)
601from transformers import pipeline
2
3generator = pipeline(model="lxyuan/distilgpt2-finetuned-finance")
4
5generator("Tesla is",
6 pad_token_id=generator.tokenizer.eos_token_id,
7 max_new_tokens=200,
8 num_return_sequences=2
9)
10
11>>>
12{'generated_text':
13 'Tesla is likely going to have a "market crash" over 20 years - I believe I\'m just not
14 sure how this is going to affect the world. \n\nHowever, I would like to see this play out
15 as a global financial crisis. With US interest rates already high, a crash in global real
16 estate prices means that people are likely to feel pressure on assets that are less well
17 served by the assets the US government gives them. \n\nWould these things help you in your
18 retirement? I\'m fairly new to Wall Street, and it makes me think that you should have a
19 bit more control over your assets (I’m not super involved in stock picking, but I’ve heard
20 many times that governments can help their citizens), right? As another commenter has put
21 it: there\'s something called a market crash that could occur in the second world country
22 for most markets (I don\'t know how that would fit under US laws if I had done all of the
23 above. \n\n'
24},
25{'generated_text':
26 "Tesla is on track to go from 1.46 to 1.79 per cent growth in Q3 (the fastest pace so far
27in the US), which will push down the share price.\n\nWhile the dividend could benefit Amazon’s
28growth, earnings also aren’t expected to be high at all, the company's annual earnings could
29be an indication that investors have a strong plan to boost sales by the end of the year if
30earnings season continues.\n\nThe latest financials showed earnings as of the end of July,
31followed by the earnings guidance from analysts at the Canadian Real Estate Association, which
32showed that Amazon’s revenues were up over $1.8 Trillion, which is a far cry from what was
33expected in early Q1.\n\nAmazon has grown the share price by as much as 1.6 percent since June
342020. Analysts had predicted that earnings growth in the stock would drop to 0.36 per cent for
352020, which would lead to Amazon’"
36}