Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- .gitattributes +4 -34
- .github/workflows/main.yml +20 -0
- Sinhala_Singlish_Hate_Speech.csv +0 -0
- StopWords_425.txt +0 -0
- Suffixes-413.txt +0 -0
- app.py +121 -0
- requirements.txt +0 -0
- sinhala-hate-speech-dataset +3 -0
- sinhala-hate-speech-dataset.csv +0 -0
.gitattributes
CHANGED
|
@@ -1,34 +1,4 @@
|
|
| 1 |
-
*.
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.csv filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
sinhala-hate-speech-dataset.csv filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
Sinhala_Singlish_Hate_Speech.csv filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
sinhala-hate-speech-dataset filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.github/workflows/main.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face hub
|
| 2 |
+
on:
|
| 3 |
+
push:
|
| 4 |
+
branches: [main]
|
| 5 |
+
|
| 6 |
+
# to run this workflow manually from the Actions tab
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
- name: Push to hub
|
| 18 |
+
env:
|
| 19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 20 |
+
run: git push --force https://pojitha:[email protected]/spaces/pojitha/sinhalahatespeech main
|
Sinhala_Singlish_Hate_Speech.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
StopWords_425.txt
ADDED
|
Binary file (9.2 kB). View file
|
|
|
Suffixes-413.txt
ADDED
|
Binary file (5.32 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import numpy
|
| 3 |
+
from sklearn.pipeline import Pipeline
|
| 4 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 5 |
+
from sklearn.svm import SVC
|
| 6 |
+
from sklearn.metrics import accuracy_score
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import numpy as np
|
| 9 |
+
import streamlit as st
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
df1 = pd.read_csv('sinhala-hate-speech-dataset.csv')
|
| 13 |
+
df2 = pd.read_csv('Sinhala_Singlish_Hate_Speech.csv')
|
| 14 |
+
|
| 15 |
+
df2.columns= ["id","comment","label"]
|
| 16 |
+
|
| 17 |
+
df2['label'] = df2['label'].apply(lambda x: 1 if x == "YES" else 0)
|
| 18 |
+
|
| 19 |
+
df = pd.concat([df1, df2], sort=False)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
df.isnull().sum()
|
| 24 |
+
|
| 25 |
+
import re
|
| 26 |
+
|
| 27 |
+
exclude = set(",.:;'\"-?!/´`%")
|
| 28 |
+
def remove_punctutation(text):
|
| 29 |
+
return ''.join([(i if i not in exclude else " ") for i in text])
|
| 30 |
+
|
| 31 |
+
def remove_numbers(text):
|
| 32 |
+
return ''.join(c for c in text if not c.isnumeric())
|
| 33 |
+
|
| 34 |
+
df['clean_data'] = df['comment'].apply(lambda x: remove_punctutation((x)))
|
| 35 |
+
|
| 36 |
+
df['cleand'] = df['clean_data'].apply(lambda x: remove_numbers(x))
|
| 37 |
+
|
| 38 |
+
import nltk
|
| 39 |
+
from nltk.tokenize import word_tokenize
|
| 40 |
+
nltk.download('punkt')
|
| 41 |
+
|
| 42 |
+
df['tokens'] = df['cleand'].apply(word_tokenize)
|
| 43 |
+
|
| 44 |
+
with open("StopWords_425.txt", "r",encoding="utf-16") as file:
|
| 45 |
+
# Read the contents of the file
|
| 46 |
+
contents = file.read()
|
| 47 |
+
stop_word = contents.split()
|
| 48 |
+
stop_word = [word for word in stop_word if not any(char.isdigit() for char in word)]
|
| 49 |
+
print(stop_word)
|
| 50 |
+
|
| 51 |
+
df['tokens'] = df['tokens'].apply(lambda x: [item for item in x if item not in stop_word])
|
| 52 |
+
|
| 53 |
+
import nltk
|
| 54 |
+
from nltk.tokenize import word_tokenize
|
| 55 |
+
|
| 56 |
+
with open('Suffixes-413.txt', 'r', encoding='utf-16') as f:
|
| 57 |
+
stemmed_words = f.readlines()
|
| 58 |
+
|
| 59 |
+
stemmed_words = [word for word in stemmed_words if not any(char.isdigit() for char in word)]
|
| 60 |
+
stemmed_words = [word.strip() for word in stemmed_words]
|
| 61 |
+
stemmed_words = set(stemmed_words)
|
| 62 |
+
|
| 63 |
+
def stem_word(word):
|
| 64 |
+
if word in stemmed_words:
|
| 65 |
+
return word
|
| 66 |
+
else:
|
| 67 |
+
return nltk.stem.PorterStemmer().stem(word)
|
| 68 |
+
|
| 69 |
+
df['cleaneddata'] = df['tokens'].apply(lambda x: [stem_word(word) for word in x])
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
pipeline = Pipeline([
|
| 73 |
+
('tfidf', TfidfVectorizer(stop_words=stop_word, token_pattern=r'\b\w+\b')),
|
| 74 |
+
('svm', SVC())
|
| 75 |
+
])
|
| 76 |
+
|
| 77 |
+
from sklearn.model_selection import train_test_split
|
| 78 |
+
|
| 79 |
+
X_train, X_test, y_train, y_test = train_test_split(df['comment'], df['label'], test_size=0.3)
|
| 80 |
+
|
| 81 |
+
pipeline.fit(X_train, y_train)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
st.title("Sinhala Hate Speech Detector")
|
| 86 |
+
|
| 87 |
+
# Define the user input section
|
| 88 |
+
user_input = st.text_input("Enter a sentence")
|
| 89 |
+
|
| 90 |
+
# Define the model output section
|
| 91 |
+
if user_input:
|
| 92 |
+
# Check if the sentence is hate or not
|
| 93 |
+
user_pred = pipeline.predict([user_input])[0]
|
| 94 |
+
if user_pred == 1:
|
| 95 |
+
st.write("This sentence is hate.")
|
| 96 |
+
add_to_df = st.selectbox("Is this correct?", ["Choose a Option","Yes", "No"],index=0)
|
| 97 |
+
if add_to_df == "Yes":
|
| 98 |
+
st.write("Thank you")
|
| 99 |
+
else:
|
| 100 |
+
processed_text = pd.Series(user_input)
|
| 101 |
+
df = df.append({'comment': user_input, 'label': 0}, ignore_index=True)
|
| 102 |
+
df.to_csv("sinhala-hate-speech-dataset", index=False)
|
| 103 |
+
X_train, X_test, y_train, y_test = train_test_split(df['comment'], df['label'], test_size=0.3)
|
| 104 |
+
X_train = X_train.append(processed_text, ignore_index=True)
|
| 105 |
+
y_train = y_train.append(pd.Series([0]))
|
| 106 |
+
pipeline.fit(X_train, y_train)
|
| 107 |
+
st.write("Thank you for your contribution. We added that word into our system.")
|
| 108 |
+
else:
|
| 109 |
+
st.write("This sentence is not hate.")
|
| 110 |
+
add_to_df = st.selectbox("Is this correct?", ["Choose a Option","Yes", "No"],index=0)
|
| 111 |
+
if add_to_df == "Yes":
|
| 112 |
+
st.write("Thank you")
|
| 113 |
+
else:
|
| 114 |
+
processed_text = pd.Series(user_input)
|
| 115 |
+
df = df.append({'comment': user_input, 'label': 1}, ignore_index=True)
|
| 116 |
+
df.to_csv("sinhala-hate-speech-dataset.csv",index=True)
|
| 117 |
+
X_train, X_test, y_train, y_test = train_test_split(df['comment'], df['label'], test_size=0.3)
|
| 118 |
+
X_train = X_train.append(processed_text, ignore_index=True)
|
| 119 |
+
y_train = y_train.append(pd.Series([1]))
|
| 120 |
+
pipeline.fit(X_train, y_train)
|
| 121 |
+
st.write("Thank you for your contribution. We added that word into our system.")
|
requirements.txt
ADDED
|
Binary file (41.5 kB). View file
|
|
|
sinhala-hate-speech-dataset
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:372a6f64a4b68a8f5f820eac885dfa3526151acfab38dfb725d03f821de77c94
|
| 3 |
+
size 12901950
|
sinhala-hate-speech-dataset.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|