|
|
|
|
|
|
|
|
from utils import extract_sentences_by_intent, train_model_with_chkpt, batch_predict_and_save |
|
|
from time import time |
|
|
import logging |
|
|
from config import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from transformers import BertTokenizer |
|
|
from preprocess_data import SentenceDataset |
|
|
from models import SentenceExtractionModel |
|
|
from utils import train_sentence_extractor |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) |
|
|
dataset = SentenceDataset("data/Fin_ExBERT_train_val_data.xlsx", tokenizer) |
|
|
|
|
|
|
|
|
model = SentenceExtractionModel( |
|
|
base_model_name=MODEL_NAME, |
|
|
backbone='finexbert' |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
batch_predict_and_save( |
|
|
model, |
|
|
tokenizer, |
|
|
excel_path="data/Fin_ExBERT_test_set.xlsx", |
|
|
ckpt_path="checkpoints/sentence_extractor/best_model.pth", |
|
|
output_path="results/predictions_sample200.xlsx", |
|
|
n_samples=200, |
|
|
temperature=1.0, |
|
|
device="cuda" |
|
|
) |
|
|
|
|
|
sample_transcript = """ |
|
|
Agent: Hello, thank you for calling Acme Financial Services. My name is Priya. How can I help you today? |
|
|
Customer: Hi Priya, I’m considering opening a new savings account with you. |
|
|
Agent: Absolutely—our savings account offers 4% interest per annum. Do you have a balance in mind? |
|
|
Customer: Yes, I’d like to deposit ₹50,000 initially, and then I’m interested in investing another ₹2 lakh in mutual funds over the next month. |
|
|
Agent: Great, we have several mutual fund options. Are you more growth-oriented or looking for steady income? |
|
|
Customer: I want to focus on growth. Also, could you tell me about your home loan rates? I may need a ₹30 lakh mortgage in the next six months. |
|
|
Agent: Certainly—we currently offer home loan rates starting at 6.8%. Do you already own property or are you planning to buy? |
|
|
Customer: Planning to buy. Finally, I’d like to apply for a credit card with a high cashback—maybe one that gives 2% on all spends. |
|
|
Agent: We have a Platinum Cashback Card at 1.5%, and our Signature Cashback Card at 2%. Would you like me to initiate the application? |
|
|
Customer: Yes please, go ahead with the Signature Cashback Card, and send me the home-loan documents via email. |
|
|
Agent: Done. You’ll receive an email shortly. Is there anything else I can help you with? |
|
|
Customer: No, that’s all for today—thank you! |
|
|
""" |
|
|
|
|
|
complex_transcript = """ |
|
|
Agent: Good morning, thank you for calling Maple Grove Bank. This is Rahul speaking—how may I assist you today? |
|
|
Customer: Hi Rahul, I’ve been reviewing my financial goals for the next five years and want to discuss a mix of savings, investments, and insurance. |
|
|
Agent: Absolutely. Would you like to start with your current cash savings or jump straight into investment products? |
|
|
Customer: Let’s begin with savings: I’d like to open a high-yield savings account with at least ₹1 lakh to start, and then set up an automatic top-up of ₹10,000 each month. |
|
|
Agent: Great choice. We have our “Plus Savings” account at 4.2% APY. Next, investments—are you looking at mutual funds, stocks, or retirement plans? |
|
|
Customer: I’m particularly interested in tax-saving ELSS mutual funds and a more conservative retirement pension plan. Also, could you explain your term insurance offerings? |
|
|
Agent: Sure—our ELSS options include Fund A (equity-heavy) and Fund B (balanced). For term cover, we have 20-year plans up to ₹50 lakhs. Any preference? |
|
|
Customer: I want a balanced ELSS with a 3-year lock-in, and term insurance of ₹30 lakhs for 25 years. After that, I may need advice on buying a second home—so let’s also discuss mortgage pre-approval. |
|
|
Agent: Understood. For a ₹30 lakh home loan, current interest rates start at 6.9%. We can pre-approve you based on your income. Shall I proceed? |
|
|
Customer: Yes, please initiate the home-loan pre-approval. And lastly, I’d like to apply for a debit card with no annual fee and a co-branded credit card offering travel rewards. |
|
|
Agent: Certainly—our “Freedom” debit card has no fee, and the “SkyMiles” credit card gives 2 airline miles per ₹100 spent. Would you like to complete those applications now? |
|
|
Customer: Yes, go ahead with both. Also, can you set up a quarterly portfolio review call with a financial advisor? |
|
|
Agent: Absolutely. I’ll schedule a review every three months starting next quarter. You’ll get email confirmations shortly. |
|
|
Customer: Perfect—that covers all my needs. Thanks for your help! |
|
|
Agent: My pleasure! Have a great day and feel free to call back anytime. |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|