0% found this document useful (0 votes)
8 views8 pages

Language Processing For Social Media Ex No: Date

Uploaded by

Shanmugam K
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)
8 views8 pages

Language Processing For Social Media Ex No: Date

Uploaded by

Shanmugam K
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
You are on page 1/ 8

EX NO: LANGUAGE PROCESSING FOR SOCIAL

DATE: MEDIA
AIM
AIM:

To write a python code for language for social media.

ALGORITHM:

Step 1: import required libraries

Step 2: Model architecture.

Step 3: Training process text prediction.

Step 4: Evaluation metrics limitations.

PROGRAM:

import re

from textblob import TextBlob

def clean_text(text):

return re.sub(r"@\w+|#\w+|http\S+|[^a-zA-Z0-9\s]", "", text).strip()

print ("Social Media NLP (Type 'exit' to stop)")

while True:

text = input ("Enter text: ")

if text.lower() == "exit": break

print (f"Cleaned: {clean_text(text)} | Sentiment: {['Negative ', 'Neutral ',


'Positive'][(TextBlob(text).sentiment.polarity > 0) - (TextBlob(text).sentiment.polarity
< 0) + 1]}")

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
OUTPUT:

Social Media NLP (Type 'exit' to stop)


Enter text: I am bad
Cleaned: I am bad| Sentiment: Negative

Enter Text: Good guys!

Cleaned: Good guys|Sentiment: Positive

RESULT:

Thus the python code for language processing for social media was executed
successfully.

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
EX NO:
CHATBOT FOR CUSTOMER SERVICES
DATE:

AIM:
To write a python code for chatbot for customer services.

ALGORITHM:
Step 1: Import the required libraries.

Step 2: Gather dataset common customer service interaction.

Step 3: Process data an using training neutral networks.

Step 4: Testing ensure chatbots retrability and accuracy.

PROGRAM:

Import math

import random

def calculator_chatbot():

print ("?? Hello! I am MathBot")

greetings = [ "Hello! Ask me any math problem!"]

allowed_functions = {

"sqrt": math.sqrt, "pow": math.pow, "sin": math.sin, "cos": math.cos,

"tan": math.tan, "log": math.log, "pi": math.pi, "e": math.e

while True:

user_input = inpt ("You: ").strip ().lower()

if user_input == "exit":

print ("Chatbot: It was great talking to you! Have a fantastic day! ??")

break

elif user_input in ["hi", "hello", "hey"]:

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
print ("Chatbot:", random.choice(greetings))

elif user_input in ["how are you?"]:

print ("Chatbot: I'm feeling great! How about you?")

else:

try:

print (f"Chatbot: {eval(user_input, {'__builtins__': None}, allowed_functions)}")

except:

print ("Chatbot: I can only solve math problems! ")

calculator_chatbot()

OUTPUT:

Hello: I am mathbot

You: Hi

Chatbot: Hello! Ask me any math problem!

You:4*8

Chartbot: 32

You: Sqrt(64)

Chatbot: 8.0

You: How are you!

Chatbot: I’m feeling great?How about you?

You: Exit

Chatbot: It was talking to you?Have a fantastic day!??

RESULT:
Thus the python code for chatbot for customer services was executed
successfully.

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
EX NO:
MUSIC GENERATION
DATE:

AIM:
To write a python code for music generation.

ALGORITHM:
Step 1: Import the required libraries.

Step 2: then gathering of data from collect dataset.

Step 3: Convert the musical data into suitable format training the rnn.

Step 4: Design and build an rnn model generating mp3 file.

PROGRAM:

! pip install pydub

import numpy as np

from scipy.io.wavfile import write

from pydub import AudioSegment

sample_rate = 44100

duration = 2

freq = 440.0

t = np.linspace(0, duration, int(sample_rate * duration), False)

wave = 0.5 * np.sin(2 * np.pi * freq * t)

wave = (wave * 32767) .astype(np.int16)

wav_filename = "simple_tone.wav"

write (wav_filename, sample_rate, wave)

mp3_filename = "simple_tone.mp3"

sound = AudioSegment.from_wav(wav_filename)

sound.export(mp3_filename, format="mp3")

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
print (f"MP3 file saved as '{mp3_filename}'.")

OUTPUT:

MP3 file saves as ‘simple_tone.mp3’

RESULT:

Thus the python code for music generation was executed Successfully.

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K
RESULT:
Thus the python code for chatbot for customer services was executed
successfully.

CSE/NM/NN&DL / 513322104048/SHANMUGASUNDARAM K

You might also like