From f08b5150f1516574faf41389f042ff585c237e9d Mon Sep 17 00:00:00 2001 From: navinagop Date: Thu, 4 Dec 2025 15:23:04 -0500 Subject: [PATCH] Enhance pos_exercise with code examples Added code snippets for extracting NOUNs and numbers from a news story. --- 7_pos/pos_exercise.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/7_pos/pos_exercise.md b/7_pos/pos_exercise.md index e70a362..35bdea4 100644 --- a/7_pos/pos_exercise.md +++ b/7_pos/pos_exercise.md @@ -4,6 +4,13 @@ Exercise for Spacy POS tutorial, 1) Extract all NOUN tokens from this story. You will have to read the file in python first to collect all the text and then extract NOUNs in a python list 2) Extract all numbers (NUM POS type) in a python list 3) Print a count of all POS tags in this story + for token in doc: + if token.pos_ in ["NOUN", "PROPN"]: + print(token, "|",token.pos_ ) + if token.pos_=='NUM': + print(token ,"|", token.pos_) + count=doc.count_by(spacy.attrs.POS) + print(count) [Solution](https://github.com/codebasics/nlp-tutorials/blob/main/7_pos/Exercise/pos_exercise_solution.ipynb)