nifty-rl / utils /utils_inference.py
raeidsaqur's picture
.
c8b8544
raw
history blame
No virus
1.48 kB
#!/usr/bin/python3
## Author: Raeid Saqur
### -------- CONSTANTS -------- ###
LABELS = ["Fall", "Neutral", "Rise"]
LABEL_MAP = {"Rise": 2, "Neutral": 1, "Fall": 0}
NUMERIC_LABEL_MAP = {v: k for k, v in LABEL_MAP.items()}
SEEDS = [0, 13, 42]
SYSTEM_ROLE_DEF_1 = "You are a helpful assistant and a financial technical analyst."
SYSTEM_ROLE_DEF_2 = ("You are a helpful financial market technical analyst. "
"You specialize in financial stock and equities market, a top expert in assessing market index movement direction from events and news. ")
def get_truncated_user_prompt_for_nifty(user_prompt: str, drop_percent: float = 0.5) -> str:
"""Keeps instruction and context unchanged, drops p% of news headlines randomly
Usage e.g.:
user_prompt = get_truncated_user_prompt_for_nifty(user_prompt, drop_percent=drop_percent)
"""
import random
splits = user_prompt.split("\n\n")
context, news = splits[:-1], splits[-1]
news_headlines = news.split("\n")
news_headlines, suffix = news_headlines[:-1], news_headlines[-1]
N = len(news_headlines)
N_truncated = int(N * drop_percent)
random.shuffle(news_headlines)
truncated_news_headlines = news_headlines[:N_truncated] + [suffix]
truncated_news_string = "\n".join(truncated_news_headlines)
truncated_user_prompt = context + [truncated_news_string]
truncated_user_prompt = "\n\n".join(truncated_user_prompt)
return truncated_user_prompt