Spaces:
Sleeping
Sleeping
Update app.py
#1
by
Mpavan45
- opened
app.py
CHANGED
|
@@ -306,255 +306,256 @@ elif selected_page == "๐ Lifecycle of NLP":
|
|
| 306 |
|
| 307 |
elif selected_page == "โ๏ธ NLP Techniques":
|
| 308 |
st.header("โ๏ธ NLP Techniques")
|
| 309 |
-
if selected_subpoint
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
""")
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
**Example:**
|
| 323 |
-
- Input: `["running", "runner", "runs"]`
|
| 324 |
-
- Output: `["run", "runner", "run"]` (Porter Stemmer)
|
| 325 |
-
|
| 326 |
-
**Key Points:**
|
| 327 |
-
- **Fast** and **simple**, but can lead to over-stemming or under-stemming.
|
| 328 |
-
- Example of over-stemming: `"generous"` โ `"gener"`
|
| 329 |
-
|
| 330 |
-
**Code Example:**
|
| 331 |
-
```python
|
| 332 |
-
from nltk.stem import PorterStemmer
|
| 333 |
-
|
| 334 |
-
stemmer = PorterStemmer()
|
| 335 |
-
words = ["running", "runner", "runs"]
|
| 336 |
-
print([stemmer.stem(word) for word in words])
|
| 337 |
-
# Output: ['run', 'runner', 'run']
|
| 338 |
-
```
|
| 339 |
-
""")
|
| 340 |
-
|
| 341 |
-
elif selected_subpoint == " Lemmatization":
|
| 342 |
-
st.write("### ๐ฟ Lemmatization")
|
| 343 |
-
st.write("""
|
| 344 |
-
Lemmatization reduces words to their dictionary base form (lemma), ensuring grammatical correctness.
|
| 345 |
-
|
| 346 |
-
**Example:**
|
| 347 |
-
- Input: `["running", "ran", "better"]`
|
| 348 |
-
- Output: `["run", "run", "good"]`
|
| 349 |
-
|
| 350 |
-
**Key Points:**
|
| 351 |
-
- Context-aware and accurate.
|
| 352 |
-
- More computationally intensive than stemming.
|
| 353 |
-
|
| 354 |
-
**Code Example:**
|
| 355 |
-
```python
|
| 356 |
-
from nltk.stem import WordNetLemmatizer
|
| 357 |
-
|
| 358 |
-
lemmatizer = WordNetLemmatizer()
|
| 359 |
-
words = ["running", "ran", "better"]
|
| 360 |
-
print([lemmatizer.lemmatize(word, pos="v") for word in words])
|
| 361 |
-
```
|
| 362 |
-
""")
|
| 363 |
-
elif selected_subpoint == " stop Words":
|
| 364 |
-
st.write("### ๐ซ Stop Words")
|
| 365 |
-
st.write("""
|
| 366 |
-
Stop words are common words (e.g., *the*, *is*) that are removed during text processing as they don't add much meaning.
|
| 367 |
-
|
| 368 |
-
**Example:**
|
| 369 |
-
- Input: `"This is a simple sentence."`
|
| 370 |
-
- Output: `"simple sentence"`
|
| 371 |
-
|
| 372 |
-
**Code Example:**
|
| 373 |
-
```python
|
| 374 |
-
from nltk.corpus import stopwords
|
| 375 |
-
|
| 376 |
-
stop_words = set(stopwords.words("english"))
|
| 377 |
-
sentence = "This is a simple sentence."
|
| 378 |
-
filtered_sentence = [word for word in sentence.split() if word.lower() not in stop_words]
|
| 379 |
-
print(filtered_sentence) # Output: ['simple', 'sentence']
|
| 380 |
-
```
|
| 381 |
-
""")
|
| 382 |
-
|
| 383 |
-
elif selected_subpoint == " One Hot Encoding":
|
| 384 |
-
st.write("### ๐ฅ One-Hot Encoding")
|
| 385 |
-
st.write("""
|
| 386 |
-
Representing categorical data as binary vectors to make it suitable for machine learning models.
|
| 387 |
-
|
| 388 |
-
**How it works:**
|
| 389 |
-
- Each unique category is assigned a unique binary vector.
|
| 390 |
-
- A binary vector has all values as `0` except for the position representing the category, which is `1`.
|
| 391 |
-
|
| 392 |
-
**Example:**
|
| 393 |
-
- Categories: `["Apple", "Banana", "Cherry"]`
|
| 394 |
-
- Encoding:
|
| 395 |
-
- `Apple`: `[1, 0, 0]`
|
| 396 |
-
- `Banana`: `[0, 1, 0]`
|
| 397 |
-
- `Cherry`: `[0, 0, 1]`
|
| 398 |
-
""")
|
| 399 |
-
|
| 400 |
-
st.write("### ๐ Example with Fruits")
|
| 401 |
-
st.write("""
|
| 402 |
-
**Input Categories:** `["Apple", "Banana", "Cherry", "Banana", "Apple"]`
|
| 403 |
-
**Output (One-Hot Encoding):**
|
| 404 |
-
- `Apple`: `[1, 0, 0]`
|
| 405 |
-
- `Banana`: `[0, 1, 0]`
|
| 406 |
-
- `Cherry`: `[0, 0, 1]`
|
| 407 |
-
- `Banana`: `[0, 1, 0]`
|
| 408 |
-
- `Apple`: `[1, 0, 0]`
|
| 409 |
-
""")
|
| 410 |
-
|
| 411 |
-
elif selected_subpoint == " Bag Of Words":
|
| 412 |
-
st.write("### ๐ Bag of Words (BoW)")
|
| 413 |
-
st.write("""
|
| 414 |
-
Bag of Words converts text into a matrix of word frequencies, where each word is represented by a unique index in the vocabulary.
|
| 415 |
-
|
| 416 |
-
**Example:**
|
| 417 |
-
- Input: `["I love NLP", "NLP is fun"]`
|
| 418 |
-
- Vocabulary: `["I", "love", "NLP", "is", "fun"]`
|
| 419 |
-
- BoW Matrix:
|
| 420 |
-
- `"I love NLP"`: `[1, 1, 1, 0, 0]`
|
| 421 |
-
- `"NLP is fun"`: `[0, 0, 1, 1, 1]`
|
| 422 |
-
|
| 423 |
-
**Code Example:**
|
| 424 |
-
```python
|
| 425 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
| 426 |
-
|
| 427 |
-
documents = ["I love NLP", "NLP is fun"]
|
| 428 |
-
vectorizer = CountVectorizer()
|
| 429 |
-
bow_matrix = vectorizer.fit_transform(documents)
|
| 430 |
-
|
| 431 |
-
print(bow_matrix.toarray()) # Output: [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]]
|
| 432 |
-
```
|
| 433 |
-
""")
|
| 434 |
-
|
| 435 |
-
elif selected_subpoint == " Binary Bag Of Words":
|
| 436 |
-
st.write("### ๐ฒ Binary Bag of Words")
|
| 437 |
-
st.write("""
|
| 438 |
-
Binary Bag of Words is a variation of the BoW model where each word is represented by `1` if present in the document and `0` if absent, ignoring word frequencies.
|
| 439 |
-
|
| 440 |
-
**Example:**
|
| 441 |
-
- Input: `["I love NLP", "NLP is fun"]`
|
| 442 |
-
- Vocabulary: `["I", "love", "NLP", "is", "fun"]`
|
| 443 |
-
- Binary BoW Matrix:
|
| 444 |
-
- `"I love NLP"`: `[1, 1, 1, 0, 0]`
|
| 445 |
-
- `"NLP is fun"`: `[0, 0, 1, 1, 1]`
|
| 446 |
-
|
| 447 |
-
**Code Example:**
|
| 448 |
-
```python
|
| 449 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
| 450 |
-
|
| 451 |
-
documents = ["I love NLP", "NLP is fun"]
|
| 452 |
-
vectorizer = CountVectorizer(binary=True)
|
| 453 |
-
binary_bow_matrix = vectorizer.fit_transform(documents)
|
| 454 |
-
|
| 455 |
-
print(binary_bow_matrix.toarray()) # Output: [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]]
|
| 456 |
-
```
|
| 457 |
-
""")
|
| 458 |
-
|
| 459 |
-
elif selected_subpoint == " TF-IDF":
|
| 460 |
-
st.write("### ๐งฎ TF-IDF (Term Frequency - Inverse Document Frequency)")
|
| 461 |
-
st.write("""
|
| 462 |
-
TF-IDF is a statistical measure used to evaluate how important a word is to a document in a collection or corpus. It considers two factors:
|
| 463 |
-
- **Term Frequency (TF)**: The frequency of a word in a document.
|
| 464 |
-
- **Inverse Document Frequency (IDF)**: The importance of the word across all documents in the corpus. Words that appear in many documents are less important.
|
| 465 |
-
|
| 466 |
-
The formula for TF-IDF is:
|
| 467 |
-
- **TF-IDF = TF * IDF**
|
| 468 |
-
|
| 469 |
-
**Example:**
|
| 470 |
-
Consider three documents:
|
| 471 |
-
1. `"I love programming"`
|
| 472 |
-
2. `"Programming is fun"`
|
| 473 |
-
3. `"I love Python programming"`
|
| 474 |
-
|
| 475 |
-
- **TF (for "programming")**:
|
| 476 |
-
- Document 1: `1/3`
|
| 477 |
-
- Document 2: `1/3`
|
| 478 |
-
- Document 3: `1/3`
|
| 479 |
-
|
| 480 |
-
- **IDF (for "programming")**:
|
| 481 |
-
- IDF = log(3/3) = 0 (common word, less informative)
|
| 482 |
-
|
| 483 |
-
**Code Example:**
|
| 484 |
-
```python
|
| 485 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 486 |
-
|
| 487 |
-
documents = ["I love programming", "Programming is fun", "I love Python programming"]
|
| 488 |
-
vectorizer = TfidfVectorizer()
|
| 489 |
-
tfidf_matrix = vectorizer.fit_transform(documents)
|
| 490 |
-
|
| 491 |
-
print(tfidf_matrix.toarray()) # Output will show TF-IDF scores for each word in each document
|
| 492 |
-
```
|
| 493 |
-
""")
|
| 494 |
-
|
| 495 |
-
elif selected_subpoint == " Word Embeddings":
|
| 496 |
-
st.write("### ๐ค Word Embeddings")
|
| 497 |
-
st.write("""
|
| 498 |
-
Word embeddings are dense vector representations of words in a continuous vector space, capturing semantic meanings and relationships between words.
|
| 499 |
-
|
| 500 |
-
**Types of Word Embeddings:**
|
| 501 |
-
|
| 502 |
-
1. **Word2Vec**: Learns word associations from context using two approaches: Word2Vec is a model that transforms words into dense vector representations in a continuous vector space, capturing semantic relationships. It learns these representations by predicting words based on their context.
|
| 503 |
-
|
| 504 |
-
- **Skip-gram model**: This model predicts context words from a target word, similar to Word2Vec's Skip-gram model. It's useful for capturing word relationships, and it works well with smaller datasets.
|
| 505 |
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
3. **FastText**: Extends Word2Vec by breaking words into subword units, which helps capture morphology and represent rare or unseen words.
|
| 511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
|
| 559 |
|
| 560 |
|
|
|
|
| 306 |
|
| 307 |
elif selected_page == "โ๏ธ NLP Techniques":
|
| 308 |
st.header("โ๏ธ NLP Techniques")
|
| 309 |
+
if selected_subpoint:
|
| 310 |
+
if selected_subpoint == "Tokenization":
|
| 311 |
+
st.write("""
|
| 312 |
+
Breaking down text into smaller units such as words or sentences to make it manageable for analysis.
|
| 313 |
+
**Example:**
|
| 314 |
+
- Input: `"Artificial Intelligence is fascinating."`
|
| 315 |
+
- Word Tokens: `["Artificial", "Intelligence", "is", "fascinating", "."]`
|
| 316 |
+
- Sentence Tokens: `["Artificial Intelligence is fascinating."]`
|
| 317 |
+
""")
|
| 318 |
+
elif selected_subpoint == "Stemming":
|
| 319 |
+
st.write("### ๐ฑ Stemming")
|
| 320 |
+
st.write("""
|
| 321 |
+
Stemming reduces words to their root form by removing prefixes or suffixes, often resulting in a non-grammatical base.
|
| 322 |
+
|
| 323 |
+
**Example:**
|
| 324 |
+
- Input: `["running", "runner", "runs"]`
|
| 325 |
+
- Output: `["run", "runner", "run"]` (Porter Stemmer)
|
| 326 |
+
|
| 327 |
+
**Key Points:**
|
| 328 |
+
- **Fast** and **simple**, but can lead to over-stemming or under-stemming.
|
| 329 |
+
- Example of over-stemming: `"generous"` โ `"gener"`
|
| 330 |
+
|
| 331 |
+
**Code Example:**
|
| 332 |
+
```python
|
| 333 |
+
from nltk.stem import PorterStemmer
|
| 334 |
+
|
| 335 |
+
stemmer = PorterStemmer()
|
| 336 |
+
words = ["running", "runner", "runs"]
|
| 337 |
+
print([stemmer.stem(word) for word in words])
|
| 338 |
+
# Output: ['run', 'runner', 'run']
|
| 339 |
+
```
|
| 340 |
""")
|
| 341 |
+
|
| 342 |
+
elif selected_subpoint == " Lemmatization":
|
| 343 |
+
st.write("### ๐ฟ Lemmatization")
|
| 344 |
+
st.write("""
|
| 345 |
+
Lemmatization reduces words to their dictionary base form (lemma), ensuring grammatical correctness.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
+
**Example:**
|
| 348 |
+
- Input: `["running", "ran", "better"]`
|
| 349 |
+
- Output: `["run", "run", "good"]`
|
|
|
|
|
|
|
| 350 |
|
| 351 |
+
**Key Points:**
|
| 352 |
+
- Context-aware and accurate.
|
| 353 |
+
- More computationally intensive than stemming.
|
| 354 |
+
|
| 355 |
+
**Code Example:**
|
| 356 |
+
```python
|
| 357 |
+
from nltk.stem import WordNetLemmatizer
|
| 358 |
+
|
| 359 |
+
lemmatizer = WordNetLemmatizer()
|
| 360 |
+
words = ["running", "ran", "better"]
|
| 361 |
+
print([lemmatizer.lemmatize(word, pos="v") for word in words])
|
| 362 |
+
```
|
| 363 |
+
""")
|
| 364 |
+
elif selected_subpoint == " stop Words":
|
| 365 |
+
st.write("### ๐ซ Stop Words")
|
| 366 |
+
st.write("""
|
| 367 |
+
Stop words are common words (e.g., *the*, *is*) that are removed during text processing as they don't add much meaning.
|
| 368 |
+
|
| 369 |
+
**Example:**
|
| 370 |
+
- Input: `"This is a simple sentence."`
|
| 371 |
+
- Output: `"simple sentence"`
|
| 372 |
+
|
| 373 |
+
**Code Example:**
|
| 374 |
+
```python
|
| 375 |
+
from nltk.corpus import stopwords
|
| 376 |
+
|
| 377 |
+
stop_words = set(stopwords.words("english"))
|
| 378 |
+
sentence = "This is a simple sentence."
|
| 379 |
+
filtered_sentence = [word for word in sentence.split() if word.lower() not in stop_words]
|
| 380 |
+
print(filtered_sentence) # Output: ['simple', 'sentence']
|
| 381 |
+
```
|
| 382 |
+
""")
|
| 383 |
+
|
| 384 |
+
elif selected_subpoint == " One Hot Encoding":
|
| 385 |
+
st.write("### ๐ฅ One-Hot Encoding")
|
| 386 |
+
st.write("""
|
| 387 |
+
Representing categorical data as binary vectors to make it suitable for machine learning models.
|
| 388 |
+
|
| 389 |
+
**How it works:**
|
| 390 |
+
- Each unique category is assigned a unique binary vector.
|
| 391 |
+
- A binary vector has all values as `0` except for the position representing the category, which is `1`.
|
| 392 |
+
|
| 393 |
+
**Example:**
|
| 394 |
+
- Categories: `["Apple", "Banana", "Cherry"]`
|
| 395 |
+
- Encoding:
|
| 396 |
+
- `Apple`: `[1, 0, 0]`
|
| 397 |
+
- `Banana`: `[0, 1, 0]`
|
| 398 |
+
- `Cherry`: `[0, 0, 1]`
|
| 399 |
+
""")
|
| 400 |
+
|
| 401 |
+
st.write("### ๐ Example with Fruits")
|
| 402 |
+
st.write("""
|
| 403 |
+
**Input Categories:** `["Apple", "Banana", "Cherry", "Banana", "Apple"]`
|
| 404 |
+
**Output (One-Hot Encoding):**
|
| 405 |
+
- `Apple`: `[1, 0, 0]`
|
| 406 |
+
- `Banana`: `[0, 1, 0]`
|
| 407 |
+
- `Cherry`: `[0, 0, 1]`
|
| 408 |
+
- `Banana`: `[0, 1, 0]`
|
| 409 |
+
- `Apple`: `[1, 0, 0]`
|
| 410 |
+
""")
|
| 411 |
+
|
| 412 |
+
elif selected_subpoint == " Bag Of Words":
|
| 413 |
+
st.write("### ๐ Bag of Words (BoW)")
|
| 414 |
+
st.write("""
|
| 415 |
+
Bag of Words converts text into a matrix of word frequencies, where each word is represented by a unique index in the vocabulary.
|
| 416 |
+
|
| 417 |
+
**Example:**
|
| 418 |
+
- Input: `["I love NLP", "NLP is fun"]`
|
| 419 |
+
- Vocabulary: `["I", "love", "NLP", "is", "fun"]`
|
| 420 |
+
- BoW Matrix:
|
| 421 |
+
- `"I love NLP"`: `[1, 1, 1, 0, 0]`
|
| 422 |
+
- `"NLP is fun"`: `[0, 0, 1, 1, 1]`
|
| 423 |
+
|
| 424 |
+
**Code Example:**
|
| 425 |
+
```python
|
| 426 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 427 |
+
|
| 428 |
+
documents = ["I love NLP", "NLP is fun"]
|
| 429 |
+
vectorizer = CountVectorizer()
|
| 430 |
+
bow_matrix = vectorizer.fit_transform(documents)
|
| 431 |
+
|
| 432 |
+
print(bow_matrix.toarray()) # Output: [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]]
|
| 433 |
+
```
|
| 434 |
+
""")
|
| 435 |
+
|
| 436 |
+
elif selected_subpoint == " Binary Bag Of Words":
|
| 437 |
+
st.write("### ๐ฒ Binary Bag of Words")
|
| 438 |
+
st.write("""
|
| 439 |
+
Binary Bag of Words is a variation of the BoW model where each word is represented by `1` if present in the document and `0` if absent, ignoring word frequencies.
|
| 440 |
+
|
| 441 |
+
**Example:**
|
| 442 |
+
- Input: `["I love NLP", "NLP is fun"]`
|
| 443 |
+
- Vocabulary: `["I", "love", "NLP", "is", "fun"]`
|
| 444 |
+
- Binary BoW Matrix:
|
| 445 |
+
- `"I love NLP"`: `[1, 1, 1, 0, 0]`
|
| 446 |
+
- `"NLP is fun"`: `[0, 0, 1, 1, 1]`
|
| 447 |
+
|
| 448 |
+
**Code Example:**
|
| 449 |
+
```python
|
| 450 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 451 |
+
|
| 452 |
+
documents = ["I love NLP", "NLP is fun"]
|
| 453 |
+
vectorizer = CountVectorizer(binary=True)
|
| 454 |
+
binary_bow_matrix = vectorizer.fit_transform(documents)
|
| 455 |
+
|
| 456 |
+
print(binary_bow_matrix.toarray()) # Output: [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]]
|
| 457 |
+
```
|
| 458 |
+
""")
|
| 459 |
+
|
| 460 |
+
elif selected_subpoint == " TF-IDF":
|
| 461 |
+
st.write("### ๐งฎ TF-IDF (Term Frequency - Inverse Document Frequency)")
|
| 462 |
+
st.write("""
|
| 463 |
+
TF-IDF is a statistical measure used to evaluate how important a word is to a document in a collection or corpus. It considers two factors:
|
| 464 |
+
- **Term Frequency (TF)**: The frequency of a word in a document.
|
| 465 |
+
- **Inverse Document Frequency (IDF)**: The importance of the word across all documents in the corpus. Words that appear in many documents are less important.
|
| 466 |
+
|
| 467 |
+
The formula for TF-IDF is:
|
| 468 |
+
- **TF-IDF = TF * IDF**
|
| 469 |
+
|
| 470 |
+
**Example:**
|
| 471 |
+
Consider three documents:
|
| 472 |
+
1. `"I love programming"`
|
| 473 |
+
2. `"Programming is fun"`
|
| 474 |
+
3. `"I love Python programming"`
|
| 475 |
+
|
| 476 |
+
- **TF (for "programming")**:
|
| 477 |
+
- Document 1: `1/3`
|
| 478 |
+
- Document 2: `1/3`
|
| 479 |
+
- Document 3: `1/3`
|
| 480 |
+
|
| 481 |
+
- **IDF (for "programming")**:
|
| 482 |
+
- IDF = log(3/3) = 0 (common word, less informative)
|
| 483 |
+
|
| 484 |
+
**Code Example:**
|
| 485 |
+
```python
|
| 486 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 487 |
+
|
| 488 |
+
documents = ["I love programming", "Programming is fun", "I love Python programming"]
|
| 489 |
+
vectorizer = TfidfVectorizer()
|
| 490 |
+
tfidf_matrix = vectorizer.fit_transform(documents)
|
| 491 |
+
|
| 492 |
+
print(tfidf_matrix.toarray()) # Output will show TF-IDF scores for each word in each document
|
| 493 |
+
```
|
| 494 |
+
""")
|
| 495 |
+
|
| 496 |
+
elif selected_subpoint == " Word Embeddings":
|
| 497 |
+
st.write("### ๐ค Word Embeddings")
|
| 498 |
+
st.write("""
|
| 499 |
+
Word embeddings are dense vector representations of words in a continuous vector space, capturing semantic meanings and relationships between words.
|
| 500 |
+
|
| 501 |
+
**Types of Word Embeddings:**
|
| 502 |
+
|
| 503 |
+
1. **Word2Vec**: Learns word associations from context using two approaches: Word2Vec is a model that transforms words into dense vector representations in a continuous vector space, capturing semantic relationships. It learns these representations by predicting words based on their context.
|
| 504 |
+
|
| 505 |
+
- **Skip-gram model**: This model predicts context words from a target word, similar to Word2Vec's Skip-gram model. It's useful for capturing word relationships, and it works well with smaller datasets.
|
| 506 |
+
|
| 507 |
+
- **CBOW (Continuous Bag of Words) model**: This model predicts a target word from a context window of words, similar to Word2Vec's CBOW model. It's effective for larger datasets and works well when words occur frequently.
|
| 508 |
|
| 509 |
+
2. **GloVe (Global Vectors for Word Representation)**: Uses a co-occurrence matrix to capture the relationships between words. It factors the matrix to produce low-dimensional vectors.
|
| 510 |
+
|
| 511 |
+
3. **FastText**: Extends Word2Vec by breaking words into subword units, which helps capture morphology and represent rare or unseen words.
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
**Example:**
|
| 515 |
+
- Words like `"king"` and `"queen"` will have similar vector representations in embedding space, reflecting their semantic relationship.
|
| 516 |
+
|
| 517 |
+
**Code Example (using Word2Vec):**
|
| 518 |
+
```python
|
| 519 |
+
from gensim.models import Word2Vec
|
| 520 |
+
|
| 521 |
+
# Sample sentences
|
| 522 |
+
sentences = [["I", "love", "programming"], ["Word", "embeddings", "are", "cool"]]
|
| 523 |
+
|
| 524 |
+
# Train Word2Vec model
|
| 525 |
+
model = Word2Vec(sentences, min_count=1)
|
| 526 |
+
|
| 527 |
+
# Get the vector for the word 'programming'
|
| 528 |
+
vector = model.wv['programming']
|
| 529 |
+
print(vector)
|
| 530 |
+
```
|
| 531 |
+
""")
|
| 532 |
+
|
| 533 |
+
elif selected_subpoint == "Part-of-Speech (POS) Tagging":
|
| 534 |
+
st.write("### ๐๏ธ Part-of-Speech (POS) Tagging")
|
| 535 |
+
st.write("""
|
| 536 |
+
Assigning grammatical labels to each word in a sentence, indicating its role in context.
|
| 537 |
+
**Example:**
|
| 538 |
+
- Input: `"Birds fly high"`
|
| 539 |
+
- Output: `["Birds (NOUN)", "fly (VERB)", "high (ADJ)"]`
|
| 540 |
+
""")
|
| 541 |
+
|
| 542 |
+
elif selected_subpoint == "Named Entity Recognition (NER)":
|
| 543 |
+
st.write("### ๐ Named Entity Recognition (NER)")
|
| 544 |
+
st.write("""
|
| 545 |
+
Detecting and categorizing entities like names, dates, and locations from text.
|
| 546 |
+
**Example:**
|
| 547 |
+
- Input: `"Tesla, founded by Elon Musk, is based in California."`
|
| 548 |
+
- Output: `["Tesla (ORGANIZATION)", "Elon Musk (PERSON)", "California (LOCATION)"]`
|
| 549 |
+
""")
|
| 550 |
+
|
| 551 |
+
elif selected_subpoint == "Sentiment Analysis":
|
| 552 |
+
st.write("### ๐ญ Sentiment Analysis")
|
| 553 |
+
st.write("""
|
| 554 |
+
Classifying the emotional tone of a text into categories such as positive, negative, or neutral.
|
| 555 |
+
**Example:**
|
| 556 |
+
- Input: `"The service was exceptional!"`
|
| 557 |
+
- Output: `Positive`
|
| 558 |
+
""")
|
| 559 |
|
| 560 |
|
| 561 |
|