Skip to content

Commit

Permalink
Create nlp_module.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 26, 2024
1 parent c2b4516 commit bfce7e2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ai_core/examples/nlp_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
nlp_module = NaturalLanguageProcessingModule()

# Train the model
X_train = [
"This product is amazing!",
"I love this product!",
"This product is terrible.",
"I hate this product.",
"This product is okay.",
"I'm neutral about this product."
]
y_train = [1, 1, 0, 0, 0.5, 0.5] # 1: positive, 0: negative, 0.5: neutral

nlp_module.train(X_train, y_train)

# Predict sentiment
text = "This is a great product!"
sentiment = nlp_module.sentiment_analysis(text)
print("Sentiment:", sentiment)

# Predict topics
texts = [
"I love playing basketball.",
"The new iPhone is amazing.",
"I'm so excited for the summer.",
"This restaurant serves great food.",
"I'm feeling sad today."
]
topics = nlp_module.topic_modeling(texts)
print("Topics:", topics)

0 comments on commit bfce7e2

Please sign in to comment.