-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtensorflow-model
146 lines (134 loc) · 7.23 KB
/
tensorflow-model
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import numpy as np
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, Dense, LSTM, Flatten
# Training data
scam_call_sentences = {
"You need to take immediate action to avoid penalties.": 90,
"Congratulations! You have won a grand prize.": 80,
"Claim your free offer now.": 75,
"This is a limited time offer, act fast.": 85,
"Act now to claim your reward before it expires.": 88,
"Try our risk-free trial today.": 70,
"Please verify your account to continue.": 78,
"A refund is available for you, contact us immediately.": 65,
"We have detected suspicious activity in your account.": 92,
"This is a call from the government, please listen carefully.": 95,
"Your bank account has been compromised.": 80,
"Your account has been suspended due to unusual activity.": 85,
"An unauthorized transaction has been detected on your account.": 82,
"Payment is needed to resolve this issue.": 80,
"Please provide your personal information to proceed.": 95,
"We need your credit card details to process your request.": 85,
"Your social security number is required for verification.": 90,
"Confirm your password to secure your account.": 88,
"Secure your account immediately to prevent loss.": 70,
"Security alert: Your account is at risk.": 90,
"Claim your reward by calling us now.": 75,
"You have a bonus offer waiting inside.": 70,
"Technical support is needed to fix your device.": 80,
"Your account has been blocked due to suspicious activity.": 85,
"We have notified you of a data breach, please respond.": 88,
"Legal action will be taken if you do not respond immediately.": 95,
"You are required to appear in court.": 90,
"Law enforcement action is needed on your account.": 93,
"There is an issue detected by customs.": 85,
"We have identified an immigration problem with your account.": 88,
"You owe taxes and must pay immediately.": 90,
"This is an IRS notification, please respond.": 95,
"This is a CRA notification, please respond.": 95,
"You need to pay a fine to avoid further action.": 85,
"Settle your debt now to avoid penalties.": 80,
"Customer support is needed to verify your details.": 65,
"You've won a free vacation!": 70,
"This is the IRS calling, you owe back taxes and must pay immediately.": 90,
"We're calling from Microsoft, your computer has a virus.": 85,
"You've been pre-approved for a loan, but we need your bank details.": 80,
"Your Social Security Number has been compromised.": 95,
"Act now to claim your free gift!": 60,
"You have an unpaid ticket. Pay now to avoid arrest.": 75,
"Congratulations! You've won the lottery!": 70,
"We detected suspicious activity on your bank account.": 85,
"This is an urgent message about your car's extended warranty.": 65,
"Can you hear me?": 50,
"We're offering a special discount on your utility bill.": 55,
"Your credit card has been compromised.": 90,
"Please confirm your personal information for security purposes.": 80,
"There's a problem with your recent purchase, please contact us.": 70,
"You've qualified for a lower interest rate on your mortgage.": 75,
"This is a limited-time offer, act now!": 60,
"We need to verify your identity.": 85,
"Your account has been locked.": 80,
"There's a warrant out for your arrest.": 85,
"Your account will be terminated unless you respond immediately.": 90,
"You have been selected for a special offer, act now.": 75,
"We require your immediate attention to resolve this issue.": 88,
"A large sum of money is waiting for you, call us now.": 80,
"Your identity has been compromised, verify your details.": 92,
"This is an urgent notice from your financial institution.": 85,
"You are eligible for a free upgrade, contact us today.": 70,
"Your account has unusual login activity, secure it now.": 88,
"Respond now to avoid legal proceedings.": 95,
"This is an official notice, please contact us immediately.": 90,
"Your account requires verification to prevent suspension.": 85,
"You have an unpaid bill, please settle it now.": 80,
"A large transaction has been detected, confirm if it was you.": 82,
"Your personal details are needed to complete this transaction.": 95,
"Your bank has flagged your account, call us now.": 80,
"We need your credit card number to verify your purchase.": 85,
"There is a problem with your social security number, contact us.": 90,
"Confirm your login details to continue.": 88,
"We have secured your account, please verify your identity.": 70,
"Security alert: Unusual activity detected.": 90,
"Special bonus available, respond to claim.": 70,
"Technical issue detected, support needed.": 80,
"Your account access has been restricted, verify now.": 85,
"Data breach alert, respond immediately.": 88,
"Legal notice: Immediate response required.": 95,
"Court summons issued, contact us.": 90,
"Law enforcement notification, urgent response needed.": 93,
"Customs alert: Package held, contact us.": 85,
"Immigration alert: Contact us immediately.": 88,
"Tax notification: Payment required.": 90,
"This is a final notice from the IRS.": 95,
"Final notice from the CRA, respond now.": 95,
"Pay your outstanding fine to avoid further action.": 85,
"Settle your outstanding balance today.": 80,
"Act immediately to secure your funds.": 88,
"Respond now to avoid service interruption.": 85,
"Your package is being held, provide your details to release it.": 80,
"This is a final warning before your account is closed.": 90,
"Your bank requires additional information to proceed.": 85,
"You have been overcharged, contact us for a refund.": 70
}
# Step 1: Prepare data
sentences = list(scam_call_sentences.keys())
labels = np.array(list(scam_call_sentences.values())) / 100 # Normalize between 0 and 1
# Step 2: Tokenize text
tokenizer = Tokenizer()
tokenizer.fit_on_texts(sentences)
sequences = tokenizer.texts_to_sequences(sentences)
word_index = tokenizer.word_index
# Pad sequences for uniform input length
max_length = max(len(seq) for seq in sequences)
padded_sequences = pad_sequences(sequences, maxlen=max_length, padding='post')
# Step 3: Build the model
vocab_size = len(word_index) + 1
embedding_dim = 16
model = Sequential([
Embedding(input_dim=vocab_size, output_dim=embedding_dim, input_length=max_length),
LSTM(32), # LSTM layer to capture sequential information
Dense(16, activation='relu'),
Dense(1, activation='linear') # Linear output for regression
])
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['mae'])
model.summary()
# Step 4: Train the model
model.fit(padded_sequences, labels, epochs=10, batch_size=8)
# Step 5: Test the model
while True:
input_sentence = input("What's the sentence? ")
test_seq = pad_sequences(tokenizer.texts_to_sequences(input_sentence), maxlen=max_length, padding='post')
predicted_likelihood = model.predict(test_seq)
print(f"Predicted scam likelihood: {predicted_likelihood[0][0] * 100:.2f}%/n")