Views
No views yet
| Train loss | Validation loss | Validation accuracy | |
|---|---|---|---|
| epoch1 | 0.3495 | 0.2956 | 0.8679 |
| epoch2 | 0.2717 | 0.2235 | 0.9021 |
| epoch3 | 0.2360 | 0.1875 | 0.9210 |
| epoch4 | 0.2106 | 0.1603 | 0.9343 |
1from transformers import RobertaForSequenceClassification, RobertaTokenizer
2from transformers import pipeline
3import pandas as pd
4import emoji
5
6# the model was trained upon below preprocessing
7def process_text(texts):
8
9 # remove URLs
10 texts = re.sub(r'https?://\S+', "", texts)
11 texts = re.sub(r'www.\S+', "", texts)
12 # remove '
13 texts = texts.replace(''', "'")
14 # remove symbol names
15 texts = re.sub(r'(\#)(\S+)', r'hashtag_\2', texts)
16 texts = re.sub(r'(\$)([A-Za-z]+)', r'cashtag_\2', texts)
17 # remove usernames
18 texts = re.sub(r'(\@)(\S+)', r'mention_\2', texts)
19 # demojize
20 texts = emoji.demojize(texts, delimiters=("", " "))
21
22 return texts.strip()
23
24tokenizer_loaded = RobertaTokenizer.from_pretrained('zhayunduo/roberta-base-stocktwits-finetuned')
25model_loaded = RobertaForSequenceClassification.from_pretrained('zhayunduo/roberta-base-stocktwits-finetuned')
26
27nlp = pipeline("text-classification", model=model_loaded, tokenizer=tokenizer_loaded)
28
29sentences = pd.Series(['just buy','just sell it',
30 'entity rocket to the sky!',
31 'go down','even though it is going up, I still think it will not keep this trend in the near future'])
32# sentences = list(sentences.apply(process_text)) # if input text contains https, @ or # or $ symbols, better apply preprocess to get a more accurate result
33sentences = list(sentences)
34results = nlp(sentences)
35print(results) # 2 labels, label 0 is bearish, label 1 is bullish
36