Go Swear Words Logistic Regression
This project implements a logistic regression model to detect swear words in text. The model is trained using a predefined vocabulary and can predict whether a given word is considered profane.
Profanity List
The profanity list used in this project is sourced from:
Surge AI Profanity List
Usage
To train the model and run predictions, follow these steps:
-
Prepare your training data and test cases within the code.
-
Run the tests to ensure everything is working correctly:
go test
-
Use the logistic regression model in your application:
package main
import (
"fmt"
)
func main() {
lr := &LogisticRegression{}
// Define your vocabulary
vocabulary := map[string]int{
"hello": 0,
"world": 1,
"goodbye": 2,
}
// Define your training data
trainingData := []struct {
text string
label float64
}{
{"hello world", 0},
{"goodbye world", 1},
}
// Prepare training samples and labels
var samples [][]float64
var labels []float64
for _, data := range trainingData {
sample := make([]float64, len(vocabulary))
words := strings.Fields(data.text)
for _, word := range words {
if index, exists := vocabulary[strings.ToLower(word)]; exists {
sample[index]++
}
}
samples = append(samples, sample)
labels = append(labels, data.label)
}
// Train the model
lr.train(samples, labels)
// Predict a new sample
newSample := make([]float64, len(vocabulary))
newSample[vocabulary["hello"]]++
prediction := lr.predict(newSample)
fmt.Printf("Prediction: %f\n", prediction)
}
Contributing
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
).
- Make your changes.
- Commit your changes (
git commit -m 'Add new feature'
).
- Push to the branch (
git push origin feature-branch
).
- Open a pull request.
Tests
The project is tested by one integration test that check the entire flow of the project.
License
This project is licensed under the MIT License. See the LICENSE file for details.