# C3\_W1 assignment

**URL:** <https://community.deeplearning.ai/t/c3-w1-assignment/160962>\
**Category:** Natural Language Processing in TensorFlow\
**Tags:** week-module-1\
**Created:** [July 13, 2022, 9:18pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962 "2022-07-13T21:18:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 13, 2022, 9:18pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/1 "2022-07-13T21:18:54Z")

</div>

hi,

I’m having problems with C3\_W1 assignment. Wondering if you could help.  
I have the remove\_stopwords(sentence): working correctly, and am working on the parse\_data\_from\_file()

I am getting the error "AttributeError: ‘list’ object has no attribute ‘lower’

and it stems from  
sentence = sentence.lower()  
in the “remove\_stopwords(sentence)” function

Somehow it is being passed as an array of strings instead of just the string itself.

any suggestions? I can share my code if you would like to have a look

thank you,  
Ed

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 14, 2022, 6:10am UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/2 "2022-07-14T06:10:51Z")

</div>

`sentence` should be a python string. Please use this hint to fix the calling code.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 14, 2022, 1:53pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/3 "2022-07-14T13:53:35Z")

</div>

hi

My # Test your function works correctly:

`remove_stopwords("I am about to go to the store and get any snack")`

I get:  
`'go store get snack'`

In

```auto
def parse_data_from_file(filename):
   sentences = []
   ....
   sentences.append(row[1])
   sentences = remove_stopwords(sentences)

```

The error is:  
sentence = sentence.lower()  
AttributeError: ‘list’ object has no attribute ‘lower’

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 14, 2022, 1:55pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/4 "2022-07-14T13:55:35Z")

</div>

Please remove stopwords before adding the csv data to `sentences`.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 1:27pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/5 "2022-07-15T13:27:18Z")

</div>

hi

I think there is something wrong with either the assignment template or the bbc-text.csv (or bbc-train.csv files).

here is what I have:

```auto
for row in reader:
            # article ID (row [0]) is omitted
            sentences.append(remove_stopwords(row[1])) # actual text
            labels.append(row[2]) # category

```

but row[2] causes an error:

```auto
IndexError: list index out of range

```

but from [https://www.kaggle.com/competitions/learn-ai-bbc/data?select=BBC+News+Train.csv](https://www.kaggle.com/competitions/learn-ai-bbc/data?select=BBC+News+Train.csv)

it is clear there are 3 fields:

```auto
ArticleId - Article id unique # given to the record
Article - text of the header and article
Category - cateogry of the article (tech, business, sport, entertainment, politics/li>

```

but the “bbc-text.csv” that we were given in the assignment only has 2 fields: the Article ID and text. (no category).

thanks for your help  
Ed

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 1:32pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/6 "2022-07-15T13:32:10Z")

</div>

Please execute this cell in the notebook to know the data format:

```auto
with open("./bbc-text.csv", 'r') as csvfile:
    print(f"First line (header) looks like this:\n\n{csvfile.readline()}")
    print(f"Each data point looks like this:\n\n{csvfile.readline()}")

```

The 1st row in the csv is column headers i.e. `category,text`  
Data starts from 2nd row onwards. Based on the column headers, row[0] is the label.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 1:41pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/7 "2022-07-15T13:41:40Z")

</div>

I’m afraid that’s not the case.

When I run the template code:

```auto
with open("./bbc-text.csv", 'r') as csvfile:
    print(f"First line (header) looks like this:\n\n{csvfile.readline()}")
    print(f"Each data point looks like this:\n\n{csvfile.readline()}")     

```

I get:

````auto
First line (header) looks like this:

ArticleId,Text

Each data point looks like this:

1018,qpr keeper day heads for preston queens park rangers keeper chris day is set to join preston on a month s loan. day has been displaced by the arrival of simon royce who is in his second month on loan from charlton. qpr have also signed italian generoso rossi. r s manager ian holloway said: some might say it s a risk as he can t be recalled during that month and simon royce can now be recalled by charlton. but i have other irons in the fire. i have had a yes from a couple of others should i need them. day s rangers contract expires in the summer. meanwhile holloway is hoping to complete the signing of middlesbrough defender andy davies - either permanently or again on loan - before saturday s match at ipswich. davies impressed during a recent loan spell at loftus road. holloway is also chasing bristol city midfielder tom doherty.```
````

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 1:46pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/8 "2022-07-15T13:46:44Z")

</div>

Please use the file(s) provided by coursera and not kaggle. See below the output of executing the cell on coursera lab environment.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/2/2/2280d5db4164ea9ee98f03d0454377d603e4021d.png)

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 1:47pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/9 "2022-07-15T13:47:10Z")

</div>

I am!

was there an update?

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 1:48pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/10 "2022-07-15T13:48:10Z")

</div>

Based on your output, seems so.

Please refresh your workspace and try again.  
See `Refresh your Lab Workspace` section [here](https://www.coursera.support/s/article/360044758731-Solving-common-issues-with-Coursera-Labs?language=en_US)

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 1:54pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/11 "2022-07-15T13:54:10Z")

</div>

could you attached the correct ‘bbc-text.csv’ file, please?

thanks,

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 1:57pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/12 "2022-07-15T13:57:24Z")

</div>

I’m working locally, using Visual Studio Code

thanks

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 1:57pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/13 "2022-07-15T13:57:53Z")

</div>

Go ahead and download the dataset from coursera lab environment.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 2:02pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/14 "2022-07-15T14:02:46Z")

</div>

Thanks

can you send me the link again? There isn’t anything in the current specialization.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 2:04pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/15 "2022-07-15T14:04:31Z")

</div>

found it:

> **[GitHub - https-deeplearning-ai/tensorflow-1-public](https://github.com/https-deeplearning-ai/tensorflow-1-public)**
>
> Contribute to https-deeplearning-ai/tensorflow-1-public development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 2:04pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/16 "2022-07-15T14:04:42Z")

</div>

Here’s the [link](https://www.coursera.org/learn/natural-language-processing-tensorflow/programming/lI0HI/explore-the-bbc-news-archive) to the assignment page.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 2:13pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/17 "2022-07-15T14:13:27Z")

</div>

works now!

is it because I ‘reset’ the course? that there were changes?

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [July 15, 2022, 2:18pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/18 "2022-07-15T14:18:59Z")

</div>

Sorry. I don’t know about the state of your workspace. Good to know that resetting the lab got things back to the latest version.

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 2:23pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/19 "2022-07-15T14:23:25Z")

</div>

I just downloaded the ‘lab files’

thank you for your help

---

<div class="post-metadata">

**Author:** ![Ed\_Sykes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_sykes/32/18019_2.png) [@Ed\_Sykes](https://community.deeplearning.ai/u/Ed_Sykes)\
**Post date:** [July 15, 2022, 2:26pm UTC](https://community.deeplearning.ai/t/c3-w1-assignment/160962/20 "2022-07-15T14:26:00Z")

</div>

I’m now on the last section

```auto
label_sequences, label_word_index = tokenize_labels(labels)
print(f"Vocabulary of labels looks like this {label_word_index}\n")
print(f"First ten sequences {label_sequences[:10]}\n")

```

It prints out a LOT of values:

```auto
Vocabulary of labels looks like this {'<OOV>': 1, 's': 2, 'said': 3, 'will': 4, 'not': 5, 'mr': 6, 'year': 7, 'also': 8, 'people': 9, 'new': 10, 'us': 11, 'one': 12, 'can': 13, 'last': 14, 'first': 15, 't': 16, 'time': 17, 'two': 18, ..... all the way to 'allocating': 29713, 'heerenveen': 29714}

```

First ten sequences [[96, 176, 1157, 1220, 54, 1122, 742, 5211, 85, 1074, 4267, 147, 184, 4127, 1344, 1311, 1595, 47, 9, 949, 96, 4, 6516, 329, 92, 23, 17, 140, 3128, 1330, 2519, 576, 419, 1277, 72, 2963, 3046, 1755, 10, 894, 4, 755, 12, … all the way to 14996, 14997, 6527, 4802, 31, 5813, 10942, 19540, 19541, 19542, 19543, 162, 59, 949, 27, 4003, 8836, 5003, 3, 30, 63, 2884, 4420, 2, 63, 4004]]

So, clearly not getting the “Expected Output” of:

```auto

Vocabulary of labels looks like this {'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}

First ten sequences [[4], [2], [1], [1], [5], [3], [3], [1], [1], [5]]

```

[Next page](https://community.deeplearning.ai/t/c3-w1-assignment/160962.md?page=2)
