What if customers rarely mention a feature your team considers a major selling point? Frequency analysis may miss the question you actually need answered. Lexical search—also called keyword search—locates text containing specified words or phrases so you can pull out the relevant records and inspect what customers say. section 5.5
Think of a keyword list as a set of labels for sorting a crowded inbox. Searching reviews for “durable,” “enduring,” and “lasting” can gather comments about product quality. Repeating the search can help track mentions over time; it does not, by itself, establish what every customer thinks. section 5.5.1
For a first pass through customer reviews:
- Choose the question and matching terms. A named feature calls for its name; positive-feedback extraction calls for words associated with praise. For reviews in another language, choose terms in that language. section 5.5 section 5.5.6
- Ask an AI assistant for Python that checks a review column against the list, marks matches, and filters the matching rows. Specify the column name and language in the prompt. section 5.5.6
- Run and inspect the code and extracted reviews. Ask follow-up questions about missing reviews and cleaning rather than assuming the first answer handles them. section 5.5.6 section 5.0
Positive reviews in Portuguese
A practical prompt is: “I have a dataframe with a review_comment_message column containing Portuguese customer reviews. Propose Python code to extract positive reviews using a keyword search.” One generated approach lists Portuguese praise words, applies a matching function to each review, creates a True/False column, and saves the filtered rows. Its basic substring check needs further attention to missing values and text cleaning. section 5.5.6
Improve matches by cleaning text before searching. The demonstrated steps include lowercasing, removing punctuation and extra whitespace, and stemming; lemmatization is another option. Apply the same processing consistently when checking terms. These choices can improve relevance, but the result still depends on the words selected. section 5.5 section 5.5.5
Listing 5.8 Data cleaning before keyword search
import string
import nltk
from nltk.stem import RSLPStemmer
nltk.download('rslp')
stemmer = RSLPStemmer()
def remove_punctuation(text):
return text.translate(str.maketrans("", "", string.punctuation))
def remove_extra_whitespace(text):
return ' '.join(text.split())
def stem_words(text):
words = text.split()
stemmed_words = [stemmer.stem(word) for word in words]
return ' '.join(stemmed_words)
def clean_text(text):
if not isinstance(text, str):
return ""
text = text.lower()
text = remove_punctuation(text)
text = remove_extra_whitespace(text)
text = stem_words(text)
return text
df['cleaned_review_text'] = df['review_text'].apply(clean_text)
Inspect the cleaning function as a starting point, including its check for non-string values, before adapting it to a review column. section 5.5.5
Validate positive-review labels against a reference, such as review scores. Sensitivity measures how many reference-positive reviews the search finds; specificity measures how many reference-negative reviews it leaves out. In one 500-review comparison, basic keyword search reached 0.45 sensitivity and 0.90 specificity: it missed many positives despite rejecting most negatives. Treat a match as a lead for inspection, not a verdict on sentiment. section 5.5.5 section 6.2.9
Table 6.3 Quality of sentiment analysis with different pretrained models
|
Sentiment analysis (
n=500)
|
Number of reviews classified as positive
|
Sensitivity
|
Specificity
|
|---|---|---|---|
|
Reference review score
|
320 (63%)
true positives
|
1
|
1
|
|
Basic keyword search
|
163 (33%)
|
0.45
|
0.9
|
|
ChatGPT 4 API
|
250 (50%)
|
0.74
|
0.93
|
|
Suboptimal model
|
193 (39%)
|
0.56
|
0.93
|
|
Translated inputs
|
295 (59%)
|
0.86
|
0.89
|
|
Multilingual model
|
265 (53%)
|
0.79
|
0.93
|
|
Zero-shot learning model
|
325 (65%)
|
0.87
|
0.74
|
Compare the keyword baseline with other sentiment-analysis approaches using both sensitivity and specificity, rather than the number of positive labels alone. section 6.2.9







