File size: 1,957 Bytes
4f4dc18
4e867fd
4f4dc18
a89525e
 
 
7179ecd
4f4dc18
 
a89525e
4f4dc18
a89525e
b63e376
4f4dc18
6e36f0f
 
 
 
a89525e
4f4dc18
b55ad02
 
a89525e
 
 
4f4dc18
a89525e
4f4dc18
2923918
4f4dc18
a89525e
 
 
f0b6f68
a89525e
4f4dc18
a89525e
 
 
 
 
 
 
 
b55ad02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
---
license: apache-2.0
library_name: transformers
tags:
- finance
pipeline_tag: text-generation
base_model: TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T
---

# Tiny Crypto Sentiment Analysis

Fine-tuned (with LoRA) version of [TinyLlama](https://huggingface.co/TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T) on cryptocurrency news articles
to predict the sentiment and subject of an article. The dataset used is [Crypto News+](https://www.kaggle.com/datasets/oliviervha/crypto-news/).

## How to Train Your Own Tiny LLM?

Follow the complete tutorial on how this model was trained: https://www.mlexpert.io/bootcamp/fine-tuning-tiny-llm-on-custom-dataset

## How to Use

Load the model:

```py
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

MODEL_NAME = "curiousily/tiny-crypto-sentiment-analysis"

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)

model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME,
    device_map="auto",
    torch_dtype=torch.float16
)

pipe = pipeline(
    task="text-generation",
    model=model,
    tokenizer=tokenizer,
    max_new_tokens=16,
    return_full_text=False,
)
```

Prompt format:

```py
prompt = """
### Title:
<YOUR ARTICLE TITLE>
### Text:
<YOUR ARTICLE PARAGRAPH>
### Prediction:
""".strip()
```

Here's an example:

```py
prompt = """
### Title:
Bitcoin Price Prediction as BTC Breaks Through $27,000 Barrier Here are Price Levels to Watch
### Text:
Bitcoin, the world's largest cryptocurrency by market capitalization, has been making headlines recently as it broke through the $27,000 barrier for the first time. This surge in price has reignited speculation about where Bitcoin is headed next, with many analysts and investors offering their predictions.
### Prediction:
""".strip()
```

Get a prediction:

```py
outputs = pipe(prompt)
print(outputs[0]["generated_text"].strip())
```

```md
subject: bitcoin
sentiment: positive
```