Chapter 15 exercises: Preparing Text and Multimodal Data
On this page
Attempt these tasks before opening the worked answers. Use the chapter experiment notebook, or import NumPy as np and Pandas as pd in your own notebook. Retain your first attempt and explain each correction.
B2-15-E01 · Compare Unicode spellings
Normalize and casefold so the two entries compare equal while retaining raw s.
s=pd.Series(["Café","CAFÉ"],dtype="string")One hint after an attempt
Preserve the raw column.
B2-15-E02 · Count documents and occurrences
Compute the occurrence count of red and its document frequency; verify 2 and 1.
docs=pd.Series(["red red house","blue house"],dtype="string")One hint after an attempt
Count distinct membership within each document.
B2-15-E03 · Verify representation dimensions
Interpret shape as samples, time steps and features; retrieve sample 1, step 0, feature 2.
batch=np.arange(24,dtype="float32").reshape(2,3,4)One hint after an attempt
Trace one coordinate through the stored order.
Reflect and get feedback
Explain one result without looking at the code. Identify one boundary case that would change your method. An optional tutor prompt is: “Here is my attempt at B2-15-E03. Give one hint about the violated assumption; do not give the solution yet.” Then use the worked answers.