Skip to content

Commit 8ebd482

Browse files
Androz2091claude
andcommitted
chore: stub sentiment scoring, drop nltk
Sentiment analysis pulled in nltk + a baked-in vader_lexicon (~50MB), which inflated the Lambda image and added cold-start cost. Stub count_sentiments() to a constant 0.5 for now. The TODO in tasks.py calls out how to revive it. - remove nltk from requirements - drop the vader_lexicon download from both Dockerfiles - drop scripts/download-ntk.py and the install-step Makefile reference Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2c16c23 commit 8ebd482

6 files changed

Lines changed: 8 additions & 31 deletions

File tree

Dockerfile.api

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ FROM python:3.10-slim-buster
44
# Create application directory and move there
55
WORKDIR /app
66

7-
# Install nltk
8-
RUN pip install --no-cache-dir --prefer-binary nltk
9-
10-
# Copy the script that downloads the vader lexicon module
11-
COPY scripts/download-ntk.py ./
12-
13-
# Execute that script
14-
RUN python download-ntk.py
15-
167
# Copy requirements file from the host to the container
178
COPY requirements.txt ./
189

Dockerfile.lambda

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
# handler is selected per-function via the Lambda ImageConfig.Command.
33
FROM public.ecr.aws/lambda/python:3.10
44

5-
# NLTK data lives at a known path so we can ship it with the image and skip
6-
# any runtime download attempts (which would fail in the VPC anyway).
7-
ENV NLTK_DATA=/var/task/nltk_data
8-
95
WORKDIR ${LAMBDA_TASK_ROOT}
106

117
COPY requirements.txt ./
128
RUN pip install --no-cache-dir -r requirements.txt
139

14-
RUN python -c "import nltk; nltk.download('vader_lexicon', download_dir='${NLTK_DATA}')"
15-
1610
# Flat layout: src/* sits at the task root so existing top-level imports
1711
# (`from tasks import ...`) keep working.
1812
COPY src/ ${LAMBDA_TASK_ROOT}/

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ install:
1414
uv venv --python 3.10
1515
. .venv/bin/activate
1616
uv pip install -r requirements.txt
17-
uv run ./scripts/download-ntk.py
1817

1918
dev:
2019
. .venv/bin/activate

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ limits==3.5.0
2222
markdown-it-py==3.0.0
2323
MarkupSafe==2.1.2
2424
mdurl==0.1.2
25-
nltk==3.9.1
2625
numpy==1.24.3
2726
ordered-set==4.1.0
2827
orjson==3.9.15

scripts/download-ntk.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tasks.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,15 @@
4646

4747
from wh import send_internal_notification
4848

49-
from nltk.sentiment import SentimentIntensityAnalyzer
50-
sia = SentimentIntensityAnalyzer()
51-
49+
# TODO: restore real sentiment scoring. Stubbed to a constant so we can
50+
# drop NLTK + the vader_lexicon download from the Lambda image while we
51+
# decide whether sentiment is worth the ~50MB of data and the cold-start
52+
# cost. Re-enable by reinstating SentimentIntensityAnalyzer here and the
53+
# nltk install step in Dockerfile.lambda.
5254
def count_sentiments(contents):
53-
sentiments = []
54-
for content in contents:
55-
if not content:
56-
continue
57-
score = sia.polarity_scores(str(content))["compound"]
58-
if score != 0:
59-
sentiments.append(score)
60-
return sum(sentiments) / len(sentiments) if len(sentiments) > 0 else 0
55+
for _ in contents:
56+
pass
57+
return 0.5
6158

6259
def find_user_root(zip_namelist):
6360
"""

0 commit comments

Comments
 (0)