machine learning - Tensorflow How to convert words(Strings) from a csv file to proper vectors -


hi im trying make small classifier in tensorflow. want read data csv file , use training phase, problem content of file looks this:

object,categorie
blue balon,toy
white plastic ship,toy
big book,other
wild cat,animal
wet dolphin,animal ...

so want read sentences , convert them vector use in tensorflow model. information readed numerical data no idea how use data this.

the turorials oficial site use numeric data, best option far has been use dictionary think there should exist better option.

another option make own method imprecise.

have ideas how can that? alternative mi method or how can process words in tensorflow?

sorry if english not good.

edit

try convert sentences multidimensional arrays results not good, estimate poor results due statements can short , others long, affects final free space on each array , free space affects results probabilistic model. recommendation?

luckily, solution pretty simple using pandas module!

first, let's create quick .csv file:

example.csv:

"object","category" "the blue balloon","toy" "a white plastic ship","toy" "a big book","other" "the wild cat","animal" "a wet dolphin","animal" 

now can write our simple python file:

convert.py

import pandas pd  data = pd.read_csv("example.csv") print(data)  data = data.join(pd.get_dummies(data["category"])) data = data.drop("category", axis=1) print(data) 

finally, can run our file , see our results!

$ python convert.py                   object category 0      blue balloon      toy 1  white plastic ship      toy 2            big book    other 3          wild cat   animal 4         wet dolphin   animal                   object  animal  other  toy 0      blue balloon     0.0    0.0  1.0 1  white plastic ship     0.0    0.0  1.0 2            big book     0.0    1.0  0.0 3          wild cat     1.0    0.0  0.0 4         wet dolphin     1.0    0.0  0.0 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -