File size: 1,961 Bytes
9acfa79
 
6dcd279
 
 
 
 
 
 
 
 
 
 
 
e94c674
 
 
 
 
6dcd279
 
 
 
 
e94c674
 
9acfa79
6b546f5
 
 
 
8250767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
license: mit
dataset_info:
  features:
  - name: input
    dtype: string
  - name: output
    dtype: string
  - name: instruction
    dtype: string
  splits:
  - name: train
    num_bytes: 1906560
    num_examples: 9543
  - name: validation
    num_bytes: 479540
    num_examples: 2388
  download_size: 728648
  dataset_size: 2386100
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
  - split: validation
    path: data/validation-*
---

[zeroshot/twitter-financial-news-sentiment](https://huggingface.co/datasets/zeroshot/twitter-financial-news-sentiment) prepared for LLM fine-tuning
by adding an `instruction` column and mapping the label from numeric to string (`{0:"negative", 1:'positive', 2:'neutral'}`).

[Source](https://github.com/AI4Finance-Foundation/FinGPT/blob/master/fingpt/FinGPT-v3/data/making_data.ipynb)
```python
from datasets import load_dataset
import datasets

from huggingface_hub import notebook_login
notebook_login()

ds = load_dataset('zeroshot/twitter-financial-news-sentiment')

num_to_label = {
    0: 'negative',
    1: 'positive',
    2: 'neutral',
}

instruction = 'What is the sentiment of this tweet? Please choose an answer from {negative/neutral/positive}.'

# Training split

ds_train = ds['train']
ds_train = ds_train.to_pandas()
ds_train['label'] = ds_train['label'].apply(num_to_label.get)
ds_train['instruction'] = instruction
ds_train.columns = ['input', 'output', 'instruction']
ds_train = datasets.Dataset.from_pandas(ds_train)

ds_train.push_to_hub("twitter-financial-news-sentiment")

# Validation split

ds_valid = ds['validation']
ds_valid = ds_valid.to_pandas()
ds_valid['label'] = ds_valid['label'].apply(num_to_label.get)
ds_valid['instruction'] = instruction
ds_valid.columns = ['input', 'output', 'instruction']
ds_valid = datasets.Dataset.from_pandas(ds_valid, split='validation')

ds_valid.push_to_hub("twitter-financial-news-sentiment", split='validation')
```