Spaces:
Sleeping
Sleeping
feat: update src
Browse files- Shopee_Reviews_Analysis.ipynb +0 -0
- data/shopee_sentiment.csv +0 -0
- src/evalute.py +0 -40
- src/pipeline/__init__.py +0 -0
- src/pipeline/inference_pipeline.py +0 -29
- src/pipeline/train_pipeline.py +0 -49
- src/train_model.py +0 -6
Shopee_Reviews_Analysis.ipynb
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/shopee_sentiment.csv
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/evalute.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import joblib
|
| 3 |
-
|
| 4 |
-
from sklearn.model_selection import train_test_split
|
| 5 |
-
from sklearn.metrics import classification_report
|
| 6 |
-
|
| 7 |
-
from src.preprocess import load_stopwords, preprocess
|
| 8 |
-
from src.build_features import transform_features
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
DATA_PATH = "data/shopee_sentiment.csv"
|
| 12 |
-
STOPWORD_PATH = "data/vietnamese-stopwords.txt"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def main():
|
| 16 |
-
df = pd.read_csv(DATA_PATH)
|
| 17 |
-
|
| 18 |
-
df = df.dropna(subset=["text", "label"])
|
| 19 |
-
df = df.drop_duplicates(subset=["text"])
|
| 20 |
-
|
| 21 |
-
stopwords = load_stopwords(STOPWORD_PATH)
|
| 22 |
-
df["text"] = df["text"].apply(lambda x: preprocess(x, stopwords))
|
| 23 |
-
df["text"] = df["text"].apply(lambda x: " ".join(x))
|
| 24 |
-
|
| 25 |
-
X_train, X_test, y_train, y_test = train_test_split(
|
| 26 |
-
df["text"], df["label"], test_size=0.2, random_state=42
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
model = joblib.load("models/model.pkl")
|
| 30 |
-
vectorizer = joblib.load("models/vectorizer.pkl")
|
| 31 |
-
|
| 32 |
-
X_test_vec = transform_features(X_test, vectorizer)
|
| 33 |
-
|
| 34 |
-
y_pred = model.predict(X_test_vec)
|
| 35 |
-
|
| 36 |
-
print(classification_report(y_test, y_pred))
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
if __name__ == "__main__":
|
| 40 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/pipeline/__init__.py
DELETED
|
File without changes
|
src/pipeline/inference_pipeline.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import joblib
|
| 2 |
-
|
| 3 |
-
from src.preprocess import preprocess, load_stopwords
|
| 4 |
-
from src.build_features import transform_features
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
STOPWORD_PATH = "data/vietnamese-stopwords.txt"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def predict(text):
|
| 11 |
-
# Load
|
| 12 |
-
model = joblib.load("models/model.pkl")
|
| 13 |
-
vectorizer = joblib.load("models/vectorizer.pkl")
|
| 14 |
-
stopwords = load_stopwords(STOPWORD_PATH)
|
| 15 |
-
|
| 16 |
-
# Preprocess
|
| 17 |
-
tokens = preprocess(text, stopwords)
|
| 18 |
-
text_clean = " ".join(tokens)
|
| 19 |
-
|
| 20 |
-
# Feature
|
| 21 |
-
X = transform_features([text_clean], vectorizer)
|
| 22 |
-
|
| 23 |
-
# Predict
|
| 24 |
-
return model.predict(X)[0]
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
if __name__ == "__main__":
|
| 28 |
-
text = input("Enter text: ")
|
| 29 |
-
print("Prediction:", "positive" if predict(text) == 1 else "negative")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/pipeline/train_pipeline.py
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import joblib
|
| 3 |
-
|
| 4 |
-
from sklearn.model_selection import train_test_split
|
| 5 |
-
|
| 6 |
-
from src.preprocess import load_stopwords, preprocess
|
| 7 |
-
from src.build_features import build_features
|
| 8 |
-
from src.train_model import train_model
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# ===== CONFIG =====
|
| 12 |
-
DATA_PATH = "data/shopee_sentiment.csv"
|
| 13 |
-
STOPWORD_PATH = "data/vietnamese-stopwords.txt"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def run_pipeline():
|
| 17 |
-
# 1. Load data
|
| 18 |
-
df = pd.read_csv(DATA_PATH)
|
| 19 |
-
|
| 20 |
-
# 2. Clean
|
| 21 |
-
df = df.dropna(subset=["text", "label"])
|
| 22 |
-
df = df.drop_duplicates(subset=["text"])
|
| 23 |
-
|
| 24 |
-
# 3. Preprocess
|
| 25 |
-
stopwords = load_stopwords(STOPWORD_PATH)
|
| 26 |
-
df["text"] = df["text"].apply(lambda x: preprocess(x, stopwords))
|
| 27 |
-
df["text"] = df["text"].apply(lambda x: " ".join(x))
|
| 28 |
-
|
| 29 |
-
# 4. Split
|
| 30 |
-
X_train, X_test, y_train, y_test = train_test_split(
|
| 31 |
-
df["text"], df["label"], test_size=0.2, random_state=42
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# 5. Feature
|
| 35 |
-
X_train_vec, vectorizer = build_features(X_train)
|
| 36 |
-
X_test_vec = vectorizer.transform(X_test)
|
| 37 |
-
|
| 38 |
-
# 6. Train
|
| 39 |
-
model = train_model(X_train_vec, y_train)
|
| 40 |
-
|
| 41 |
-
# 7. Save
|
| 42 |
-
joblib.dump(model, "models/model.pkl")
|
| 43 |
-
joblib.dump(vectorizer, "models/vectorizer.pkl")
|
| 44 |
-
|
| 45 |
-
print("Pipeline training completed!")
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
if __name__ == "__main__":
|
| 49 |
-
run_pipeline()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/train_model.py
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
from sklearn.svm import SVC
|
| 2 |
-
|
| 3 |
-
def train_model(X_train, y_train):
|
| 4 |
-
model = SVC(kernel='linear')
|
| 5 |
-
model.fit(X_train, y_train)
|
| 6 |
-
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|