Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,178 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: feature-extraction
|
6 |
---
|
7 |
+
|
8 |
+
# Model Card for Model ID
|
9 |
+
|
10 |
+
<!-- Based on https://huggingface.co/t5-small, model generates SQL from text given table list with "CREATE TABLE" statements.
|
11 |
+
This is a very light weigh model and could be used in multiple analytical applications. -->
|
12 |
+
|
13 |
+
This model is an example on how to handle multi-target regression problem using llms. Model takes in tweet,stock ticker, month, last_price and volume for a stock (around the tweet was publish) and returns 1,2,3 and 7 day returns and 10 day anualized volatility. Model uses feature vectors output by the tweet text (mobile-bert output), numerical (last price and volume), and categorical(stock ticker and month) sub-components then are concatenated into a single feature vector which is fed into a final ouput layers.
|
14 |
+
Used [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased) for text feature extraction (MobileBERT is a thin version of BERT_LARGE, while equipped with bottleneck structures and a carefully designed balance between self-attentions and feed-forward networks). This model detects SQLInjection attacks in the input string (check How To Below).
|
15 |
+
This is again a very very light model (100mb), used following dataset from [Kaggle](www.kaggle.com) called [Tweet Sentiment's Impact on Stock Returns (by THE DEVASTATOR)](https://www.kaggle.com/datasets/thedevastator/tweet-sentiment-s-impact-on-stock-returns).
|
16 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
17 |
+
Contact us for more info: support@cloudsummary.com
|
18 |
+
|
19 |
+
|
20 |
+
## Model Details
|
21 |
+
|
22 |
+
### Model Description
|
23 |
+
|
24 |
+
<!-- Provide a longer summary of what this model is. -->
|
25 |
+
Model takes in tweet,stock ticker, month, last_price and volume for a stock (around the tweet was publish) and returns 1,2,3 and 7 day returns and 10 day anualized volatility. Model uses feature vectors output by the tweet text (mobile-bert output), numerical (last price and volume), and categorical(stock ticker and month) sub-components then are concatenated into a single feature vector which is fed into a final ouput layers.
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
- **Developed by:** cssupport (support@cloudsummary.com)
|
30 |
+
- **Model type:** Language model
|
31 |
+
- **Language(s) (NLP):** English
|
32 |
+
- **License:** Apache 2.0
|
33 |
+
- **Finetuned from model :** [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)
|
34 |
+
|
35 |
+
### Model Sources
|
36 |
+
|
37 |
+
<!-- Provide the basic links for the model. -->
|
38 |
+
|
39 |
+
Please refer [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased) for Model Sources.
|
40 |
+
|
41 |
+
## How to Get Started with the Model
|
42 |
+
|
43 |
+
Use the code below to get started with the model.
|
44 |
+
**hugging face library is currently not working (will fix it an update the model card). You will need to download the model and then load it manually. Use the code below**
|
45 |
+
|
46 |
+
```python
|
47 |
+
from transformers import AutoTokenizer
|
48 |
+
from sklearn.preprocessing import LabelEncoder
|
49 |
+
import torch
|
50 |
+
from sklearn.preprocessing import LabelEncoder
|
51 |
+
import joblib
|
52 |
+
|
53 |
+
|
54 |
+
# Initialize the BERT tokenizer
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained('google/mobilebert-uncased')
|
56 |
+
# Load the model
|
57 |
+
model = torch.load('pytorch_model.pt')
|
58 |
+
#load the stock enoder
|
59 |
+
#list of ticker supported - ['21CF', 'ASOS', 'AT&T', 'Adobe', 'Allianz', 'Amazon', 'American Express', 'Apple', 'AstraZeneca', 'Audi', 'Aviva', 'BASF', 'BMW', 'BP', 'Bank of America', 'Bayer', 'BlackRock', 'Boeing', 'Burberry', 'CBS', 'CVS Health', 'Cardinal Health', 'Carrefour', 'Chevron', 'Cisco', 'Citigroup', 'CocaCola', 'Colgate', 'Comcast', 'Costco', 'Danone', 'Deutsche Bank', 'Disney', 'Equinor', 'Expedia', 'Exxon', 'Facebook', 'FedEx', 'Ford', 'GSK', 'General Electric', 'Gillette', 'Goldman Sachs', 'Google', 'Groupon', 'H&M', 'HP', 'HSBC', 'Heineken', 'Home Depot', 'Honda', 'Hyundai', 'IBM', 'Intel', 'JPMorgan', 'John Deere', "Kellogg's", 'Kroger', "L'Oreal", 'Mastercard', "McDonald's", 'Microsoft', 'Morgan Stanley', 'Nestle', 'Netflix', 'Next', 'Nike', 'Nissan', 'Oracle', 'P&G', 'PayPal', 'Pepsi', 'Pfizer', 'Reuters', 'Ryanair', 'SAP', 'Samsung', 'Santander', 'Shell', 'Siemens', 'Sony', 'Starbucks', 'TMobile', 'Tesco', 'Thales', 'Toyota', 'TripAdvisor', 'UPS', 'Verizon', 'Viacom', 'Visa', 'Vodafone', 'Volkswagen', 'Walmart', 'Wells Fargo', 'Yahoo', 'adidas', 'bookingcom', 'eBay', 'easyJet', 'salesforce.com']
|
60 |
+
stock_encoder = joblib.load("data/stock_encoder.pkl")
|
61 |
+
|
62 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
63 |
+
|
64 |
+
|
65 |
+
def preprocess_text(raw_text):
|
66 |
+
tweet_data = tokenizer.batch_encode_plus(
|
67 |
+
[raw_text],
|
68 |
+
padding=True,
|
69 |
+
return_attention_mask=True,
|
70 |
+
truncation=True,
|
71 |
+
max_length=512
|
72 |
+
)
|
73 |
+
return tweet_data['input_ids'][0], tweet_data['attention_mask'][0]
|
74 |
+
|
75 |
+
|
76 |
+
def make_prediction(tweet, stock, month, last_price, volume):
|
77 |
+
# Preprocess the Data
|
78 |
+
input_ids, attention_mask = preprocess_text(tweet)
|
79 |
+
|
80 |
+
# LAST_PRICE, PX_VOLUME
|
81 |
+
numerical_data = np.array([last_price, volume])
|
82 |
+
#STOCK and MONTH
|
83 |
+
categorical_data = np.array([stock_encoder.transform([stock])[0], month])
|
84 |
+
|
85 |
+
# Convert them into PyTorch tensors
|
86 |
+
input_ids = torch.tensor([input_ids]).to(device)
|
87 |
+
attention_mask = torch.tensor([attention_mask]).to(device)
|
88 |
+
numerical_data = torch.tensor([numerical_data], dtype=torch.float32).to(device)
|
89 |
+
categorical_data = torch.tensor([categorical_data], dtype=torch.float32).to(device)
|
90 |
+
|
91 |
+
# Run the model
|
92 |
+
with torch.no_grad():
|
93 |
+
output_one_day, output_two_day, output_three_day, output_seven_day, output_vol_10d = model(
|
94 |
+
input_ids=input_ids,
|
95 |
+
attention_mask=attention_mask,
|
96 |
+
numerical_data=numerical_data,
|
97 |
+
categorical_data=categorical_data
|
98 |
+
)
|
99 |
+
|
100 |
+
# Convert to readable format (in this example, convert to percentages)
|
101 |
+
output_one_day = (output_one_day.item() * 100) # Convert tensor to Python float and then to percentage
|
102 |
+
output_two_day = (output_two_day.item() * 100)
|
103 |
+
output_three_day = (output_three_day.item() * 100)
|
104 |
+
output_seven_day = (output_seven_day.item() * 100)
|
105 |
+
|
106 |
+
return output_one_day, output_two_day, output_three_day, output_seven_day, output_vol_10d
|
107 |
+
|
108 |
+
tweet = "Check out BURGUNDY REED AND BARTON 13 PC SET OF SLIVERWARE FORKS SPOONS KNIFES GRAVY SPOON via @eBay"
|
109 |
+
stock = "eBay"
|
110 |
+
month = 9
|
111 |
+
last_price = 38.46
|
112 |
+
volume = 9964979.0
|
113 |
+
output_one_day, output_two_day, output_three_day, output_seven_day, output_vol_10d = make_prediction(
|
114 |
+
tweet, stock, month, last_price, volume)
|
115 |
+
|
116 |
+
# Print outputs
|
117 |
+
print(f"1 Day Return: {output_one_day}%")
|
118 |
+
print(f"2 Day Return: {output_two_day}%")
|
119 |
+
print(f"3 Day Return: {output_three_day}%")
|
120 |
+
print(f"7 Day Return: {output_seven_day}%")
|
121 |
+
print(f"10 Day Volatility: {output_vol_10d}")
|
122 |
+
|
123 |
+
```
|
124 |
+
|
125 |
+
## Uses
|
126 |
+
|
127 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
128 |
+
|
129 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
130 |
+
|
131 |
+
|
132 |
+
### Direct Use
|
133 |
+
|
134 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
135 |
+
Could used in application where natural language is to be converted into SQL queries.
|
136 |
+
|
137 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
### Out-of-Scope Use
|
142 |
+
|
143 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
144 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
145 |
+
[More Information Needed]
|
146 |
+
|
147 |
+
## Bias, Risks, and Limitations
|
148 |
+
|
149 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
150 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
151 |
+
|
152 |
+
[More Information Needed]
|
153 |
+
|
154 |
+
### Recommendations
|
155 |
+
|
156 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
157 |
+
|
158 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
159 |
+
**Disclaimer: This model should not be used for trading. Data source is not verified, assumption is that data is synthetically generated. This is just an example how to handle multi-target regression problem**.
|
160 |
+
|
161 |
+
|
162 |
+
## Technical Specifications
|
163 |
+
|
164 |
+
### Model Architecture and Objective
|
165 |
+
|
166 |
+
[google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)
|
167 |
+
|
168 |
+
### Compute Infrastructure
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
#### Hardware
|
173 |
+
|
174 |
+
one P6000 GPU
|
175 |
+
|
176 |
+
#### Software
|
177 |
+
|
178 |
+
Pytorch and HuggingFace
|