C3W3 Assignment Question

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:]}")

Hello @Anthony_Lee ,

  1. It is : def parse_data_from_file(filename)
    You have written : def parse_data_from_file(SENTIMENT_CSV):
    Here filename is the parameter of the function. It’s not there to fill up or replace name of the file.
    And you are not supposed to write the file name there. Just keep it like that.
def parse_data_from_file(filename): ##don't modify this.
  1. As per the hint,
# 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

You are supposed to write a code to check these particular clauses.But it’s not there.Write a code to implement this.

With regards,
Nilosree Sengupta

Hello @Anthony_Lee ,
Sorry for the late response!I hope that the advice given by my fellow mentor helps you crack the problem.
Please feel free to reach us out in the future as and when needed.
Happy Coding:))
Thanks and Regards,
Mayank Ghogale