CARVIEW |
Select Language
HTTP/2 200
date: Fri, 10 Oct 2025 23:37:52 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=7873ad60092be5d4e90c9ddd30de60e295285b341491399b0b6f27ce67622494a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22QGs9CbfMrOWFT_Wi-UsUoJ52E_pLVJr2%22%3B%7D; HttpOnly; Path=/
cf-ray: 98c9f2b66ec7b080-BLR
NLP Exp 5 - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nltk
- from nltk import ngrams
- from nltk.tokenize import word_tokenize
- from collections import Counter
- #nltk.download('punkt')
- text = """
- Natural Language Processing with Python and NLTK is powerful.
- It helps in building models to understand and generate human language.
- """
- tokens = word_tokenize(text.lower())
- def generate_ngrams(tokens,n):
- n_grams = list(ngrams(tokens,n))
- return n_grams
- bigrams = generate_ngrams(tokens,2)
- trigrams = generate_ngrams(tokens,3)
- bigram_freq = Counter(bigrams)
- trigram_freq = Counter(trigrams)
- print("Bigrams:")
- for gram,freq in bigram_freq.items():
- print(f"{gram}: {freq}")
- print("\nTrigrams:")
- for gram,freq in trigram_freq.items():
- print(f"{gram}: {freq}")
- def predict_next_word(input_word, bigram_freq):
- candidates = {second: freq for (first, second), freq in bigram_freq.items() if first == input_word.lower()}
- if candidates:
- predicted = max(candidates, key=candidates.get)
- return predicted
- else:
- return None
- input_word = input("Enter word: ")
- next_word = predict_next_word(input_word, bigram_freq)
- if next_word:
- print(f"Predicted next word after '{input_word}' is: {next_word}")
- else:
- print(f"No prediction available for '{input_word}'")
- def predict_next_word_trigram(word1, word2, trigram_freq):
- candidates = {
- third: freq
- for (first, second, third), freq in trigram_freq.items()
- if first == word1.lower() and second == word2.lower()
- }
- if candidates:
- predicted = max(candidates, key=candidates.get)
- return predicted
- else:
- return None
- input_word1 = input("Enter word 1: ")
- input_word2 = input("Enter word 2: ")
- next_word = predict_next_word_trigram(input_word1, input_word2, trigram_freq)
- if next_word:
- print(f"Predicted next word after '{input_word1} {input_word2}' is: {next_word}")
- else:
- print(f"No prediction available for '{input_word1} {input_word2}'")
Tags:
nlp
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ 5
JavaScript | 3 sec ago | 0.24 KB
-
⭐⭐⭐Exchange Exploit T 3⭐⭐
Java | 8 sec ago | 0.10 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 7
JavaScript | 9 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ 6
JavaScript | 15 sec ago | 0.24 KB
-
⭐⭐⭐Crypto Accounts⭐⭐
Java | 20 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ 7
JavaScript | 20 sec ago | 0.24 KB
-
⭐⭐⭐Exchange Exploit T 3⭐⭐
Java | 32 sec ago | 0.10 KB
-
⭐⭐Exchange Exploit⭐⭐ L
JavaScript | 42 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand