Does anyone know how to rectify this? I have a different outcome from the expected outcome when running this.
def parse_data_from_file(SENTIMENT_CSV):
“”"
Extracts sentences and labels from a CSV file
Args:
filename (string): path to the CSV file
Returns:
sentences, labels (list of string, list of string): tuple containing lists of sentences and labels
"""
sentences = []
labels = []
num_sentences = 0
with open("./data/training_cleaned.csv", 'r') as csvfile:
### START CODE HERE
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
# Your Code here. Create list items where the first item is the text, found in row[5], and the second is the label. Note that the label is a '0' or a '4' in the text. When it's the former, make
# your label to be 0, otherwise 1. Keep a count of the number of sentences in num_sentences
list_item=[]
# YOUR CODE HERE
num_sentences = num_sentences + 1
corpus.append(list_item)
### END CODE HERE
return sentences, labels
Test your function
sentences, labels = parse_data_from_file(SENTIMENT_CSV)
print(f"dataset contains {len(sentences)} examples\n")
print(f"Text of second example should look like this:\n{sentences[1]}\n")
print(f"Text of fourth example should look like this:\n{sentences[3]}")
print(f"\nLabels of last 5 examples should look like this:\n{labels[-5:]}")