Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I Have done the code for 1-6 listed below but stuck on question 6 and 7? S1=S.lower() print(S1) S2='' for l in S1: if 97

image text in transcribed

I Have done the code for 1-6 listed below but stuck on question 6 and 7?

S1=S.lower() print(S1)

S2='' for l in S1: if 97

print(S2)

L=S2.split() print(L)

W = set(L) print(W) WS =sorted(list(W)) print(WS)

wordvector=(WS,L)

tab Code V 2. Snippets Halt Validate Question 3 Consider the string S defined in the cell below (borrowed from the New York Times). Please process this string in the ollowing ways. (This tutorial might be helpful.) Please make the result of each part clear and easy to see. 1. Convert the string to only lowercase letters (let the result be called S). (Hint: there is a built-in string method that does this) 2. Remove all non-alphabetical characters from Si except for spaces (let the result be called S2). 3. Use the split() method on S2 to produce a list of words occurring in S. 4. By using the python set type, produce a set W of all the unique words occurring in L. What is the ratio of the length of W to the length of L? 5. Use W to produce a list WS of the words in W occurring in sorted order. 6. Create a function word_vector(WS, L) that takes W S and Las input and returns a numpy array N of length len (WS) such that for each i in range(len(WS)), N[i] is equal to the number of times the word W S[i] occurs in 7. Create a function cos_sim(N,M) that computes the cosine similarity of two word vectors (two outputs from word_vector called N and M)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions