File size: 1,141 Bytes
c82e328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from sentence_transformers import SentenceTransformer
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report
import numpy as np
import os
import sys
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "src"))
sys.path.append(src_directory)
from data import sample_data

file_path = r"D:\Jupyter_project\sms_process_data_main.xlsx"
df = sample_data.get_data_frame(file_path)

def get_label(message):
    X_train, X_test, y_train, y_test = train_test_split(df['MessageText'], df['label'], test_size=0.2, random_state=42)
    model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
    X_train_embeddings = model.encode(X_train.tolist())
    models = LogisticRegression(max_iter=100)
    models.fit(X_train_embeddings, y_train)
    new_embeddings = model.encode(message)
    array = np.array(new_embeddings).tolist()
    # new_predictions = models.predict(new_embeddings)
    dimention = pd.DataFrame(array,columns=["Dimention"])
    return dimention