Home > Back-end >  how to define sample in a natural language processing model
how to define sample in a natural language processing model

Time:06-11

for doc in sample['documents']: 

The error is 'sample' undefined (I was trying to reproduce a natural language processing model)

CodePudding user response:

I this you are searching that the way to display the natural processing language and i this this is helpful to you. i mention the link below so please come check this.. https://www.tableau.com/learn/articles/natural-language-processing-examples

CodePudding user response:

In this case, your problem is the way you are reading the input. Not big deal no worries ! In the loop: for doc in sample['documents'] sample is the Dataframe of input, or a dictionary, and 'documents' is the name of the column. Let's suppose I have a csv of input like the following:

documents,label
Being offensive isnt illegal you idiot, negative
Loving the first days of summer! <3, positive
I hate when people put lol when we are having a serious talk ., negative

in python you will read the csv using pandas dataframe, for example:

sample=pd.read_csv('inputdata.csv',header=0)

and your sample['documents'] is the first colum of the input file. header =0 means that the label of your column are specified at the first line of the csv.

for doc in sample['documents'] will iterate over the first column, like this:

Being offensive isnt illegal you idiot
Loving the first days of summer! <3
I hate when people put lol when we are having a serious talk 

This means that maybe the origin of your error is that you call your input data in some other ways instead of sample or it is not reading the header of the csv input.

If the csv doesn't have documents as the name of the header you can specify it like this:

columns = ['documents', 'labels'] sample = pd.read_csv(inputdata.csv', header = None, names = columns) sample

Hope it helps !

  • Related