Instructions to use DragonLLM/fin-pythia-1.4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DragonLLM/fin-pythia-1.4b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DragonLLM/fin-pythia-1.4b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("DragonLLM/fin-pythia-1.4b") model = AutoModelForCausalLM.from_pretrained("DragonLLM/fin-pythia-1.4b") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use DragonLLM/fin-pythia-1.4b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DragonLLM/fin-pythia-1.4b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DragonLLM/fin-pythia-1.4b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/DragonLLM/fin-pythia-1.4b
- SGLang
How to use DragonLLM/fin-pythia-1.4b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "DragonLLM/fin-pythia-1.4b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DragonLLM/fin-pythia-1.4b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "DragonLLM/fin-pythia-1.4b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DragonLLM/fin-pythia-1.4b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use DragonLLM/fin-pythia-1.4b with Docker Model Runner:
docker model run hf.co/DragonLLM/fin-pythia-1.4b
Fin-Pythia-1.4B is an instruction-finetuned model for sentiment analysis of financial text. It is built by 1) further training Pythia-1.4B model on financial documents, then 2) instruction fine-tuning on financial tasks. Although, the model is designed to be used for sentiment analysis, it performs well on other tasks such as named entity recognition (check our FinNLP 2023 paper). Fin-Pythia-1.4B's performance on financial sentiment analysis is on par with much larger financial LLMs and exceeds the performance of general models like GPT-4:
| Models | FPB | FIQA-SA | Headlines | NER |
|---|---|---|---|---|
| BloombergGPT | 0.51 | 0.75 | 0.82 | 0.61 |
| GPT-4 | 0.78 | - | 0.86 | 0.83 |
| FinMA-7B | 0.86 | 0.84 | 0.98 | 0.75 |
| FinMA-30B | 0.88 | 0.87 | 0.97 | 0.62 |
| Pythia-1.4B | 0.84 | 0.83 | 0.97 | 0.69 |
Usage
Your instruction should follow this format:
prompt = "\n".join([
'### Instruction: YOUR_INSTRUCTION',
'### Text: YOUR_SENTENCE',
'### Answer:'])
For example:
### Instruction: Analyze the sentiment of this statement extracted from a financial news article. Provide your answer as either negative, positive, or neutral.\n### Text: The economic uncertainty caused by the ongoing trade tensions between major global economies has led to a sharp decline in investor confidence, resulting in a significant drop in the stock market.\n### Answer:
You could also force the model to generate only the sentiment tokens using the following example code:
prompt = "### Instruction: Analyze the sentiment of this statement extracted from a financial news article. Provide your answer as either negative, positive, or neutral.\n### Text: XYZ reported record-breaking profits for the quarter, exceeding analyst expectations and driving their stock price to new highs.\n### Answer:"
target_classes = ["positive", "negative", "neutral"]
target_class_ids = tokenizer.convert_tokens_to_ids(target_classes)
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(args.device)
outputs = model(inputs.input_ids)
top_output = outputs.logits[0][-1][target_class_ids].argmax(dim=0)
print(target_classes[top_output])
Citation
@misc{lc_finnlp2023,
title={Large Language Model Adaptation for Financial Sentiment Analysis},
author={Rodriguez Inserte Pau and Nakhlé Mariam and Qader Raheel and Caillaut Gaëtan and Liu Jingshu},
year={2023},
}
- Downloads last month
- 24