Bird
Raised Fist0
Intro to Computingfundamentals~20 mins

Natural language processing basics in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
NLP Basics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
What does tokenization do in NLP?

In natural language processing, what is the main purpose of tokenization?

AIt converts text into numerical vectors directly.
BIt translates text from one language to another.
CIt removes all punctuation from the text.
DIt splits text into smaller pieces like words or sentences.
Attempts:
2 left
💡 Hint

Think about how you break a sentence into parts before understanding it.

🔍 Analysis
intermediate
1:30remaining
Output of simple word count code

What is the output of this Python code that counts word frequencies?

Intro to Computing
from collections import Counter
text = 'apple banana apple orange banana apple'
word_counts = Counter(text.split())
print(word_counts)
ACounter({'apple': 3, 'banana': 2, 'orange': 1})
BCounter({'banana': 3, 'apple': 2, 'orange': 1})
C{'apple': 3, 'banana': 2, 'orange': 1}
DCounter({'apple': 1, 'banana': 1, 'orange': 1})
Attempts:
2 left
💡 Hint

Count how many times each word appears in the text.

❓ Model Choice
advanced
2:00remaining
Best model for sentiment analysis

You want to build a model to classify movie reviews as positive or negative. Which model type is best suited for this task?

AConvolutional Neural Network (CNN) designed for image recognition
BK-Means clustering for grouping similar reviews
CRecurrent Neural Network (RNN) or Transformer model for text sequences
DLinear regression predicting review length
Attempts:
2 left
💡 Hint

Think about models that understand sequences of words.

❓ Metrics
advanced
2:00remaining
Choosing the right metric for imbalanced text classification

You trained a spam detection model where spam messages are rare. Which metric is best to evaluate your model's performance?

APrecision and recall, to balance false positives and false negatives
BAccuracy, because it shows overall correct predictions
CMean squared error, to measure prediction errors
DConfusion matrix size, to count total classes
Attempts:
2 left
💡 Hint

Think about what matters when one class is much smaller than the other.

🔍 Analysis
expert
2:30remaining
Why does this text preprocessing code raise an error?

Consider this Python code snippet for lowercasing and removing punctuation from text. Why does it raise an error?

Intro to Computing
import string
text = 'Hello, World!'
clean_text = text.lower().translate(str.maketrans('', '', string.punctuation))
print(clean_text)
Alower() cannot be chained with translate(), causing an AttributeError
Btranslate() expects a translation table, but string.punctuation is a string, causing a TypeError
Cstring.punctuation is empty, so translate() does nothing
Dprint() is missing parentheses, causing a SyntaxError
Attempts:
2 left
💡 Hint

Check what the translate() method needs as input.

Practice

(1/5)
1. What is the main goal of Natural Language Processing (NLP)?
easy
A. To help computers understand and work with human language
B. To create images from text descriptions
C. To speed up computer hardware
D. To encrypt messages for security

Solution

  1. Step 1: Understand NLP purpose

    NLP is about making computers understand human language, like English or Spanish.
  2. Step 2: Compare options

    Only To help computers understand and work with human language talks about computers working with human language, which matches NLP's goal.
  3. Final Answer:

    To help computers understand and work with human language -> Option A
  4. Quick Check:

    NLP = computers understand human language [OK]
Hint: NLP = computers + human language understanding [OK]
Common Mistakes:
  • Confusing NLP with image processing
  • Thinking NLP speeds up hardware
  • Mixing NLP with encryption tasks
2. Which of the following is the correct way to split a sentence into words in Python?
easy
A. sentence.add()
B. sentence.split()
C. sentence.remove()
D. sentence.join()

Solution

  1. Step 1: Recall Python string methods

    To split a sentence into words, we use the split() method which breaks text at spaces by default.
  2. Step 2: Check each option

    Only split() breaks text into parts; join() combines parts, remove() and add() are not string methods.
  3. Final Answer:

    sentence.split() -> Option B
  4. Quick Check:

    Split = break text into words [OK]
Hint: Use split() to break text into words [OK]
Common Mistakes:
  • Using join() instead of split()
  • Trying to use remove() on strings
  • Confusing add() with string methods
3. What will be the output of this Python code?
text = "I love AI"
tokens = text.split()
print(len(tokens))
medium
A. 1
B. 0
C. 4
D. 3

Solution

  1. Step 1: Tokenize the text

    Using split() on "I love AI" splits it into ['I', 'love', 'AI'], which has 3 words.
  2. Step 2: Count tokens

    len(tokens) counts the number of items in the list, which is 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Words count = 3 [OK]
Hint: Count words after split() to get token count [OK]
Common Mistakes:
  • Counting characters instead of words
  • Assuming split() returns a string
  • Forgetting split() splits by spaces
4. Find the error in this code snippet for tokenizing text:
text = "Hello world"
tokens = text.split('')
print(tokens)
medium
A. text should be a list, not a string
B. print() is missing parentheses
C. split('') is invalid; split() should have no argument or a space
D. tokens should be joined, not split

Solution

  1. Step 1: Check split() argument

    split('') is invalid in Python because empty string is not a valid separator.
  2. Step 2: Correct usage

    Use split() with no argument or split(' ') to split by spaces correctly.
  3. Final Answer:

    split('') is invalid; split() should have no argument or a space -> Option C
  4. Quick Check:

    split('') causes error [OK]
Hint: split('') causes error; use split() or split(' ') [OK]
Common Mistakes:
  • Using empty string as split separator
  • Thinking print() needs no parentheses in Python 3
  • Confusing string and list types
5. You want to count how many times each word appears in a sentence using Python. Which code correctly does this?
hard
A. from collections import Counter words = sentence.split() counts = Counter(words) print(counts)
B. words = sentence.join() counts = len(words) print(counts)
C. counts = sentence.count() print(counts)
D. words = sentence.split('') counts = dict(words) print(counts)

Solution

  1. Step 1: Tokenize sentence into words

    sentence.split() breaks the sentence into a list of words.
  2. Step 2: Use Counter to count words

    Counter(words) counts how many times each word appears and stores results in a dictionary-like object.
  3. Step 3: Check other options

    Options A, B, D use wrong methods or syntax for counting words.
  4. Final Answer:

    from collections import Counter words = sentence.split() counts = Counter(words) print(counts) -> Option A
  5. Quick Check:

    Use Counter + split() for word counts [OK]
Hint: Use Counter with split() to count words fast [OK]
Common Mistakes:
  • Using join() instead of split()
  • Calling count() without arguments
  • Trying to split with empty string
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard