license:mit region:us
---
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')
```

