File size: 917 Bytes
4bfb7b6
b9797cb
4bfb7b6
d0c0a4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bfb7b6
d0c0a4a
 
 
 
 
 
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
import re
import pandas as pd

# 1️⃣ Data loading + cleaning

def load_and_clean_data():
    # Load train+val
    df = pd.read_csv(
        "https://drive.google.com/uc?export=download&id=14D_HcvTFL63-KffCQLNFxGH-oY_knwmo",
        delimiter=';', header=None, names=['sentence','label']
    )
    # Load test
    ts = pd.read_csv(
        "https://drive.google.com/uc?export=download&id=1Vmr1Rfv4pLSlAUrlOCxAcszvlxJOSHrm",
        delimiter=';', header=None, names=['sentence','label']
    )
    df = pd.concat([df, ts], ignore_index=True)
    df.drop_duplicates(inplace=True)
    df['clean'] = df['sentence'].apply(clean_text)
    return df

# 2️⃣ Text cleaning utility
def clean_text(text):
    if pd.isnull(text): return ""
    t = text.lower()
    t = re.sub(r"http\S+|www\S+|https\S+", "", t)
    t = re.sub(r"\@\w+|\#", "", t)
    t = re.sub(r"[^a-z\s]", "", t)
    return re.sub(r"\s+", " ", t).strip()