Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # steg 1: skapa lista med unika ord i träningsexempel
- import string
- workout_data = [('I love this car', 1),
- ('This view is amazing', 1),
- ('I feel great this morning', 1),
- ('I am so excited about the concert', 1),
- ('He is my best friend', 1),
- ('I do not like this car', 0),
- ('This view is horrible', 0),
- ('I feel tired this morning', 0),
- ('I am not looking forward to the concert', 0),
- ('He is my enemy', 0)]
- word_list = []
- spec = string.punctuation+"1234567890"
- # lägg till så att det tar bort de vanligaste funktionsorden? Ta sen 100 vanligaste orden
- for words, b in workout_data:
- words = words.split()
- for i in words:
- i = i.lower()
- if i not in word_list:
- word_list.append(i)
- # steg 2: för varje ord i sträng tilldela 1 om finns, 0 om noll
- def encode_string(s):
- # ta bort specialtecken ur s!!!
- x = s.split()
- # global res
- res = []
- for word in word_list:
- if word in x:
- res.append(1)
- # res.append(0)
- elif word not in spec:
- res.append(0)
- return res
- """
- def rensa(s):
- e = ''
- for tecken in s:
- if tecken not in spec:
- e += tecken
- return e
- """
- print(encode_string('love view hej'))
- y = []
- x = []
- # steg 3: översätt inputvektorer till x input
- # översätt positiv och negativ till y
- for a, b in workout_data:
- for a in workout_data:
- encode_string(a)
- for b in workout_data:
- if b == 1:
- y.append(1)
- else:
- y.append(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement