Upload folder using huggingface_hub
Browse filesFiles changed (18)
- __pycache__/classification.cpython-38.pycAdded
- app.pyAdded+28
- checkpoint-770.zipAdded+3
- checkpoint-770/config.jsonAdded+48
- checkpoint-770/merges.txtAdded
- checkpoint-770/model.safetensorsAdded+3
- checkpoint-770/optimizer.ptAdded+3
- checkpoint-770/rng_state.pthAdded+3
- checkpoint-770/scheduler.ptAdded+3
- checkpoint-770/special_tokens_map.jsonAdded+51
- checkpoint-770/tokenizer.jsonAdded
- checkpoint-770/tokenizer_config.jsonAdded+58
- checkpoint-770/trainer_state.jsonAdded
- checkpoint-770/training_args.binAdded+3
- checkpoint-770/vocab.jsonAdded
- classification.pyAdded+96
- prompt.pyAdded+52
- requirements.txtAdded+9
12345678910111213141516171819202122232425262728from flask import Flask, request, jsonifyfrom flask_cors import CORSimport classification
app = Flask(__name__)CORS(app)
@app.route('/api/classify', methods=['POST'])def classify_email(): data = request.json if not data or ('subject' not in data and 'body' not in data): return jsonify({'error': 'Missing email content'}), 400 subject = data.get('subject', '') body = data.get('body', '') email = f""" Subject: {subject} Body: {body} """ result = classification.classify(email) return result
if __name__ == '__main__': app.run(debug=True, port=5007)123version https://git-lfs.github.com/spec/v1oid sha256:440847c43b6723ad6dec74aa701f01bdd3783d440233b69f99b10aaf1565b05dsize 617581195123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "architectures": [ "RobertaForSequenceClassification" ], "attention_probs_dropout_prob": 0.1, "bos_token_id": 0, "classifier_dropout": null, "eos_token_id": 2, "gradient_checkpointing": false, "hidden_act": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 768, "id2label": { "0": "Intent_Amendment_Abstraction", "1": "Intent_Clause_Protect", "2": "Intent_Company_research", "3": "Intent_Comparison_LOI_Lease", "4": "Intent_Lease_Abstraction", "5": "Intent_Lease_Listings_Comparison", "6": "Intent_Sales_Listings_Comparison", "7": "Intent_Transaction_Date_navigator" }, "initializer_range": 0.02, "intermediate_size": 3072, "label2id": { "Intent_Amendment_Abstraction": 0, "Intent_Clause_Protect": 1, "Intent_Company_research": 2, "Intent_Comparison_LOI_Lease": 3, "Intent_Lease_Abstraction": 4, "Intent_Lease_Listings_Comparison": 5, "Intent_Sales_Listings_Comparison": 6, "Intent_Transaction_Date_navigator": 7 }, "layer_norm_eps": 1e-05, "max_position_embeddings": 514, "model_type": "roberta", "num_attention_heads": 12, "num_hidden_layers": 12, "pad_token_id": 1, "position_embedding_type": "absolute", "problem_type": "single_label_classification", "torch_dtype": "float32", "transformers_version": "4.51.3", "type_vocab_size": 1, "use_cache": true, "vocab_size": 50265}123version https://git-lfs.github.com/spec/v1oid sha256:9d157cae8ab980d89e5d426c84adeeed7a7c7aa988652ee0db903f0e554d5c96size 498631280123version https://git-lfs.github.com/spec/v1oid sha256:2c2d013e8a08903506b83e98e7795cebb6ed24e8d8cfa6be6ab33da27d900b37size 254292026123version https://git-lfs.github.com/spec/v1oid sha256:d5c63f61290f5421d6c6c8d31fafa5315c374c21561b10e72403200f87627ab2size 14244123version https://git-lfs.github.com/spec/v1oid sha256:b911e9d190a52c2fdaf1fc288a99472d1155b896916224bae1f6948903948c82size 1064123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051{ "bos_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "cls_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "eos_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "mask_token": { "content": "<mask>", "lstrip": true, "normalized": false, "rstrip": false, "single_word": false }, "pad_token": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "sep_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "unk_token": { "content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758{ "add_prefix_space": false, "added_tokens_decoder": { "0": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "1": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "2": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "3": { "content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50264": { "content": "<mask>", "lstrip": true, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "<s>", "clean_up_tokenization_spaces": false, "cls_token": "<s>", "eos_token": "</s>", "errors": "replace", "extra_special_tokens": {}, "mask_token": "<mask>", "model_max_length": 1000000000000000019884624838656, "pad_token": "<pad>", "sep_token": "</s>", "tokenizer_class": "RobertaTokenizer", "trim_offsets": true, "unk_token": "<unk>"}123version https://git-lfs.github.com/spec/v1oid sha256:5c7a683e8060061a252378604e6aed2dc6535a81e8f3f319e777d656331eab38size 5240123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import torchfrom scipy.special import softmaxfrom transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("/home/nobroker/Downloads/emailclassification/backend/checkpoint-770")model = AutoModelForSequenceClassification.from_pretrained("/home/nobroker/Downloads/emailclassification/backend/checkpoint-770")
def classify(email) :
promptForIntentclassification = """ You are an AI who is an expert email analyzer and classification system specializing in real estate and legal documentation. Your task is to accurately classify incoming emails into one of 8 predefined business intents. You must also identify emails that contain mixed intents or fall outside these 8 categories.
**Here are the 8 predefined business intents:**
0. **Intent_Amendment_Abstraction**: Emails requesting the extraction of new terms or highlighting changes introduced by a lease amendment compared to the original lease. 1. **Intent_Clause_Protect**: Emails requesting a review of lease clauses to detect potentially risky, missing, or unfavorable terms (e.g., subletting rights, break clauses, indemnity, assignment terms, unreasonable liabilities, compliance issues). 2. **Intent_Company_research**: Emails seeking background information or due diligence on a company involved in a transaction (e.g., credibility, litigation history, public disputes, bankruptcies, financial health, track record). 3. **Intent_Comparison_LOI_Lease**: Emails asking to compare a Letter of Intent (LOI) with a final lease agreement to identify discrepancies, changes, or deviations in terms (e.g., TI allowances, common area maintenance, termination clauses). 4. **Intent_Lease_Abstraction**: Emails requesting the extraction of key lease metadata and clauses (e.g., rent, term, landlord, tenant, renewal options, escalation schedules, important dates, responsibilities). 5. **Intent_Lease_Listings_Comparison**: Emails asking to compare multiple lease listing summaries for properties, focusing on identifying the best terms, overlaps, gaps, per square foot pricing, and tenant-friendly clauses. 6. **Intent_Sales_Listings_Comparison**: Emails asking to compare multiple sales listing summaries for properties, focusing on metrics like pricing, square footage, capitalization rate (cap rate), and average price per square foot (PSF). 7. **Intent_Transaction_Date_navigator**: Emails focused on extracting, scheduling, or managing transaction-related dates (e.g., escrow, closing, notice periods, possession dates, due diligence deadlines, funding deadlines, inspection dates).
**If an email clearly contains elements of more than one of the above intents, or if its primary intent does not fit any of the 8 categories, classify it as "Intent_Mixed_Other".** This "Intent_Mixed_Other" category is crucial for handling complex or out-of-scope requests.
**Output Format:**
For each email, provide *only* the most appropriate intent label. Do not include any additional text or explanation strictly.
Here are some **Example Emails:**
**Email 1:** Subject: Lease Summary for 123 Main St Body: Hi team, please summarize the key terms of the lease for the 123 Main St property. I need to know the base rent, commencement and expiry dates, renewal options, and escalation schedule. Thanks!
**Classification 1:** Intent_Lease_Abstraction
**Email 2:** Subject: LOI vs. Lease Discrepancies - 789 Oak Ave Body: Hey, I need help comparing the LOI we submitted for 789 Oak Ave with the final lease. Can you identify any deviations, especially around TI allowances and common area maintenance? Appreciate your help.
**Classification 2:** Intent_Comparison_LOI_Lease
**Email 3:** Subject: Review for Risky Clauses - New Lease for 456 Elm Rd Body: Could you please review the new lease for 456 Elm Rd and detect any potentially risky or missing lease clauses, such as those related to subletting rights or indemnity? Best regards.
**Classification 3:** Intent_Clause_Protect
**Email 4:** Subject: Background Check on Global Holdings Inc. Body: Urgent: Can you do a background check on Global Holdings Inc. before we proceed? I’m particularly interested in any litigation history or bankruptcies in the past 5 years. Cheers.
**Classification 4:** Intent_Company_research
Here is the email {email}. Now classify this keeping all points in view. Do not hallaucinate. """
id2label = { 0: "Intent_Amendment_Abstraction", 1: "Intent_Clause_Protect", 2: "Intent_Company_research", 3: "Intent_Comparison_LOI_Lease", 4: "Intent_Lease_Abstraction", 5: "Intent_Lease_Listings_Comparison", 6: "Intent_Sales_Listings_Comparison", 7: "Intent_Transaction_Date_navigator" }
encoded_input = tokenizer(email, return_tensors='pt', truncation=True, padding=True, max_length = 256)
with torch.no_grad(): output = model(**encoded_input)
scores = output.logits[0].detach().numpy() print(scores) probs = softmax(scores) print(probs)
predicted_class_id = probs.argmax() print("here \n") print(predicted_class_id)
if predicted_class_id >=0 and predicted_class_id <=7 : print(predicted_class_id) predicted_label = id2label[predicted_class_id] print(predicted_label) else : predicted_label = "Intent_Mixed_Other"
return f"\n🧠 Predicted Category: {predicted_label}"12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152promptForIntentclassification = """You are an AI who is an expert email analyzer and classification system specializing in real estate and legal documentation.Your task is to accurately classify incoming emails into one of 8 predefined business intents. You must also identify emails thatcontain mixed intents or fall outside these 8 categories.
**Here are the 8 predefined business intents:**
1. **Intent_Lease_Abstraction**: Emails requesting the extraction of key lease metadata and clauses (e.g., rent, term, landlord, tenant, renewal options, escalation schedules, important dates, responsibilities).2. **Intent_Comparison_LOI_Lease**: Emails asking to compare a Letter of Intent (LOI) with a final lease agreement to identify discrepancies, changes, or deviations in terms (e.g., TI allowances, common area maintenance, termination clauses).3. **Intent_Clause_Protect**: Emails requesting a review of lease clauses to detect potentially risky, missing, or unfavorable terms (e.g., subletting rights, break clauses, indemnity, assignment terms, unreasonable liabilities, compliance issues).4. **Intent_Company_research**: Emails seeking background information or due diligence on a company involved in a transaction (e.g., credibility, litigation history, public disputes, bankruptcies, financial health, track record).5. **Intent_Transaction_Date_navigator**: Emails focused on extracting, scheduling, or managing transaction-related dates (e.g., escrow, closing, notice periods, possession dates, due diligence deadlines, funding deadlines, inspection dates).6. **Intent_Amendment_Abstraction**: Emails requesting the extraction of new terms or highlighting changes introduced by a lease amendment compared to the original lease.7. **Intent_Sales_Listings_Comparison**: Emails asking to compare multiple sales listing summaries for properties, focusing on metrics like pricing, square footage, capitalization rate (cap rate), and average price per square foot (PSF).8. **Intent_Lease_Listings_Comparison**: Emails asking to compare multiple lease listing summaries for properties, focusing on identifying the best terms, overlaps, gaps, per square foot pricing, and tenant-friendly clauses.
**If an email clearly contains elements of more than one of the above intents, or if its primary intent does not fit any of the 8 categories, classify it as "Intent_Mixed_Other".** This "Intent_Mixed_Other" category is crucial for handling complex or out-of-scope requests.
**Output Format:**
For each email, provide *only* the most appropriate intent label. Do not include any additional text or explanation strictly.
Here are some **Example Emails:**
**Email 1:**Subject: Lease Summary for 123 Main StBody: Hi team, please summarize the key terms of the lease for the 123 Main St property. I need to know the base rent, commencement and expiry dates, renewal options, and escalation schedule. Thanks!
**Classification 1:** Intent_Lease_Abstraction
**Email 2:**Subject: LOI vs. Lease Discrepancies - 789 Oak AveBody: Hey, I need help comparing the LOI we submitted for 789 Oak Ave with the final lease. Can you identify any deviations, especially around TI allowances and common area maintenance? Appreciate your help.
**Classification 2:** Intent_Comparison_LOI_Lease
**Email 3:**Subject: Review for Risky Clauses - New Lease for 456 Elm RdBody: Could you please review the new lease for 456 Elm Rd and detect any potentially risky or missing lease clauses, such as those related to subletting rights or indemnity? Best regards.
**Classification 3:** Intent_Clause_Protect
**Email 4:**Subject: Background Check on Global Holdings Inc.Body: Urgent: Can you do a background check on Global Holdings Inc. before we proceed? I’m particularly interested in any litigation history or bankruptcies in the past 5 years. Cheers.
**Classification 4:** Intent_Company_research
Here is the email {email}. Now classify this keeping all points in view. Do not hallaucinate."""123456789flask>=2.2flask-corswerkzeug>=2.2transformerstorchscipydatasetsscikit-learnpandas__pycache__/classification.cpython-38.pycAdded
app.pyAdded+28
checkpoint-770.zipAdded+3
checkpoint-770/config.jsonAdded+48
checkpoint-770/merges.txtAdded
checkpoint-770/model.safetensorsAdded+3
checkpoint-770/optimizer.ptAdded+3
checkpoint-770/rng_state.pthAdded+3
checkpoint-770/scheduler.ptAdded+3
checkpoint-770/special_tokens_map.jsonAdded+51
checkpoint-770/tokenizer.jsonAdded
checkpoint-770/tokenizer_config.jsonAdded+58
checkpoint-770/trainer_state.jsonAdded
checkpoint-770/training_args.binAdded+3
checkpoint-770/vocab.jsonAdded
classification.pyAdded+96
prompt.pyAdded+52
requirements.txtAdded+9