aditdwi123 commited on
Commit
1a70b10
1 Parent(s): bacb444

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -7
README.md CHANGED
@@ -1,9 +1,57 @@
1
  ---
2
- license: mit
3
- language:
4
- - id
5
  tags:
6
- - sentiment-analysis
7
- - text-classification
8
- - naive-bayes
9
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: id
 
 
3
  tags:
4
+ - sentiment-analysis
5
+ - text-classification
6
+ - naive-bayes
7
+ license: mit
8
+ ---
9
+
10
+ # SentimentAnalyzer
11
+
12
+ **SentimentAnalyzer** adalah model analisis sentimen berbasis Naive Bayes yang dirancang untuk mengklasifikasikan kalimat dalam bahasa Indonesia ke dalam kategori sentimen seperti positif, negatif, atau netral.
13
+
14
+ ## Deskripsi Model
15
+
16
+ Model ini menggunakan algoritma Naive Bayes untuk analisis sentimen. Model ini dilatih menggunakan dataset teks dalam bahasa Indonesia yang berisi kalimat-kalimat dengan label sentimen. Model ini dapat digunakan untuk mengidentifikasi sentimen dari teks bahasa Indonesia dengan akurasi yang baik.
17
+
18
+ ## Penggunaan
19
+
20
+ Berikut adalah contoh kode untuk mengunduh dan menggunakan model ini:
21
+
22
+ ```python
23
+ from huggingface_hub import hf_hub_download
24
+ import pickle
25
+ import nltk
26
+ from nltk.tokenize import word_tokenize
27
+ from nltk.corpus import stopwords
28
+ import string
29
+
30
+ # Unduh model dari Hugging Face
31
+ model_path = hf_hub_download(repo_id="aditdwi123/SentimentAnalyzer", filename="naive_bayes_model.pkl")
32
+
33
+ # Muat model dari file
34
+ with open(model_path, "rb") as model_file:
35
+ model = pickle.load(model_file)
36
+
37
+ # Fungsi untuk preprocessing teks
38
+ def preprocess(text):
39
+ text = text.lower() # Konversi ke huruf kecil
40
+ tokens = word_tokenize(text) # Tokenisasi
41
+ tokens = [t for t in tokens if t not in stopwords.words('indonesian') and t not in string.punctuation] # Hapus stopwords dan tanda baca
42
+ return tokens
43
+
44
+ # Fungsi untuk mengekstrak fitur dari setiap kata
45
+ def extract_features(words):
46
+ return {word: True for word in words}
47
+
48
+ # Fungsi untuk mengklasifikasikan kalimat
49
+ def classify_sentence(sentence):
50
+ features = extract_features(preprocess(sentence))
51
+ return model.classify(features)
52
+
53
+ # Uji model dengan kalimat baru
54
+ test_sentence = "saya sangat senang dengan pelayanan yang baik"
55
+ predicted_sentiment = classify_sentence(test_sentence)
56
+ print(f"Kalimat: {test_sentence}")
57
+ print(f"Prediksi Sentimen: {predicted_sentiment}")