raeidsaqur commited on
Commit
c8b8544
1 Parent(s): 0311672
Files changed (2) hide show
  1. nifty-icon.png +3 -0
  2. utils/utils_inference.py +36 -0
nifty-icon.png ADDED

Git LFS Details

  • SHA256: df0ed6194e1f9c0eb773c12e9d9413925a5458b287a2a3030c9ca2a96d090311
  • Pointer size: 131 Bytes
  • Size of remote file: 377 kB
utils/utils_inference.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ ## Author: Raeid Saqur
3
+
4
+ ### -------- CONSTANTS -------- ###
5
+
6
+ LABELS = ["Fall", "Neutral", "Rise"]
7
+ LABEL_MAP = {"Rise": 2, "Neutral": 1, "Fall": 0}
8
+ NUMERIC_LABEL_MAP = {v: k for k, v in LABEL_MAP.items()}
9
+ SEEDS = [0, 13, 42]
10
+
11
+ SYSTEM_ROLE_DEF_1 = "You are a helpful assistant and a financial technical analyst."
12
+ SYSTEM_ROLE_DEF_2 = ("You are a helpful financial market technical analyst. "
13
+ "You specialize in financial stock and equities market, a top expert in assessing market index movement direction from events and news. ")
14
+
15
+
16
+ def get_truncated_user_prompt_for_nifty(user_prompt: str, drop_percent: float = 0.5) -> str:
17
+ """Keeps instruction and context unchanged, drops p% of news headlines randomly
18
+ Usage e.g.:
19
+ user_prompt = get_truncated_user_prompt_for_nifty(user_prompt, drop_percent=drop_percent)
20
+ """
21
+ import random
22
+
23
+ splits = user_prompt.split("\n\n")
24
+ context, news = splits[:-1], splits[-1]
25
+ news_headlines = news.split("\n")
26
+ news_headlines, suffix = news_headlines[:-1], news_headlines[-1]
27
+ N = len(news_headlines)
28
+ N_truncated = int(N * drop_percent)
29
+ random.shuffle(news_headlines)
30
+ truncated_news_headlines = news_headlines[:N_truncated] + [suffix]
31
+ truncated_news_string = "\n".join(truncated_news_headlines)
32
+ truncated_user_prompt = context + [truncated_news_string]
33
+ truncated_user_prompt = "\n\n".join(truncated_user_prompt)
34
+
35
+ return truncated_user_prompt
36
+