AI Mail Analyzer¶
mail_analysis
¶
MODEL_SPECS = (ModelSpec('safe_suspicious_30_epochs_model.pth', 2, 'main'), ModelSpec('spam_dangerous_30_epochs_model.pth', 2, 'main'), ModelSpec('safe_30_epochs_model.pth', 2, 'sub'), ModelSpec('unwanted_30_epochs_model.pth', 2, 'sub'), ModelSpec('dangerous_30_epochs_model.pth', 4, 'sub'))
module-attribute
¶
ClassificationName
¶
SubClassificationName
¶
Bases: Enum
INTERNAL = 0
class-attribute
instance-attribute
¶
EXTERNAL = 1
class-attribute
instance-attribute
¶
SPAM = 2
class-attribute
instance-attribute
¶
NEWSLETTER = 3
class-attribute
instance-attribute
¶
CLASSIC_PHISHING = 4
class-attribute
instance-attribute
¶
CLONE = 5
class-attribute
instance-attribute
¶
BLACKMAIL = 6
class-attribute
instance-attribute
¶
WHALING = 7
class-attribute
instance-attribute
¶
ModelSpec
¶
untar_file(filepath, extract_to)
¶
get_header_dict_list(msg)
¶
getMainClassificationProbabilities(device, safe_suspicious_model, spam_dangerous_model, email_embedding)
¶
getMainClassificationInfo(global_probabilities)
¶
getSubClassificationProbabilities(device, models, email_embedding, main_classification_probabilities)
¶
getSubClassificationInfo(global_sub_probabilities)
¶
get_classification_breakdown(global_probabilities)
¶
Label the raw main-classification array by enum name, e.g. {"SAFE": 0.83, "UNWANTED": 0.12, "DANGEROUS": 0.05}.
get_sub_classification_breakdown(global_sub_probabilities)
¶
Label the raw sub-classification array by enum name.
split_into_sentences(mail_body, max_sentences=40)
¶
Split a mail body into sentence-ish chunks for occlusion analysis.
Caps at max_sentences so a pathologically long body can't turn the per-sentence re-embedding pass in get_contributing_phrases into an unbounded number of model calls.
rank_phrase_impacts(sentences, impacts, top_n=5)
¶
Pair sentences with their occlusion impact, keep only sentences whose removal reduced confidence in the predicted class (impact > 0), and return the top_n by impact descending.
get_contributing_phrases(device, safe_suspicious_model, spam_dangerous_model, vectorizer, mail_body, classification_index, baseline_probability, top_n=5)
¶
Sentence-level occlusion: re-embed the body with each sentence removed and measure how much confidence in the predicted class drops. Sentences whose removal drops confidence the most are the ones driving the classification.
ai_mail_classifier
¶
ResNetMLP
¶
ResNetMLP
¶
Bases: Module