0% found this document useful (0 votes)
54 views3 pages

Untitled17.Ipynb - Colab

The document is a Jupyter notebook that demonstrates the use of Google Translate and NLTK for Natural Language Processing (NLP). It includes code for tokenizing text, removing stopwords and punctuation, and translating cleaned text into multiple languages. The example text discusses the importance of NLP in artificial intelligence and its applications.

Uploaded by

yuvijk5989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Untitled17.Ipynb - Colab

The document is a Jupyter notebook that demonstrates the use of Google Translate and NLTK for Natural Language Processing (NLP). It includes code for tokenizing text, removing stopwords and punctuation, and translating cleaned text into multiple languages. The example text discusses the importance of NLP in artificial intelligence and its applications.

Uploaded by

yuvijk5989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/8/25, 9:49 PM Untitled17.

ipynb - Colab

!pip install googletrans==4.0.0-rc1


!pip install nltk

RequirementInsert
already satisfied:
code cell below (Ctrl+Mgoogletrans==4.0.0-rc1
B) in /usr/local/lib/python3.11/di
Requirement already satisfied: httpx==0.13.3 in /usr/local/lib/python3.11/dist-packag
Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (fr
Requirement already satisfied: hstspreload in /usr/local/lib/python3.11/dist-packages
Requirement already satisfied: sniffio in /usr/local/lib/python3.11/dist-packages (fr
Requirement already satisfied: chardet==3.* in /usr/local/lib/python3.11/dist-package
Requirement already satisfied: idna==2.* in /usr/local/lib/python3.11/dist-packages (
Requirement already satisfied: rfc3986<2,>=1.3 in /usr/local/lib/python3.11/dist-pack
Requirement already satisfied: httpcore==0.9.* in /usr/local/lib/python3.11/dist-pack
Requirement already satisfied: h11<0.10,>=0.8 in /usr/local/lib/python3.11/dist-packa
Requirement already satisfied: h2==3.* in /usr/local/lib/python3.11/dist-packages (fr
Requirement already satisfied: hyperframe<6,>=5.2.0 in /usr/local/lib/python3.11/dist
Requirement already satisfied: hpack<4,>=3.0 in /usr/local/lib/python3.11/dist-packag
Requirement already satisfied: nltk in /usr/local/lib/python3.11/dist-packages (3.9.1
Requirement already satisfied: click in /usr/local/lib/python3.11/dist-packages (from
Requirement already satisfied: joblib in /usr/local/lib/python3.11/dist-packages (fro
Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.11/dist-pack
Requirement already satisfied: tqdm in /usr/local/lib/python3.11/dist-packages (from

 

from googletrans import Translator


import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
import string

nltk.download('punkt') # For sentence/word tokenization


nltk.download('stopwords')
nltk.download('punkt_tab')

[nltk_data] Downloading package punkt to /root/nltk_data...


[nltk_data] Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to /root/nltk_data...
[nltk_data] Package stopwords is already up-to-date!
[nltk_data] Downloading package punkt_tab to /root/nltk_data...
[nltk_data] Unzipping tokenizers/punkt_tab.zip.
True

Double-click (or enter) to edit

text ="""Natural Language Processing (NLP) is a crucial area of artificial


intelligence that focuses on the interaction between computers and human
language.
It allows machines to understand, interpret, and respond to human language
in a way that is both meaningful and useful. NLP is used in various
real-world
applications such as language translation, virtual assistants, sentiment
analysis, chatbots, and speech recognition. With advancements in deep
learning and
https://colab.research.google.com/drive/1WawWIbHGGiGfYns0Z4Gz6kbF0uI7UQoB#scrollTo=K7WiTdzFMwql&printMode=true 1/3
4/8/25, 9:49 PM Untitled17.ipynb - Colab
access to massive datasets, the accuracy of NLP systems has improved
significantly. Today, researchers are even exploring complex tasks like
emotion detection,
sarcasm recognition, and creating context-aware conversational systems,
bringing machines closer to human-like communication."""

Insert code cell below (Ctrl+M B)


print("Original Text:\n", text)

Original Text:
Natural Language Processing (NLP) is a crucial area of artificial intelligence that
It allows machines to understand, interpret, and respond to human language in a way t
applications such as language translation, virtual assistants, sentiment analysis, ch
access to massive datasets, the accuracy of NLP systems has improved significantly. T
sarcasm recognition, and creating context-aware conversational systems, bringing mach

 

tokens = word_tokenize(text)
print("\n Tokenized Words:\n", tokens)

Tokenized Words:
['Natural', 'Language', 'Processing', '(', 'NLP', ')', 'is', 'a', 'crucial', 'area',

 

Start coding or generate with AI.

stop_words = set(stopwords.words('english'))
punctuation = set(string.punctuation)

clean_tokens = [word for word in tokens if word.lower() not in stop_words


and word not in punctuation]
print("\n Cleaned Tokens (no stopwords or punctuation):\n", clean_tokens)

Cleaned Tokens (no stopwords or punctuation):


['Natural', 'Language', 'Processing', 'NLP', 'crucial', 'area', 'artificial', 'intel

 

cleaned_text = ' '.join(clean_tokens)


print("\n Cleaned Text for Translation:\n", cleaned_text)

Cleaned Text for Translation:


Natural Language Processing NLP crucial area artificial intelligence focuses interac

 

translator = Translator()

languages = {
'French': 'fr',

https://colab.research.google.com/drive/1WawWIbHGGiGfYns0Z4Gz6kbF0uI7UQoB#scrollTo=K7WiTdzFMwql&printMode=true 2/3
4/8/25, 9:49 PM Untitled17.ipynb - Colab

'Hindi': 'hi',
'Spanish': 'es',
'German': 'de',
'Tamil': 'ta'
}

Insert code cell below (Ctrl+M B)


print("\nTranslations:\n")
for lang_name, lang_code in languages.items():
translated = translator.translate(cleaned_text, src='en', dest=lang_code)
print(f"{lang_name}:\n{translated.text}\n")

Translations:

French:
Traitement du langage naturel NLP domaine crucial Intelligence artificielle se concen

Hindi:
प्राकृ तिक भाषा प्रसंस्करण एनएलपी महत्वपूर्ण क्षेत्र कृ त्रिम बुद्धिमत्ता इंटरै क्शन कं प्यूटर पर ध्यान कें द्रित करती है मा

Spanish:
Procesamiento del lenguaje natural NLP Área crucial de la inteligencia artificial Enf

German:
Natürliche Sprache Verarbeitung NLP Crucial Area Künstliche Intelligenz Fokussiere In

Tamil:
இயற்கையான மொழி செயலாக்கம் என் .எல் .பி முக்கியமான பகுதி செயற்கை நுண்

 

https://colab.research.google.com/drive/1WawWIbHGGiGfYns0Z4Gz6kbF0uI7UQoB#scrollTo=K7WiTdzFMwql&printMode=true 3/3

You might also like