Views
No views yet
FinBERT (ProsusAI/finbert) fine-tuned on Indian financial news headlines using LoRA adapters.
Optimised for Indian market sentiment — Nifty 50 stocks, NSE/BSE news, RBI announcements, and Indian business headlines. This repo contains the model itself, you don't need to download file , just go to the How to use model section of this read me and check how to do inference.
├── config.json
├── labeled_dataset.csv # training dataset
├── result.png # Result image
├── model.safetensor # Whole merged model
├── tokenizer.json
├── tokenizer_config.json # Tokenizer settings
└── README.md| ID | Label | Meaning |
|---|---|---|
| 0 | POSITIVE | Bullish sentiment |
| 1 | NEGATIVE | Bearish sentiment |
| 2 | NEUTRAL | No clear directional signal |
pip install torch==2.6.0 transformers==4.47.0 peft==0.13.0 safetensors==0.4.3Have an NVIDIA GPU? Install the CUDA build of torch for faster inference:bash1pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu124 2pip install transformers==4.47.0 peft==0.13.0 safetensors==0.4.3
1import torch
2from transformers import pipeline
3
4LABEL_MAP = {"LABEL_0": "POSITIVE", "LABEL_1": "NEGATIVE", "LABEL_2": "NEUTRAL"}
5
6# HuggingFace downloads and caches the model automatically on first run
7nlp = pipeline(
8 "sentiment-analysis",
9 model = "ArpitJha/Indian-FinBert",
10 tokenizer = "ArpitJha/Indian-FinBert",
11 device = 0 if torch.cuda.is_available() else -1
12)
13
14headlines = [
15 "Reliance Industries posts record quarterly profit.",
16 "Adani Group stocks crash amid fraud allegations.",
17 "RBI keeps interest rates unchanged in policy meeting.",
18 "Infosys wins $2 billion AI transformation deal.",
19]
20
21for h in headlines:
22 result = nlp(h)[0]
23 sentiment = LABEL_MAP.get(result["label"], result["label"])
24 print(f"{sentiment} ({result['score']*100:.1f}%) — {h}")1import torch
2import pandas as pd
3from transformers import pipeline
4
5LABEL_MAP = {"LABEL_0": "POSITIVE", "LABEL_1": "NEGATIVE", "LABEL_2": "NEUTRAL"}
6
7# 1. Initialize the pipeline
8print("Loading model...")
9nlp = pipeline(
10 "sentiment-analysis",
11 model="ArpitJha/Indian-FinBert",
12 tokenizer="ArpitJha/Indian-FinBert",
13 device=0 if torch.cuda.is_available() else -1
14)
15
16# 2. Load the CSV data
17csv_file_path = "input_data.csv" # Change this to your file's path
18print(f"Loading data from {csv_file_path}...")
19df = pd.read_csv(csv_file_path)
20
21# Ensure the column exists (replace 'headline' with your actual column name)
22text_column = "headline"
23if text_column not in df.columns:
24 raise ValueError(f"Column '{text_column}' not found in the CSV. Available columns: {df.columns.tolist()}")
25
26# Convert the column to a standard Python list
27texts_to_analyze = df[text_column].astype(str).tolist()
28
29# 3. Run Batch Inference
30print(f"Processing {len(texts_to_analyze)} rows. This might take a moment...")
31# Adjust batch_size based on your GPU memory (e.g., 8, 16, 32, 64)
32results = nlp(texts_to_analyze, batch_size=16)
33
34# 4. Extract labels and scores
35mapped_sentiments = []
36confidence_scores = []
37
38for result in results:
39 mapped_sentiments.append(LABEL_MAP.get(result["label"], result["label"]))
40 confidence_scores.append(round(result["score"] * 100, 2)) # Score as a percentage
41
42# 5. Add the results back to the DataFrame
43df["predicted_sentiment"] = mapped_sentiments
44df["confidence_score_%"] = confidence_scores
45
46# 6. Save the results to a new CSV
47output_path = "output_results.csv"
48df.to_csv(output_path, index=False)
49print(f"Batch inference complete! Results saved to {output_path}")torch>=2.6.0
transformers==4.47.0
peft==0.13.0
safetensors==0.4.3
pandas>=2.2.0 # only needed for batch CSV inference| Property | Value |
|---|---|
| Base model | ProsusAI/finbert |
| Fine-tuning method | LoRA (PEFT) |
| LoRA rank | 32 |
| LoRA alpha | 64 |
| Target modules | query, value |
| Training data | Indian financial news headlines |
| Task | 3-class sentiment classification |
| Labels | Positive / Negative / Neutral |
| Trainable parameters | ~1% of total |
ProsusAI/finbert) is subject to its own Apache 2.0 license.