Python,how to convert word to vector

flame_copper

Banned
Joined
Apr 13, 2006
Messages
1,474
Reaction score
0
text = 'John likes to watch movies. Mary likes too.'
text1 = 'John also likes to watch football games.'

dic1 = {"John": 1, "likes": 2, "to": 3, "watch": 4, "movies": 5, "also": 6, "football": 7, "games": 8, "Mary": 9, "too": 10}

v1 = [1, 2, 1, 1, 1, 0, 0, 0, 1, 1]
v2 = [1, 1, 1, 1, 0, 1, 1, 1, 0, 0]

hi there,I am doing my information assignment.
I am trying to merge text and text1 into a dic1,

after which I want v1 and v2 to display the vectors,
how can I achieve this?

I am thinking of using set functions and dict features?
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
text = 'John likes to watch movies. Mary likes too.'
text1 = 'John also likes to watch football games.'

dic1 = {"John": 1, "likes": 2, "to": 3, "watch": 4, "movies": 5, "also": 6, "football": 7, "games": 8, "Mary": 9, "too": 10}

v1 = [1, 2, 1, 1, 1, 0, 0, 0, 1, 1]
v2 = [1, 1, 1, 1, 0, 1, 1, 1, 0, 0]

hi there,I am doing my information assignment.
I am trying to merge text and text1 into a dic1,

after which I want v1 and v2 to display the vectors,
how can I achieve this?

I am thinking of using set functions and dict features?

Instead of thinking what function to use, think about the steps to accomplish your objective.

Your idea of a vector lack of the constraint of an order. In an associative map, usually there is no predetermined order. Why should "John" appear first like the way it appear in your string ? Hence why should the vector be in that particular order your sample shows ? Perhaps you need to be more specific in your requirement.

After you merged the tokens of the 2 text into the same dict, how are you doing to split them into individual vectors, seemingly shown as v1 and v2.
 

flame_copper

Banned
Joined
Apr 13, 2006
Messages
1,474
Reaction score
0
Instead of thinking what function to use, think about the steps to accomplish your objective.

Your idea of a vector lack of the constraint of an order. In an associative map, usually there is no predetermined order. Why should "John" appear first like the way it appear in your string ? Hence why should the vector be in that particular order your sample shows ? Perhaps you need to be more specific in your requirement.

After you merged the tokens of the 2 text into the same dict, how are you doing to split them into individual vectors, seemingly shown as v1 and v2.

Feature hashing - Wikipedia, the free encyclopedia
Bag-of-words model - Wikipedia, the free encyclopedia

as in for each position,check whether the keyword does appear in the document or not
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top