Views
No views yet
huawei-noah/TinyBERT_General_4L_312D| Metric | Value |
|---|---|
| Accuracy | 89.2% |
| F1-Score | 0.87 |
| Model Size | 54.84MB |
| CPU Latency | 28ms |
| Quantized Size | 5.3MB |
1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="mikeysharma/finance-sentiment-analysis"
6)
7
8result = classifier("$TSLA - Morgan Stanley upgrades Tesla to Overweight")
9print(result)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("mikeysharma/finance-sentiment-analysis)
5model = AutoModelForSequenceClassification.from_pretrained("mikeysharma/finance-sentiment-analysis")
6
7inputs = tokenizer(
8 "$BYND - JPMorgan cuts Beyond Meat price target",
9 return_tensors="pt",
10 truncation=True,
11 max_length=128
12)
13
14with torch.no_grad():
15 outputs = model(**inputs)
16 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
17 print(predictions)1from optimum.onnxruntime import ORTModelForSequenceClassification
2from transformers import AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained("mikeysharma/finance-sentiment-analysis")
5model = ORTModelForSequenceClassification.from_pretrained("mikeysharma/finance-sentiment-analysis")
6
7inputs = tokenizer(
8 "Cemex shares fall after Credit Suisse downgrade",
9 return_tensors="pt",
10 truncation=True,
11 max_length=128
12)
13
14outputs = model(**inputs)$AAPL - Apple hits record high after earnings beat (Positive)
$TSLA - Tesla misses Q2 delivery estimates (Negative)
$MSFT - Microsoft announces new Azure features (Neutral)1FROM python:3.8-slim
2
3WORKDIR /app
4COPY . .
5
6RUN pip install transformers optimum[onnxruntime] fastapi uvicorn
7
8CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]1@misc{tinybert-fin-sentiment,
2 author = {Mikey Sharma},
3 title = {Lightweight Financial News Sentiment Analysis with TinyBERT},
4 year = {2023},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/mikeysharma/finance-sentiment-analysis}}
7}