Skip to content

Commit 9f321a0

Browse files
wrote the first study material
1 parent 43becb4 commit 9f321a0

File tree

13 files changed

+255
-219
lines changed

13 files changed

+255
-219
lines changed

Algolyzer/playground/templates/playground/home.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
<h1 class="text-center my-10 font-bold font-poppins text-5xl">Playground</h1>
66
<h1 class="font-bold text-xl mb-5">Pre-Trained AIML Models</h1>
77

8+
{% comment %} Sentiment Analysis {% endcomment %}
89
<div class="flex flex-col gap-5">
910

1011
<div class="rounded-xl border-2 border-solid border-primary p-5 hover:border-secondary">
1112
<div class="flex md:items-center justify-between md:flex-row flex-col">
1213
<h1 class="text-4xl my-2 p-4 text-primary">Sentiment Analysis</h1>
1314
<div class="flex gap-4">
1415
<a href="{% url "sentiment_analysis" %}" class="btn btn-accent font-bold font-poppins max-md:flex-1">Try Now</a>
15-
<a href="#" class="btn btn-primary btn-outline max-md:flex-1">Learn More</a>
16+
<a href="{% url "sentiment_analysis_study" %}" class="btn btn-primary btn-outline max-md:flex-1">Learn More</a>
1617
</div>
1718
</div>
1819
<div class="flex flex-col md:flex-row gap-4">
@@ -58,6 +59,7 @@ <h1 class="text-4xl my-2 p-4 text-primary">Sentiment Analysis</h1>
5859
</div>
5960
</div>
6061

62+
{% comment %} Text Classifier {% endcomment %}
6163
<div class="rounded-xl border-2 border-solid border-primary p-5 hover:border-secondary">
6264
<div class="flex md:items-center justify-between md:flex-row flex-col">
6365
<h1 class="text-4xl my-2 p-4 text-primary">Text Classifier</h1>

Algolyzer/playground/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import json
22

3+
from django.contrib.auth.decorators import login_required
34
from django.shortcuts import redirect, render
5+
from home.decorators import profile_required
46
from playground.tasks import sentiment_analysis_task
57

68
from .models import PlaygroundTask
79

810

11+
@login_required
12+
@profile_required
913
# Home Page
1014
def playground_home(request):
1115
"""Renders the playground home page."""
1216
return render(request, "playground/home.html")
1317

1418

19+
@login_required
20+
@profile_required
1521
# Task Submission View
16-
17-
1822
def sentiment_analysis(request):
1923
"""Handles sentiment analysis model submission and task status retrieval."""
2024
user = request.user # Ensure the user is authenticated

Algolyzer/quiz/templates/quiz/topic.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
</div>
5454
</div>
5555
<div class="stat-value">86%</div>
56-
<div class="stat-title">Tasks done</div>
57-
<div class="stat-desc text-secondary">31 tasks remaining</div>
56+
<div class="stat-title">Reach</div>
57+
<div class="stat-desc text-secondary">Better than Before</div>
5858
</div>
5959
</div>
6060
</div>
@@ -68,8 +68,8 @@ <h2 class="font-bold text-4xl text-center text-primary">Rules</h2>
6868
<ul class="flex flex-col gap-3 mt-4 text-lg text-center">
6969
<li>There are {{total}} No of questions in this Quiz.</li>
7070
<li>Each right answer gives 2 XP points.</li>
71-
<li>There are {{total}} No of questions in this Quiz.</li>
72-
<li>There are {{total}} No of questions in this Quiz.</li>
71+
<li>There is NO time limit so answer without hasting</li>
72+
<li>Your Score will be evaluated at the end of the Quiz</li>
7373
</ul>
7474
</div>
7575
</div>

Algolyzer/study/admin.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

Algolyzer/study/models.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1 @@
1-
from django.db import models
2-
3-
4-
class Category(models.Model):
5-
name = models.CharField(max_length=255)
6-
parent = models.ForeignKey(
7-
"self",
8-
null=True,
9-
blank=True,
10-
on_delete=models.CASCADE,
11-
related_name="subcategories",
12-
)
13-
14-
def __str__(self):
15-
return self.name
16-
17-
18-
class Topic(models.Model):
19-
title = models.CharField(max_length=255)
20-
content = models.TextField()
21-
category = models.ForeignKey(Category, on_delete=models.CASCADE)
22-
created_at = models.DateTimeField(auto_now_add=True)
23-
24-
def __str__(self):
25-
return self.title
1+
# from django.db import models
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<div class="container mx-auto p-6">
5+
<h1 class=" my-10 text-poppins text-5xl">Detailed Explanation of <span class="font-bold font-poppins text-primary">Algolyzer</span> Models</h1>
6+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
7+
8+
{% comment %} sentiment analysis {% endcomment %}
9+
<a href="{% url 'sentiment_analysis_study' %}" class="card bg-base-200 shadow-xl lg:p-4 hover:bg-base-300 border-solid border-primary border-2 hover:border-secondary">
10+
<div class="card-body">
11+
<h3 class="text-3xl font-semibold capitalize">Sentiment Analysis</h3>
12+
13+
<div class="stats stats-vertical lg:stats-horizontal shadow">
14+
<div class="stat">
15+
<div class="stat-figure text-primary">
16+
<svg
17+
xmlns="http://www.w3.org/2000/svg"
18+
fill="none"
19+
viewBox="0 0 24 24"
20+
class="inline-block h-8 w-8 stroke-current">
21+
<path
22+
stroke-linecap="round"
23+
stroke-linejoin="round"
24+
stroke-width="2"
25+
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
26+
</svg>
27+
</div>
28+
<div class="stat-title">Avg Time To Read</div>
29+
<div class="stat-value text-primary">7 Mins</div>
30+
<div class="stat-desc"></div>
31+
</div>
32+
33+
<div class="stat">
34+
<div class="stat-title">Appx. Words</div>
35+
<div class="stat-value text-secondary">1,200</div>
36+
<div class="stat-desc"></div>
37+
</div>
38+
</div>
39+
</div>
40+
</a>
41+
42+
{% comment %} Text Classifier {% endcomment %}
43+
<a href="#" class="card bg-base-200 shadow-xl lg:p-4 hover:bg-base-300 border-solid border-primary border-2 hover:border-secondary">
44+
<div class="card-body">
45+
<h3 class="text-3xl font-semibold capitalize">Text Classifier</h3>
46+
<div class="stats stats-vertical lg:stats-horizontal shadow">
47+
<div class="stat">
48+
<div class="stat-figure text-primary">
49+
<svg
50+
xmlns="http://www.w3.org/2000/svg"
51+
fill="none"
52+
viewBox="0 0 24 24"
53+
class="inline-block h-8 w-8 stroke-current">
54+
<path
55+
stroke-linecap="round"
56+
stroke-linejoin="round"
57+
stroke-width="2"
58+
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
59+
</svg>
60+
</div>
61+
<div class="stat-title">Avg Time To Read</div>
62+
<div class="stat-value text-primary">3 Mins</div>
63+
<div class="stat-desc"></div>
64+
</div>
65+
66+
<div class="stat">
67+
<div class="stat-title">Appx. Words</div>
68+
<div class="stat-value text-secondary">500</div>
69+
<div class="stat-desc"></div>
70+
</div>
71+
</div>
72+
</div>
73+
</a>
74+
75+
{% comment %} Image Recognition {% endcomment %}
76+
<a href="#" class="card bg-base-200 shadow-xl lg:p-4 hover:bg-base-300 border-solid border-primary border-2 hover:border-secondary">
77+
<div class="card-body">
78+
<h3 class="text-3xl font-semibold capitalize">Image Recognition</h3>
79+
<div class="stats stats-vertical lg:stats-horizontal shadow">
80+
<div class="stat">
81+
<div class="stat-figure text-primary">
82+
<svg
83+
xmlns="http://www.w3.org/2000/svg"
84+
fill="none"
85+
viewBox="0 0 24 24"
86+
class="inline-block h-8 w-8 stroke-current">
87+
<path
88+
stroke-linecap="round"
89+
stroke-linejoin="round"
90+
stroke-width="2"
91+
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
92+
</svg>
93+
</div>
94+
<div class="stat-title">Avg Time To Read</div>
95+
<div class="stat-value text-primary">15 Mins</div>
96+
<div class="stat-desc"></div>
97+
</div>
98+
99+
<div class="stat">
100+
<div class="stat-title">Appx. Words</div>
101+
<div class="stat-value text-secondary">3,700</div>
102+
<div class="stat-desc"></div>
103+
</div>
104+
</div>
105+
</div>
106+
</a>
107+
</div>
108+
</div>
109+
{% endblock %}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<div class="max-w-5xl mx-auto py-5 max-sm:p-4">
5+
<h1 class="max-sm:text-4xl max-sm:my-6 text-5xl my-12">A Comprehensive Guide to <span class="text-primary font-bold font-poppins">Sentiment Analysis.</span></h1>
6+
<h2 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">Introduction</h2>
7+
<p class="max-sm:text-lg text-xl">Sentiment analysis, also known as opinion mining, is a natural language processing (NLP) technique used to determine the emotional tone behind a body of text. It is widely used in various fields, including customer feedback analysis, brand reputation management, social media monitoring, and market research.
8+
This guide will cover everything you need to know about sentiment analysis, from its basic concepts to advanced deep-learning techniques, including industry-standard approaches.</p>
9+
10+
<h1 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">What is Sentiment Analysis?</h1>
11+
<p class="max-sm:text-lg text-xl">Sentiment analysis is the process of classifying text as positive, negative, neutral, or even more nuanced emotions such as anger, happiness, or frustration. It helps businesses, researchers, and developers understand public opinion, monitor trends, and automate decision-making processes.</p>
12+
13+
<h1 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">Types of Sentiment Analysis</h1>
14+
<ul class="max-sm:text-lg text-xl">
15+
<li><strong class="">Binary Sentiment Analysis: </strong>The simplest form where sentiment is classified as either positive or negative.</li>
16+
<li><strong class="">Ternary Sentiment Analysis: </strong>Classification into positive, negative, or neutral.</li>
17+
<li><strong class="">Fine-grained Sentiment Analysis: </strong>Classifies sentiment on a more granular level, such as - Very Positive, Positive, Neutral, Negative, Very Negative</li>
18+
<li><strong class="">Aspect-based Sentiment Analysis (ABSA): </strong>Identifies sentiment regarding specific aspects of a text.</li>
19+
<li><strong class="">Emotion Detection: </strong>Detects specific emotions like joy, anger, sadness, or fear.</li>
20+
</ul>
21+
22+
<h1 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">How Sentiment Analysis Works?</h1>
23+
<p class="max-sm:text-lg text-xl">Sentiment analysis can be performed using various methods, ranging from simple rule-based approaches to advanced deep learning models.</p>
24+
25+
<h2 class="max-sm:text-lg text-xl text-secondary font-bold">A. Rule-Based Approach</h2>
26+
<p class="max-sm:text-lg text-xl">Uses predefined rules and lexicons (word dictionaries) to classify sentiment.</p>
27+
<p class="max-sm:text-lg text-xl"><strong>Example:</strong> If a text contains words like "excellent", "good", or "amazing", it is classified as positive.</p>
28+
29+
<h3 class="max-sm:text-lg text-xl font-bold">Popular lexicons:</h3>
30+
<ul class="max-sm:text-lg text-xl">
31+
<li> - AFINN</li>
32+
<li> - SentiWordNet</li>
33+
<li> - VADER (Valence Aware Dictionary and sEntiment Reasoner) (works well on social media text)</li>
34+
</ul>
35+
36+
<h2 class="max-sm:text-lg text-xl text-secondary font-bold">B. Machine Learning Approach</h2>
37+
<p class="max-sm:text-lg text-xl">Uses labeled datasets to train models that predict sentiment. Common techniques include:</p>
38+
<ul class="max-sm:text-lg text-xl">
39+
<li> - Naive Bayes Classifier (Simple yet effective for text classification)</li>
40+
<li> - Support Vector Machines (SVMs)</li>
41+
<li> - Logistic Regression</li>
42+
<li> - Decision Trees and Random Forests</li>
43+
</ul>
44+
45+
<h2 class="max-sm:text-lg text-xl text-secondary font-bold">C. Deep Learning Approach</h2>
46+
<ul class="max-sm:text-lg text-xl">
47+
<li><strong>Recurrent Neural Networks (RNNs) & Long Short-Term Memory (LSTMs)</strong>
48+
<ul class="max-sm:text-lg text-xl">
49+
<li> - Used for sequential data like text.</li>
50+
<li> - Can capture context better than traditional ML models.</li>
51+
</ul>
52+
</li>
53+
<li><strong>Transformers (BERT, RoBERTa, GPT)</strong>
54+
<ul class="max-sm:text-lg text-xl">
55+
<li> - State-of-the-art NLP models.</li>
56+
<li> - Pre-trained on large datasets for contextual understanding.</li>
57+
</ul>
58+
</li>
59+
</ul>
60+
61+
<h1 class="max-sm:text-4xl text-5xl my-12">About <span class="text-primary font-bold font-poppins">DistilBERT-Base-Uncased-Finetuned-SST-2-English</span> Model</h1>
62+
<h2 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">Introduction</h2>
63+
<p class="max-sm:text-lg text-xl"><strong>distilbert-base-uncased-finetuned-sst-2-english</strong> is a pretrained transformer-based model developed by Hugging Face. It is a fine-tuned version of DistilBERT, specifically trained on the Stanford Sentiment Treebank (SST-2) dataset for sentiment analysis. This model is optimized for classifying text as positive or negative sentiment, making it highly effective for analyzing opinions, reviews, and social media posts.</p>
64+
65+
<h2 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">How to use?</h2>
66+
<p class="max-sm:text-lg text-xl">The easiest way to use the model is through the Hugging Face transformers library, But for the sake of explanation here's a code snippet of how to use this model with PyTorch</p>
67+
<div class="mockup-code mt-2">
68+
<pre data-prefix="1"><code>from transformers import DistilBertTokenizer, DistilBertForSequenceClassification</code></pre>
69+
<pre data-prefix="2"><code>import torch</code></pre>
70+
<pre data-prefix="3"><code></code></pre>
71+
<pre data-prefix="4"><code># Load tokenizer and model</code></pre>
72+
<pre data-prefix="5"><code>tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")</code></pre>
73+
<pre data-prefix="6"><code>model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")</code></pre>
74+
<pre data-prefix="7"><code></code></pre>
75+
<pre data-prefix="8"><code># Example text</code></pre>
76+
<pre data-prefix="9"><code>text = "This product is terrible, I regret buying it."</code></pre>
77+
<pre data-prefix="10"><code></code></pre>
78+
<pre data-prefix="11"><code># Tokenize input text</code></pre>
79+
<pre data-prefix="12"><code>inputs = tokenizer(text, return_tensors="pt")</code></pre>
80+
<pre data-prefix="13"><code></code></pre>
81+
<pre data-prefix="14"><code># Perform inference</code></pre>
82+
<pre data-prefix="15"><code>with torch.no_grad():</code></pre>
83+
<pre data-prefix="16"><code> outputs = model(**inputs)</code></pre>
84+
<pre data-prefix="17"><code></code></pre>
85+
<pre data-prefix="18"><code># Get predicted class</code></pre>
86+
<pre data-prefix="19"><code>logits = outputs.logits</code></pre>
87+
<pre data-prefix="20"><code>predicted_class = torch.argmax(logits).item()</code></pre>
88+
<pre data-prefix="21"><code></code></pre>
89+
<pre data-prefix="22"><code># Interpret result</code></pre>
90+
<pre data-prefix="23"><code>labels = ["NEGATIVE", "POSITIVE"]</code></pre>
91+
<pre data-prefix="24"><code>print(labels[predicted_class])</code></pre>
92+
</div>
93+
94+
<h2 class="max-sm:text-2xl text-3xl my-5 text-primary font-bold">Output</h2>
95+
<div class="mockup-code">
96+
<pre data-prefix="$"><code>NEGATIVE</code></pre>
97+
</div>
98+
99+
<h2 class="max-sm:text-2xl text-3xl my-5 font-bold">Why <span class="text-primary font-bold font-poppins">Algolyzer</span> uses this model?</h2>
100+
<ul class="max-sm:text-lg text-xl">
101+
<li>✅ Lightweight and Efficient - Faster than BERT while maintaining high accuracy.</li>
102+
<li>✅ High Accuracy - Fine-tuned on SST-2, achieving state-of-the-art performance.</li>
103+
<li>✅ Easy to Use - Direct integration with Hugging Face’s transformers library.</li>
104+
<li>✅ Suitable for Real-time Applications - Can process text quickly, making it ideal for chatbots, feedback analysis, etc.</li>
105+
</ul>
106+
</div>
107+
{% endblock %}

0 commit comments

Comments
 (0)